Announcement Announcement Module
Collapse
No announcement yet.
HTML to PDF conversion Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • HTML to PDF conversion

    My front end designers created a great looking html front end. This front end is pretty complex containing lots of images and CSS. One of my project requirements is to be able to export this front end to PDF. The PDF has to be pretty much an exact copy of the HTML version. I was looking at the AbstractPdfView examples and they seem to be pretty manual. I doubt I could manually recreate this great looking html front end using itext, although it's a great tool. If I already have the finished HTML, is there an easy way to create a PDF version? Thx.

    -karl

  • #2
    Good question. Spring's PDF support isn't designed to do this. But there must be a library out there somewhere...

    Comment


    • #3
      There is htmltopdf library, but it don't work with complex html

      regards

      Comment


      • #4
        Re: HTML to PDF conversion

        Hello kbaum,
        I'd like to know where did you find the example of AbstractPdfView, because 'till now I've just found API at this link: http://www.springframework.org/docs/...ctPdfView.html.
        Thanks in advance,
        Claudia
        Originally posted by kbaum
        ... I was looking at the AbstractPdfView examples and they seem to be pretty manual. ...
        -karl

        Comment


        • #5
          Can't think of a magic answer to this, but if you used the Apache FOP toolkit, you might do the following:

          1. Translate your CSS into an importable XML document containing xsl:attribute-set elements. This would then mirror your existing style.css.

          e.g.

          myStyle { font-weight: bold; }

          vs

          <xsl:attribute-set name="myStyle">
          <xsl:attribute name="font-weight">bold</xsl:attribute>
          </xsl:attribute-set>


          2. Maybe use some front end technology that allowed you to get at the rendered HTML, i.e. JSP is likely out, but Velocity might work since you could programmatically render the HTML into some buffer so you could subsequently process it into an XML-FO document , and then into a PDF. You may even have to cleanup the rendered HTML before trying to convert it into an XSL-FO document, i.e. make it well-formed, handle special characters.

          If you can't find a magic answer, then depending on how much XSLT/PDF building you've done, I'd also suggest you look at using the Apache FOP toolkit to build a single PDF document so you fully understand the gap between laying out HTML and PDF document -- so that you can be sure it's just not easier to build each PDF separately/manually from it's HTML version.

          Comment


          • #6
            Html-&gt;pdf

            Hey karl!

            not sure if you are still looking, but:


            I cant vouch for any of these, but check out the links on:

            http://www.w3.org/Style/CSS/


            there are a bunch(including a servlet) that should work (one even passes the ACID test)

            Comment


            • #7
              pdf possibilites

              Perhaps you are only looking for free software to do what you ask and/or software integrated with your app, however I just thought I'd mention that the Adobe Acrobat product really is great for this kind of thing. I've used it before to create a pdf copy of a site I wanted to perserve - you basically point it to a starting page and tell it how many levels to retrieve and it does - creating linked pdf. Of course you need more than the reader to do this.
              Anyway, just thought I'd mention it.

              Comment


              • #8
                PDF to HTML - Converts PDF files to HTML files while seeking to preserve the original page layout (as best as technically possible).

                Comment


                • #9
                  If you are at the XHTML level (e.g JSF/Facelets), then the integration from there on could be done as

                  http://today.java.net/pub/a/today/20...-renderer.html

                  It is problably simple to integrate in other frameworks, too. Although you should be aware that there is no 1:1 mapping between rendered HTML and e.g PDF.

                  Comment


                  • #10
                    Given 5million times I would use iText over anything else on any given day.

                    Comment


                    • #11
                      HTML to PDF Converter for .NET

                      Hi,

                      You can try the HTML to PDF converter from Winnovative Software at http://www.winnovative-software.com .

                      The HTML to PDF Converter Library for .NET can be used as a general purpose component for converting web pages and HTML code to PDF documents and images in any format or it can be used to easily create PDF reports directly from ASP.NET pages to benefit from the great power of standard ASP.NET databound server controls.

                      The converter can convert the web pages to PDF documents with selectable texts and objects or to PDF documents with an embedded image.

                      You can add footers and headers to the rendered document, set the page size, page orientation and PDF compression level. The library can be used from any .NET 2.0 application (windows forms, ASP.NET web sites or command line tools). When using the converter from ASP.NET web sites you can opt for the HTML to PDF Converter ASP.NET server control to benefit from the Visual Studio 2005 design time capabilities.

                      The .NET 2.0 libraries, ASP.NET server controls and the provided samples are royalty free. Version 2.3 adds the possibility to define custom page breaks in the HTML code. You have to simply put the b tag where you want split the page.

                      Comment


                      • #12
                        You can convert your html to postcript using html2ps and then use ghostscript to convert your postcript to pdf.

                        Comment


                        • #13
                          everyone hates pdfs. look into a tool to convert the page to a image. we use htmlsnapshot, works very well. much better than any pdf converter i found, pdf is such a crap format and they're always making it worse. adobe sucks minus photoshop.

                          Comment


                          • #14
                            Originally posted by lloyd.mcclendon View Post
                            everyone hates pdfs. look into a tool to convert the page to a image. we use htmlsnapshot, works very well. much better than any pdf converter i found, pdf is such a crap format and they're always making it worse. adobe sucks minus photoshop.
                            Well... going OT but. PDF is not that bad. Sure, it has many features that most users won't need (could be called bloat) but the last time I checked doing text search on an image wasn't that straight-forward. Or print formatting an image of hight 120000px for any number of printers.

                            HTML to PDF conversion is difficult because there is no true 1:1 mapping (most browsers don't even render the same HTML the same way) but that isn't the problem of the PDF format). There will be open (and openish) XML document formats gaining market share but they too will have strengths and weaknesses.

                            Comment


                            • #15
                              Recently I had the same problem, I haven't found a 100% satisfactory solution, but... you can use Apache FOP which gets the basic work done.
                              FOP needs a stylesheet for xhtml->fo conversion, grab it from here:
                              http://www.antennahouse.com/XSLsample/XSLsample.htm.

                              iText is great but it won't convert your html into pdf.

                              Comment

                              Working...
                              X