4 Replies Latest reply: Jan 9, 2009 5:33 AM by 843810 RSS

    Converting html to pdf

    843810
      Hi All,
      I want to convert html pages to pdf using java. Can anyone help me in converting html pages to pdf documents(Using java code).Thanks in advance,
      Deepu.
        • 1. Re: Converting html to pdf
          416044
          Read the HTML via a Reader class, parse the string, create PDF code and write it via the java.io. classes ... what do you expect?
          • 2. Re: Converting html to pdf
            843810
            Try xml fop

            http://xmlgraphics.apache.org/fop
            • 3. Re: Converting html to pdf
              801524
              try

              http://www.lowagie.com/iText/
              • 4. Re: Converting html to pdf
                843810
                HTML to PDF with Java, using OpenOffice.org - example here: [http://www.dancrintea.ro/html-to-pdf/|http://www.dancrintea.ro/html-to-pdf/]

                You can use OpenOffice.org, running as a server and command it remotely for document convertion.

                Besides HTML to PDF, there are also possible other convertions:
                doc --> pdf, html, txt, rtf
                xls --> pdf, html, csv
                ppt --> pdf, swf

                Code example:
                -----------------------------------------------------------------------------------------------------------------------------------------
                import officetools.OfficeFile; // this is my tools package
                ...
                FileInputStream fis = new FileInputStream(new File("c:/test.html"));
                FileOutputStream fos = new FileOutputStream(new File("c:/test.pdf"));

                // suppose OpenOffice.org runs on localhost, port 8100
                OfficeFile f = new OfficeFile(fis,"localhost","8100", true);

                f.convert(fos,"pdf");
                -----------------------------------------------------------------------------------------------------------------------------------------