Do you know how to convert (save) HTML to an image? Any format is acceptable: jpg, png, ... I tried this code but it does not correctly convert images from HTML (<img> tag).
A solution in Java would be preferred; however, I would appreciation any approach.
Well, here is the outline of a solution, at least:
You need a HTML renderer (Gecko, Webkit et al). Then you need to capture it's "output".
The first approaches that spring to mind are
Create a batch tool yourself, using an open source rendering engine - then render this to an image. This could be done with Qt and QWebKit, maybe even with Qt Jambi (for java). There is an example for c++ here, in the Qt developer blog.
Automating an X11 browser and using capture to capture the contents of the window. Could be a problem with scrolling, IDK.
One solution would be to use WebDriver
Another solution could be provided by this article : Capture screenshots with Selenium
They are both Java solutions.
Your description is a little shy on what your trying to do. Could you please give more details?
If you are just trying to take the html and make an image of it what you might want to try is to create a new image and insert the html as text into the image. Once that is done, you can save the image to the type of your choice. I don't know if this is what you are looking for though.
Related
I want to implement a function that can see PowerPoint on the web at this time.
You can do it simply by converting PowerPoint to an image, but if you convert it to an image, I think there are issues that you can not use video or audio.
So the idea was to convert PowerPoint to HTML and place it where I wanted. However, it does not have much ability to directly implement the pure function of converting PowerPoint to HTML. To solve this problem, I have been looking for open source or various libraries, but I have not found them yet.
The development environment is java8 + Spring Boot.
If you are OK with converting your PPT files to PDF before converting them to HTML, then pdf2htmlEX could be worth looking at. It is the best tool I could find for this kind of work, as it is capable of converting PDFs to HTML very precisely (have a look at the exmples 1,2,3,4). You should be able to find wrapper libraries in the maven repo so that you are able to call it from your Java applications.
If you are OK in using iframe you may use a Microsoft solution https://products.office.com/it-IT/office-online/view-office-documents-online
You may use this code:
<iframe src='https://view.officeapps.live.com/op/embed.aspx?src=[you_ppt_url]' width='100%' height='600px' frameborder='0'>
There's an older node package called PPTX2HTML. It outputs a bunch of garbled code on a canvas element, but it might work. They even have a demo website to try it out. They seemed to have broken the powerpoint up into parseable XML and rendered the elements.
I am trying create a java function to convert image files such as "jpg, jpeg, gif, png" into favicon.ico. Does anyone know any library can do that? I want pure java or javascript way. Not the way using imageMagick with jni
Take a look at image4J which will allow you to create ICO images through Java
As simply as...
List<BufferedImage> listOfImages = ...;
ICOEncoder.write(listOfImages , new File("favicon.ico"));
You may also want to check out Reading/Loading an Image as well...
Disclaimer: I not aiming to Answer the question in the most efficient way, but i found an interesting possibility how to solve this problem in an unconventional manner.
with some googling i found this existing site http://mrcoles.com/favicon-creator/ (first result, for the searchterms "javascript create ico").
It has javascript code to create an ICO file, coping this code and adding some canvas html5 magic like found here, you could build the whole thing in Javascript and having lots of fun.
Just a crazy Javascript approach, from the do-it-yourself (copy-past-it-yourself) shelf. :)))
How to convert an html webpage to a picture like google preview.
Is there a Java library permitting this?
Is there a command-line argument to call browsers to make them convert a web page into a picture .png for instance?
Using Qt, you can create a simple window with a QWebView (this is webkit under the covers), and then use QWidget::render() method to get QPixmap, and then convert it to QImage.
Qt is C++, but python and java bindings exist also.
http://www.roseindia.net/java/example/java/swing/Print.shtml
Here's a way to do it!
See here. It shows that iText and FlyingSaucer (xhtmlrenderer) have such options.
We have a java web application. The application generates a big image with company structure diagramm on it as jpeg. Users download the image and want to print it on DIN A2 (big paper format). The jpeg in this scale has pretty bad quality after printing.
Our idea is to generate an image in vector graphics. What vector graphics format suits the best our needs, considering that we code in java and the users have windows and use MS IE browser?
May be there is a better way archieve this? Like let the browser to display the image and let users to print the page?
PDF has been invented exactly for the same purpose. iText library enables you to draw lines, boxes, circles and insert whatever text you like. If you want to automate it a bit using templates there's JasperReports which utilizes iText.
A well known vector graphics format is Scalable Vector Graphics. It's basically an XML file (starting with <svg> tag. It can be viewed in browsers like Firefox without additional plugins.
For java, you can use the Java 2D API to create SVG format. A tutorial can be found here:
If you need the vector graphic for IE you need VML, similar to SVG but can be rendered by Internet Explorer.
RaphaelJS can be used for vector graphics independent of browser model but it's client side and you may not want to do client side processing on every page load.
I am working on a web application (using Grails) which will generate a gift certificate. I'm thinking of a workflow like this:
The user will pick a template which will be stored as an image.
Then the text (name, date, amount etc) will be overlaid on the image to make the final certificate. There is a set of co-ordinates associated with each template which describes where to put each bit of text.
There is a kind of 'live preview' in the browser which shows the user what the final certificate will look like.
When the user is happy with the results, they download the certificate as a PDF and print it.
Can anyone recommend a library for Java (or Groovy) that will make it easy to do this? I'm not particularly worried about speed, as I suspect that the webapp will only be used by a few people at a time.
UPDATE: in the end I used the iText PDF library to overlay text on a PDF template using PDFStamper.
You can do this with the standard Java 2D graphics libraries - create a BufferedImage from the image, get its Graphics and use drawString() to put the text on top. Of course, the text would then be part of the bitmap in the resulting PDF, and not use the full printing resolution.
In addition to the answers above, I have come across the groovy library GraphicsBuilder and the Grails plugin j2D which are also potiential solutions.
You might consider using Batik to do this as SVG. Your image would be an <img> tag and your text would be one or more <text> tags. There's a converter (called FOP, I believe) which will get you PDF output.