Java - Render images in pdf from html sources - java

We are currently using Jasper report to generate pdf. But recently we come to problem where we need to render HTML code in pdf. And HTML code contains images. Images sources can be both http URL or base64 string.
How can we solve the problem? Or which library can we use to solve the problem?

Related

Converting svg images to base64 interactivity not working?

I am generating one birt report output in html format and I have one svg image on which there is some interactivity is defined but while converting that image to base64 and showing in html it gives me error, my html is coming from backend dynamically.
Error I am getting is as below:
Uncaught DOMException: Blocked a frame with origin "null" from accessing a cross-origin frame.
at isIPadIPhone (data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW
and I am converting file as below:
"data:image/svg+xml;base64," + new String(Base64.encodeBase64(Files.readAllBytes(file.toPath())));
How can we resolve this issue please help me out. I cannot use "Access-Control-Allow-Origin":"*" as it is a web application security will get affected.

Extracting all images and text from pdf file

I need to create json from pdf to render the pdf content as HTML with all the images and text. I have tried the modules below to do that. I am able to extract only plain images now, but not able to extract the graphical images and background shadow images. Is there any module to get these?
Modules tried
-PDFMiner (python)
-Mammoth(Node)
-pdf2json(Node)
-PDFBox(Java)
Have a look at http://pythonhosted.org/PyMuPDF/. Apparently this product renders pages in various formats, including json. Although I have limited experience with it, the recipe at http://code.activestate.com/recipes/580703-extract-images-of-a-pdf-optionally-by-page-using-p/history/1/ shows how to use PyMuPDF to extract images from a PDF.

HTML+ Images + CSS To PDF using Google Drive API

I know it's possible to convert an HTML file to PDF using Google Drive (HTML2PDF using Google Drive API) but I'd like to know if this HTML has images and CSS files is possible and how to do that.
You need convert HTML to a Docs file and export it as PDF. During the docs conversion most of the non-trivial styles are being trimmed. Basic coloring, sizing and positioning will all you'll get. The exported PDF is the Docs' file's PDF version. Images will be preserved though.
You can make experiments by uploading your html files to Google Drive on drive.google.com with conversion settings on and see the results.
For images you could try this: Embedding Base64 Images
Worked for me when uploading by web. Should work with my solution https://stackoverflow.com/a/21711109/592042
Css can be written right into html file.

Generate a PDF and then download as JPEG or image file

I am using iText to generate PDF and is working fine, and I can also download it via browser as PDF. However, is it possible for java or iText to convert it to JPEG or any IMAGE file and allow users to download the image file.
response.setContentType("application/pdf; charset=utf-8");
Merely changing the contentType to image/jpg is not possible. I am continuously looking for answer but struggling to find one.
Any idea would be a lot of help
I dont know more about iText. But using PDFBox we can convert pdf document into images.
After splitting you can push images to response.
Here some reference links :
http://pdfbox.apache.org/commandlineutilities/PDFToImage.html
Converting a PDF into multiple JPGs with iText or other
http://www.javatpoint.com/example-to-display-image-using-servlet
you can use iText only for generating a pdf nothing else. see the link http://itextpdf.com/itext.php . see this to convert a pdf to image. See this link as well for clearer understanding with an example.

Java: Embed a HTML or PDF into a JFrame

I am open to alternative solutions, so here is my problem.
I have 111 PDFs that contain information on various degree programs. I can convert them to HTML using freeware.
The problem with the HTML is that it contains CSS, JEditorPane doesn't display the webpage, and the PDF libraries are slow and bulky.
I want to have a JCombobox where users can select a page to view, and have it appear below the box.
Any ideas on the best method?
Use iText API for PDF and DJ Project for HTML/webPage.
Most libraries that convert PDF to HTML can also convert PDF to image.
If you can convert to SVG and display it using one of the SVG libraries (E.g. Batik), that would be one way you could display it without losing any functionality like zoom in/out.
Otherwise you can convert PDF to high-res JPG/PNG and display it in your app.

Categories

Resources