Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rendering PDF document using img tag with Base64 content #829

Open
jfreedman-eagent opened this issue Apr 20, 2022 · 5 comments
Open

Rendering PDF document using img tag with Base64 content #829

jfreedman-eagent opened this issue Apr 20, 2022 · 5 comments

Comments

@jfreedman-eagent
Copy link

I want to display PDFs and images inline with the PDF I'm generating, but I only have the raw data for each file (and their associated MIME type). For images, I can do this with:

<img 
   src="data:image/png;base64,{base64 encoded data here}"
   width="500" 
   height="500"
/>

However, when I do the same thing with a PDF (following the guidance in this issue), the PDF can't be resolved.

This is the HTML that I used:

<img 
   src="data:@file/pdf;base64,{base64 encoded data here}"
   page="1"
   width="500" 
   height="500"
/>

And the error I get is:

com.openhtmltopdf.load WARNING:: Unrecognized image format for: data:@file/pdf;base64,{base64 encoded data here} => java.io.IOException:: Unrecognized Image format

Is this expected behavior, or is this a bug with how PDFs are handled via the img tag?

Thanks!

@syjer
Copy link
Contributor

syjer commented Apr 27, 2022

hi @jfreedman-eagent as far as I remember and looking at the source of the error ( https://github.com/danfickle/openhtmltopdf/blob/open-dev-v1/openhtmltopdf-pdfbox/src/main/java/com/openhtmltopdf/pdfboxout/PdfBoxImage.java#L33 ) , the base64 images are handled through ImageIO.

So we may need to add a special case for data:file/pdf;base64 encoded data.

@jfreedman-eagent
Copy link
Author

Thanks for responding! Is this something that would be worth creating a PR for? If so, I can take a stab at implementing it

@syjer
Copy link
Contributor

syjer commented Apr 28, 2022

Is this something that would be worth creating a PR for

Yes, as it's quite a coherent request, if linking a img via the file protocol work, it should also for data: base64 :)

@Dunemaster
Copy link

hi, @jfreedman-eagent
Do you still intend to make a PR? We need this function too, I am thinking about implementing it myself, but I would hate to duplicate efforts

@jfreedman-eagent
Copy link
Author

Gah, sorry @Dunemaster. I haven't started working on this, so feel free to go for it.

I meant to pick it up, but other stuff came up since then 😓

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants