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.
Related
Screenshot of sriptI wanted to download the pdf on a website which is like in an embedded form with inbuilt pdf viewer.
Here is the sreenshot of it.
I tried going through the whole website but of no use
I'm trying to download some images from a website. I've been using Jsoup to do some scraping and have successfully downloaded images given a url before but the images on this website are in svg format. There is no link to a location where the svg file is located, the image is embedded in svg tags. I have seen Batik used for converting svg files to other image formats but I don't have the svg file available.
Is there any way to do this? Would appreciate any guidance. Thank you.
Typically an SVG image is not a file, but rather it is included in the response body of the GET request from a browser. What you can do to test this is to download a REST client, POSTMAN if you're using Chrome, and issue a GET request to the url of the svg. The response will be the SVG image. Thinking now in terms of Java, you may have to do some parsing in your code to grab just the actual svg element because the website may return extra junk wrapping the embedded svg.
I have used Batik and I think it's not a good solution for many reasons for what you're trying to do. In the past I ended up writing Java code that executed a 3rd party program for image conversion. It was basically a Command class that wrapped the execution of phantomjs. Download phantomjs, and use the rasterize.js file in the examples folder to achieve quick and easy image conversion from .svg to .png or .jpg. At the command line, the command for phantomjs is something like:
phantomjs rasterize.js C:\sourceImage.svg C:\outputImage.png
If you are doing image manipulation, I did it a lot using ImageMagick as phantomjs is only good for rendering svg to a rasterized image format.
In your case what you want to do is for every svg image at the url, GET the svg, parse it into a String, write that String to a file, then do something like:
String command = "C:\\phantomjs\\phantomjs.exe C:\\phantomjs\\rasterize.js C:\\source.svg C:\\output.png"
Process process = Runtime.getRuntime().exec(command);
Obviously make your code more general, replacing the values in the command string with resusable variables.
If this is in the context of a commercial platform, you can install phantomjs and your java app on a single server, and then just connect this app via REST endpoints to your svg finder app that gets the images. When your svg finder app gets an image, have it parse it, format it, then POST it to the phantomjs server for rendering and uploading/storage.
Just save the part of the HTML file between the <svg> tags (including the <svg>). Give it a .svg extension. You should then be able to open it in a browser, or pass it to Batik, ImageMagick or some other converter.
How to prevent downloading PDF file when displaying on web pages?
I tried the content disposition inline but it didn't work.
How can i do this ?
One option is to render the PDF to JPEG or some other image format and only serve the rendered images to the user. Some of the PDF libraries allow you to render PDF's to other file formats.
Another option may be to send/redirect the PDF through to an online PDF viewing app in the same way Google does with attachments in GMail. That way the user sees a JPEG of the PDF and cannot download the PDF.
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.
I have been searching for this.
looked at this question, but looks like volo3 is discontinued, so I downloaded the DWG trueView.
then in a jsp file I have:
<EMBED SRC="randomDwg.dwg" WIDTH=800 HEIGHT=500>
in both firefox and IE keedp showing plugin required
how can I embed a dwg file in a web page just like PDF files? (doesn't matter if a plugin is required)
Since just about everyone has PDF why not convert the dwg to pdf. Since pdf is vector you shouldn't lose any resolution and should still be able to zoom in. http://anydwg.com/dwg2pdf/ might do it for you.