High Resolution HTML to Image Conversion

I am rendering a html file using JEditorPane and painting the pixels to a BufferedImage object. How can I make a higher resolution than 72 dpi.
Here is my current program
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
import javax.swing.JEditorPane;
public class Main {
    public static final double WIDTH_INCHES = 11 - 0.5 - 0.5;
    public static final double HEIGHT_INCHES = 11 - 0.5 - 0.5;
    public static final double DPI = 72;
    public static final int WIDTH_PIXELS = (int) (WIDTH_INCHES * DPI);
    public static final int HEIGHT_PIXELS = (int) (HEIGHT_INCHES * DPI);
    public static void main(String[] args) throws FileNotFoundException,
            IOException {
        StringBuilder htmlCode = new StringBuilder();
        FileReader htmlFileReader = new FileReader("test.htm");
        BufferedReader htmlFileBufferedReader =
                new BufferedReader(htmlFileReader);
        String aLine;
        while ((aLine = htmlFileBufferedReader.readLine()) != null) {
            htmlCode.append(aLine + "\n");
        JEditorPane editorPane = new JEditorPane("text/html",
                htmlCode.toString());
        editorPane.setMaximumSize(new Dimension(WIDTH_PIXELS, HEIGHT_PIXELS));
        editorPane.setSize(new Dimension(WIDTH_PIXELS, HEIGHT_PIXELS));
        editorPane.setBackground(Color.WHITE);
        editorPane.setPreferredSize(new Dimension(WIDTH_PIXELS, HEIGHT_PIXELS));
        BufferedImage image = new BufferedImage(WIDTH_PIXELS, HEIGHT_PIXELS,
                Image.SCALE_SMOOTH);
        editorPane.paint(image.getGraphics());
        ImageIO.write(image, "png", new File("test.png"));
}How can I make this program to make a better resolution image?

I was profiling the application and found that iText was copying the whole image and running transparency checks for the 8.5 by 11 that I was doing at 72x4 dpi.
I found a way to do it more efficiently and it happens to take advantage of the vector text.
I used the PdfContentByte.createGraphicsShapes method to get a PDF Graphics2D object and I painted to that instead of painting to the java.awt.image. I did this in combination with disabling double buffering on the JEditorPane
This is my working code example
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
import java.awt.Dimension;
import java.awt.Insets;
import java.io.*;
import java.util.Date;
import javax.swing.JEditorPane;
import javax.swing.border.EmptyBorder;
public class HtmlConverter {
    public static void main(String[] args) throws FileNotFoundException,
            IOException, DocumentException, BadElementException {
        StringBuilder htmlCode = new StringBuilder();
        FileReader htmlFileReader = new FileReader("test.htm");
        BufferedReader htmlFileBufferedReader =
                new BufferedReader(htmlFileReader);
        String aLine;
        while ((aLine = htmlFileBufferedReader.readLine()) != null) {
            htmlCode.append(aLine + "\n");
        convertToPdf(htmlCode.toString(),
                new FileOutputStream("test.pdf"));
    public static void convertToPdf(String htmlCode, OutputStream output) {
        final long startTime = new Date().getTime();
        try {
            final Rectangle PAGE_SIZE = PageSize.LETTER;
            final float PDF_MARGIN_INCHES = 0.5F;
            final int PDF_MARGIN_PIXELS = (int) (PDF_MARGIN_INCHES * 72);
            final int HTML_DOC_PX_WIDTH = (int) PAGE_SIZE.getWidth();
            final int HTML_DOC_PX_HEIGHT = (int) PAGE_SIZE.getHeight();
            Document document = new Document(PAGE_SIZE);
            JEditorPane htmlEditorPane = new JEditorPane("text/html", htmlCode);
            htmlEditorPane.setDoubleBuffered(false);
            htmlEditorPane.setMaximumSize(
                    new Dimension(HTML_DOC_PX_WIDTH, HTML_DOC_PX_HEIGHT));
            htmlEditorPane.setPreferredSize(
                    new Dimension(HTML_DOC_PX_WIDTH, HTML_DOC_PX_HEIGHT));
            htmlEditorPane.setSize(HTML_DOC_PX_WIDTH, HTML_DOC_PX_HEIGHT);
            htmlEditorPane.setBorder(new EmptyBorder(PDF_MARGIN_PIXELS,
                    PDF_MARGIN_PIXELS, PDF_MARGIN_PIXELS, PDF_MARGIN_PIXELS));
            htmlEditorPane.setMargin(new Insets(PDF_MARGIN_PIXELS,
                    PDF_MARGIN_PIXELS, PDF_MARGIN_PIXELS, PDF_MARGIN_PIXELS));
            PdfWriter writer = PdfWriter.getInstance(document, output);
            document.open();
            PdfContentByte cb = writer.getDirectContent();
            java.awt.Graphics2D g2d =
                    cb.createGraphicsShapes((int) PAGE_SIZE.getWidth(),
                    (int) PAGE_SIZE.getHeight());
            htmlEditorPane.paint(g2d);
            g2d.dispose();
            document.close();
        } catch (Exception ex) {
            throw new RuntimeException("Exception while generating PDF file." +
                    " This may have been caused by a I/O Exception in the" +
                    " output stream", ex);
        final long endTime = new Date().getTime();
        System.out.println("Total Time: " + (endTime - startTime) + "ms");
}

Similar Messages

  • How can you save keynote slides as high resolution (300 dpi) images?

    Apparently there is a way to save powerpoint slides as 300 dpi images, with some finagling, but not the mac version.  Does anyone know how to do this in keynote?  Or is there a relativley easy way to do it with free/cheap software?  I can increase the dpi in photoshop, but it doesn't produce crisp images for obvious reasons.

    how can you save keynote slides as high resolution (300 dpi)
    to save individual images from each slide in Keynote;     file > export > images > TIFF (for optimum quality)
    You are using the wrong terminology to describe creating an image file
    - dpi ( meaning dots per inch )  is the measurement used in printing to create the number of print dots per inch that will be deposited on to physical media like paper or film   This is done in the printer settings box of the print driver and is dependant on how the individual printer can print..
    ppi ( meaning pixels per inch ) is the measurement you need to use when creating the number of pixels in a digital image file. You establish image resolution in Keynote using the inspector;     
    Keynote > inspector > document > slide size
    I can increase the dpi in photoshop, but it doesn't produce crisp images for obvious reasons.
    You can resample images in editing applications such as Photoshop or Painter but what you are doing is adding non image information to the image to increase pixel count, this is called noise. As you state this is not the procedure to use in your situation.

  • How to maintain high resolution of exported images

    I am working with iphoto 5.0.4. When trying to export (share>export) an image as a 'Full Size' image (3264 x 2448 4.5 MB) to the desktop it appears at that size with 300 dpi resolution. However if I export the same file as 'Scale image as no larger than:' the resolution remains 300 dpi but the size is reduced to 2.4 MB while the dimensions remain the same. And finally if any cropping is performed or if I resize the dimensions of the image, the exported image will reflect the altered size but also the dpi is reduced to 72. What gives? Does that mean that the printed version will only print at 72 dpi? How can I create a smaller size image and still maintain 300 dpi resolution? I thank you in advance for your help.
    iMac   Mac OS X (10.4.5)   iphoto 5.0

    My first thought would be to remove the "Scale all objects ... " vi property.  I have been using LabVIEW for 10+ years, and I always found that function to work very poorly.  I never use it.  At least you could try removing that setting and see if your problem goes away.

  • How keep high resolution in enlarged image?

    Hi!
    When I insert my logo in Dreamweaver, I first need to give it  a certain size in Photoshop (if I fix the size in dreamweaver, the logo doesn't get sharp). But I would like logo to have a better resolution when my webpage gets enlarged (for example when reading it in mobiles). I've seen some pictures on webpages that keep their resolution even when you enlarge the webpage. How can you do that?
    Greatful for help!
    Milda
    Message was edited by: mildar
    PS. Does it help if I make the logo in Illustrator instead?
    Message was edited by: mildar

    Hi
    Adninjastrator wrote -
    it might be worth noting that mobile device resolution is much greater
    than 72 or 96 px/in. The iPhone 4 for example has 326px/in.
    Murray is correct with his 72ppi, (this is for Macs) and 96 ppi, (this is for windows).
    New Apples iDevices do have a screen resolution of 326ppi but not the safari browser for iOS, which still conforms to the macs ppi, (72). It' a similar situation to comparing your system/monitor screen resolution with your browsers screen resolution, you may have a HD screen but the browser still uses the browsers ppi for your system.
    PZ

  • How can I save a PDF and retain the high resolution of the images it contains?

    I'm using the trial version of Acrobat XI. The images are 1440dpi but always save at 120dpi. The PDF is for the content of a picture book so I need to be able to save them at a minimum of 300dpi. Any help would be very much appreciated.

    Have just discovered that although the properties for each of the photos states 1440dpi they vary from 696 to 2131 pixels on the height dimension of 10cm!
    Thanks to your help in guiding me to the Preflight profiles, I've now at long last produced a file that does the job! Thank you!!!
    I created my file in Word, saved it as a PDF (3.72MB), replaced the images with the original files (Word had made them tiny), then used the Digital Printing (Color) profile to Analyze & Fix the PDF, thus creating a PDF (98MB) that was suitable to upload. There is no doubt a more succinct and less Heath Robinson method but I wasn't able to find it!

  • HTML to Image Format

    If I run this class:
    import java.awt.*;
    import java.io.*;
    import javax.swing.*;
    public class Main {
        public static void main(String[] args) throws FileNotFoundException,
                IOException {
            StringBuilder htmlCode = new StringBuilder();
            FileReader htmlFileReader = new FileReader("test.htm");
            BufferedReader htmlFileBufferedReader =
                    new BufferedReader(htmlFileReader);
            String aLine;
            while ((aLine = htmlFileBufferedReader.readLine()) != null) {
                htmlCode.append(aLine + "\n");
            JFrame frame = new JFrame("test");
            frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            JEditorPane editorPane = new JEditorPane("text/html",
                    htmlCode.toString());
            editorPane.setMaximumSize(new Dimension(640, 700));
            editorPane.setSize(new Dimension(640, 700));
            editorPane.setBackground(Color.WHITE);
            editorPane.setPreferredSize(new Dimension(640, 700));
            frame.add(editorPane);
            frame.pack();
            frame.setVisible(true);
    }Then the HTML file displays correctly to the screen.
    How could I get it to give me an array of pixel colors or something else that I can take as an image and input into a PDF Generator like iText or PDFBox.
    Also, could we get a better resolution or anti aliasing in order to make the it look better for printing?

    This has been moved to the Swing forum under the title "High Resolution HTML to Image Conversion"

  • Is it possible to convert a PDF to a high resolution image with ColdFusion?

    I would like to determine how to convert PDFs to high resolution images using ColdFusion.
    I'm running ColdFusion 9,0,0,251028 on CentOS 5.5 with Apache 2.2.3.
    The <cfpdf action = "thumbnail" ...> is all well and good for creating 72 dpi images of a PDF, but I need to be able to create 300 dpi images of a PDF.
    The PDFs in question have a much higher level of detail available than 72 dpi.
    The related scale attribute for the action="thumbnail" functionality has an accepted range of 1 to 100, but an example of what I need is something more like a value of 415.
    I should mention that I did try to use the jpgdpi attribute, and set it to 300 dpi . . . which produced a JPG that was indeed set to 300 dpi, but still had the same pixel dimensions as the 72 dpi image, so this did not affect the pdf to jpg conversion process in any way to make the image higher resolution.
    Alternatively, would another possibility be to use ColdFusion to alter the dimensions of the pdf to be 415% of its original dimensions in memory, and then output a 100% thumbnail of that altered PDF? Is this possible? I can not for the life of me work out how to alter the set dimensions of a PDF via ColdFusion, in order to determine if this would have an affect on the size of the thumbnail produced.
    Or more broadly, how would you use ColdFusion to convert a PDF to a (or a series of) high resolution images?
    Thanks in advance for any help on this.

    Another idea:
    Use a third party tool with CFEXECUTE if there's no other way. As you're on Linux you could easily run ghostscript on the command line to do it. gs lets you specify filetype as the device and also has options for resolution. For Windows there's gs as well (not sure though what it's command line capabilities are there) or tools like this: http://www.softinterface.com/Convert-PDF-To-Image/Convert-PDF-To-Tiff.htm
    Cheers
    Kai

  • High ram usage when loading high resolution images

    Hello,
    I'm wondering why Firefox almost hangs my system while opening high-resolution images like this one (save your data, you have been warned):
    http://minecraft.1favre.de/output.png
    While opening, it involves X process to use CPU and a lot of memory (it's freed shortly after loading the image). Other browsers don't do that. Moreover, other browsers don't do any problems with such images, they load it fast and efortless. I Have 2GB of RAM.
    Firefox memory usage: http://wklej.org/id/1027301/
    Konqueror memory usage: http://wklej.org/id/1027305/
    Opera memory usage: http://wklej.org/id/1027306/
    Chromium was problematic with getting the log: http://img.koci.net.pl/images/screen252.png
    Unfortunately I was unable to generate log with nvidia-bugreport.sh. Doesn't work, strange. Here are some details of my system:
    02:00.0 VGA compatible controller: NVIDIA Corporation G73 [GeForce 7300 GT] (rev a1)
    nvidia-settings: version 304.88 (buildmeister@swio-display-x86-rhel47-06) Wed Mar 27 15:32:47 PDT 2013
    [root@linux mk]# uname -a
    Linux linux 3.8.10-1-ARCH #1 SMP PREEMPT Sat Apr 27 12:36:59 CEST 2013 x86_64 GNU/Linux
    root@linux mk]# X -version
    X.Org X Server 1.14.1
    Release Date: 2013-04-17
    X Protocol Version 11, Revision 0
    Build Operating System: Linux 3.8.7-1-ARCH x86_64
    Current Operating System: Linux linux 3.8.10-1-ARCH #1 SMP PREEMPT Sat Apr 27 12:36:59 CEST 2013 x86_64
    Kernel command line: BOOT_IMAGE=/boot/vmlinuz-linux root=UUID=9ddb4ac2-a9bf-44db-830c-9ba210ea6d12 ro quiet
    Build Date: 17 April 2013 02:37:06PM
    Current version of pixman: 0.28.2

    Hello,
    The Reset Firefox feature can fix many issues by restoring Firefox to its factory default state while saving your essential information.
    Note: ''This will cause you to lose any Extensions, Open websites, and some Preferences.''
    To Reset Firefox do the following:
    #Go to Firefox > Help > Troubleshooting Information.
    #Click the "Reset Firefox" button.
    #Firefox will close and reset. After Firefox is done, it will show a window with the information that is imported. Click Finish.
    #Firefox will open with all factory defaults applied.
    Further information can be found in the [[Reset Firefox – easily fix most problems]] article.
    Did this fix your problems? Please report back to us!
    Thank you.

  • Moving high resolution images from PSE6 to Premiere Elements 4

    I am trying to take a pdf map (happens to be of the San Diego Zoo) and insert it into a Premiere Elements 4 (PE4) project to show where we went in the Zoo and then show our family pictures/video in that area
    So I bring the pdf map file into PSE6 and convert it to a jpeg and/or psd file so I can import it into PE4 (which cannot import a pdf). It works fine, but if I don't increase the image size in PSE6 the image becomes super blurry in PE4 when I change the scale (zoom in).
    However, when I do increase the image size in PSE6 and save as either a jpeg or psd so it will be clear at 250% scale in PE4, I get this error message when I try to import it to PE4: "File video dimensions (width/height) too large."
    This happens even when I leave the dimensions (8.5 X 8.176 inches) the same and just change the ppi for the higher resolution I need. It starts out as a 300 ppi image and I get the error message even if I only change it to as high as 500 ppi. (And if I go much lower than that, it's not going to help the resolution enough to be worth it in PE4).
    (btw, the original pdf file is perfectly clear in PSE6 at 1000+% and the converted jpeg/psd are clear enough in PSE6 at 250%)
    So, my question is:
    How do I improve the picture quality in PSE6 so that it's not blurry when I export to PE4 and increase the scale, but maintain the right size that PE4 will accept?
    This might be somewhat of a PSE6 question, but hopefully somebody knows the answer and can help me out! Thanks!

    Joseph,
    In an NLE, you are really only using the pixel x pixel dimensions. DPI/PPI mean nothing, except a larger file size.
    You can set the PPI to 72 and be fine for TV. You might want to bump it up slightly, if you are outputting to a progressive file for display on a computer, but even then, you'll not need much.
    PSD will be as clear a format, as you can get. I'd not bother with any JPG compression, as by the time that you lower the compression settings, i.e. compress less, to keep the quality, you will not have compressed all that much.
    For zooming in, you do not need for the image to be much larger than the preset for your Project. The FAQ's at the top of the page have some good recs. for the exact sizing. If you will be panning, while zoomed out, you'll want just enough extra to allow for that movement.
    Depending on the native resolution of your PDF's image, you should be able to get a reasonably sharp image onto the TV screen. Also, judge the final look of this image on a TV, if that is your final output, as it will appear better, than on the computer screen. I use a DVD RW for this sort of testing and just re-use the discs.
    Last, do all of your re-sizing (as much as is possible) in Photoshop. The algorithms are a bit better than in an NLE. Now, for a dynamic zoom, you have no choice but to use Motion>Scale.
    Hunt

  • How can you make a pixlated image a higher resolution in Photoshop CC? i have tryed image size but it doesnt seem to work someone please help

    As you can see in the screenshot here ----> Gyazo - b048a0770df6264af1ff398951acd4f9.png I have typed a higher resolution but when I try the pixles never seen to ever go away and it increases the file size every time, is there an easier way? PS: if another adobe cc software is needed to complete this task I have every one so it doesn't have to only be in Photoshop.

    The image has been reduced in size and over sharpened to the point that jaggies artifacts abound.  You will not be happy with the result of interpolate the images up in size increase the number of pixels..   You need to find the original image file from the camera.

  • Saving an image to a higher resolution from a lower one

    I have photoshop cs6 on my MacBook Pro and downloaded images I'm working on for a friend who needs them for professional use. They're all in 72 dpi so I managed to save them at a higher resolution of 300 dpi, and in Tiff format but when I try to email them the images revert back to 72 dpi. How can I keep the resolution at 300 or higher for email
    Thanks

    I know you haven't asked for advice about the actual re-sampling process, but I can't help myself .
    If the images are for print reproduction or a similar high quality requirement the results are likely to be very poor even if up-sampled to 300dpi. It's OK to down-sample images if the pixel data is there in the first place. If it's only 72dpi and then up-sampled, and even if it looks good on screen, it'll be rubbish in commercial print.
    The exception might be if the actual dimensions of the 72dpi image is large and it is up-sampled to 300dpi but at the same time the dimensions are reduced considerably that should help preserve some quality.
    All that said, if you are using Mail, try selecting Actual Size, as shown in the image (if you haven't already). The option only appears when you add an attachment to an email.

  • Increasing physical dimensions of high resolution image?

    I have an image that I want to use in a video, though it is not physically large enough to fill the 1920 x 1080 dimensions of the video, though it has a 300ppi resolution and video only needs 72ppi. How do I take advantage of the fact that it is high resolution image, and increase the physical dimensions of the image? Is there a way to do this?
    Thanks.

    Hi Marian.
    Thanks for the excellent link. And I believe it is spot on.
    ***Warning: This is an off topic rant. And it's over 500 words.***
    I did not get my first computer until 2001. Although I am a scientist at heart (university trained in chemistry and physics), and quite comfortable with technology, there was something deep within me that was resistant to buying a computer. Almost an inner foreboding. Even though I had already been using corporate computer nets (not the internet) since 1979, the PC seemed ominous to me.
    And the internet seemed even more ominous. To the point that I didn't hook up to the web until 2006. I had a sense that the web was a double edged sword, and had the potential to diminish its users. Even though I had never been on line and had very little idea of what it was really all about. What I found was what I feared. A wasteland punctuated by oases of useful information. A wasteland in the literal sense. For every second saved on the task at hand, a minute is wasted by the distractions that bombard us on the way to saving that second.
    I'm not saying that the web is bad. Just that it's fraught with danger. And the worst danger is the notion that a concrete answer to every question is just a Google away. And with that, the odieous notion that every question can be answered comprehensively in one quarter of an internet page, leaving the rest for advertising.
    I do quite a bit of writing, and my first experience at writing for the internet was a disaster. Among other things, I am a fly fishing guide. A new internet fly fishing magazine had requested I submit a series of articles. Personal anecdotes about my experiences. The first article I submitted was about 2400 words. They loved it, but they said it said it was too long. So, I did a rewrite. It came in at 1800 words. And the rewrite took more time and effort than writing the original 2400 words. And the article was diminished. And still too long. They wanted it shorter.
    At this point, I dug in my heels. I admitted I understood such constraints on paper publishing, but how could they insist on such constraints on web publishing? How much does is cost to add a web page to an article? It's just another page they could slather with advertising. To which they replied, no one will read an article longer than 1200 words. I was flabbergasted. I like long articles and books. I'm bummed when I come to the end. In the end, these folks had an editor hack it down to 1200 words and publish it over my signature without my knowledge or permission. When I saw the article, I was appalled. I didn't recognize it. And demanded they take it down.
    Maybe the publisher was right about his readers having short attention spans. I hope not, but I'm afraid it's true. And this mindset is the 500 pound gorilla in the room that few want to address.
    I'm not by any stretch suggesting we should turn back the clock of progress. Only that we need to be aware of the negative potential of any new technology. And resist that negative potential with all our hearts. Or our minds will suffer.
    FWIW.
    Peace,
    Lee

  • I cant save high resolution image from google safari 5.0.4

    mac os snow lepord macbook 10.6.6 and safari 5.0,4  wont save high resolution images while searching and exploring in google my way is that i search images larger than 2mb or for e.g then right click to image then open in new tab when this opened in new tab then i right click and then use save image some times save image as not shown some times when i right click menue shows open in dashbord save frame as like this  then save to hard if i follow this step that  will  drop image resolution,  when i open in photoshop
    some time grab image and drop it to hard works same resolution but i dont want drag and drop i want to save plz help i serach google but no find any suitable answer to save high resoltion iamge

    Update your system software to v10.6.7 and Safari 5.0.5
    Click Software Update from your Apple menu (top left in your screen).
    Restart your Mac after the updates are installed, try Safari.

  • Zoom into high resolution image

    Hi,
    Before starting to learn Muse, I've one big need: zooming into high-resolution images.
    I want to show how high the resolution is by letting the viewer zoom in with a loupe (or just scrolling with mouse wheel). I'm not talking about of a slideshow through some crops of the main image, but of an shrink- or grow effect of the image.
    Is this possible to achieve?
    Thanks for your insight,
    Dominique

    Could this be the solution, you are looking for?
    https://creative.adobe.com/addons/products/2406#.U8Jp1mIaySM

  • Rendering very high-resolution image sequence

    I'm in the process of rendering a very high-resolution image sequence (8k, 2:1 aspect ratio). Yes, in this case it really is necessary to render such a large image.
    Not entirely surprisingly, I'm getting an error during rendering. "Unable to allocate space for an 8000x4000 pixel image buffer."
    I have a relatively powerful machine (Mac Pro, 8 cores, 16gb ram, plenty of hard drive space)
    How should I tune the memory settings for this process? Also, are there any "under the hood" tweaks that I can make in AE to optimize it for rendering these large files.
    Thanks!

    We get questions like this often around here and I, too, will be interested by the destination for this rendering.
    Such a mosaic cannot be displayed from a single device so it's not necessary at all to render it as a complete frame. If you are going to a digital signage system, there are workarounds for importing the source video that should be provided by the signage driver's mfr. If you're going out to several synced display systems, render them as individual movies.
    bogiesan

Maybe you are looking for