Search

I've been searching for an open source solution to easily generating a PDF from multiple XHTML pages using CSS to style the document. Allen mentioned that an XSL-FO solution was in the works back in October 2006 with hopes of offering services and support for SVG, XSL-FO to PDF, and merchant payment processing. The subject has been revived with some comments by Allen on some forthcoming announcements regarding specialized hosting services for supporting these technologies.

Commercial Products

Open Source Solutions

Most of the open source solutions appear to be written in Java

Has anyone had any experience with CSStoXSLFO? I'm testing locally in Mac OS X 10.4 with Java 5.8.8, and I have Apache FOP installed and working (with MacPorts), but I'm clueless as to how to get CSStoXSLFO integrated. I'd rather not have to add the extra step of writing the XSL-FO file when I've been able to use PrinceXML to create the PDF without this intermediary step.

I have been looking into this too, over here are some resources, Ros pdf class might be a solution.

Beyond vector based and logos, for a purely textual application do you think pdf has any advantages over 'just' printing the xhtml+css page?

The advantage for me would be one-step compilation of multiple pages as a PDF file. For example, I might have a 20 page document, formatted as individual pages to provide a simulation of the final output of individual pages with XHTML and CSS for a business proposal. I have developed a proposal builder with Symphony, but I can't figure out the last step to get the data to print. Sure, I can print 20 individual PDF pages and assemble them in Adobe Acrobat Professional, but that's tedious and prone to user error.

At the moment, the designers in our agency who work on Adobe InDesign CS3 are the bottleneck for printing professional looking proposal documents. Word and Neo Office are nightmares to work with for page layout, so we've tried to avoid these apps at all costs. Symphony works great for easily editing a document with CSS styles driving the layout, then building a document tree for the table of contents. I've been able to export XML from InDesign, then match the XML structure as a document export in Symphony, but it's extremely tedious to format the InDesign document to import the XML data seamlessly.

I've been trying to offload the creation of proposal documents to those who are producing them, rather than wasting the time of the designers. So, I've been looking for an open source / server side solution to compiling a PDF from either an XML document or a set of XHTML and CSS documents that could be built with Symphony.

I came across a PHP 5 class that I may be able to use called dompdf, however, it does not support absolute positioning, according to the documentation on CSS 2.1 compatibility (only static positioning is currently supported). I'd have to rewrite my CSS, as I'm using absolute positioning, but it wouldn't be too difficult. I would also need to learn PHP, and I am a total neophyte.

Other PHP solutions I've found do not take into account CSS stylesheets, so it means reproducing layout in raw PHP code, which might be fine for a single invoice or order receipt, but not for complex multiple page documents.

So, until I find a solution to the problem of formatting output for print, it's pointless to finish building the proposal builder in Symphony.

More of a side note, but have you tried populating an ID CS3 template using Symphony-output XML? I'm not suggesting it as a solution, but I've always wanted to test that out but never had the need to...

@ashooner, I have tried it. The setup takes a while to ensure the XML from Symphony is in the format that InDesign expects and to prepare the InDesign document to receive the data. Probably the greatest challenge is dealing with white space issues. It works, but I haven't had the time to tag the entire document to do a full import.

I was trying to see what I could accomplish without needing any proprietary software, but I may end up coming back to InDesign as the solution.

We might be getting close to a solution for multiple page PDF documents by creating a single HTML file with page-break-after, page-break-before and page-break-inside rules added to the CSS for the print style sheet. The solution I have come up with for individual pages requires some means of turning off the automatically generated headers and footers in the web browser and setting a custom page to have margins set to zero. So far, I have had the best results in Safari.

Problem Solved

Create a single HTML file with each "page" contained by a div with class="page".

For a US letter size 8.5" x 11" page (612 x 792 points), use the following CSS to create page breaks (the following code adds a 24pt margin to the page layout):

.page {
    width:564pt;
    height:744pt;
    margin:0;
    padding:24pt;
    border:0;
    page-break-before:always;
}

Add an id attribute to allow navigation to individual pages:

<div class="page" id="pg5">

Use Safari to print with a custom page with margins set to zero. Now if only we could get all browsers to respect the need to control margins for a cross-browser solution.

I just found this, which would have been so useful, had I known about this resource before:

CSS Discuss: PrintStylesheets

Awesome! thanks for the tip bauhouse. I was needing something like this for a reporting app I created with Symphony.

Glad that helped, Alistair!

You could turn this problem around... How about storing your content at google docs, it can transform to pdfs and (it's api) has many advantages. (still figuring out how to strip the raw html content from a doc of its inline unneeded stylin gtags though; ninja...?) Next you could pull in the content for your xml>xslt

@ashooner Using tcpdf script on a few sites.. and it works great! Ability to style using CSS and spit out a well presented PDF doc is an awesome feature.

@moonoo2
So you just dropped it in your workspace like a JS library, an extension for it woudln't make any sense? Do you create xhtml and css and then let tcpdf convert it to pdf? I thought tcpdf required you to code your pdf from scratch, so how do you get your xml content inside the tcpdf php template?

With an intermediary PHP script you could convert a rendered Symphony page (HTML) into a PDF — TCPDF has a writeHTML method:

http://www.tcpdf.org/examples/example_061.phps

I came across this article today, which seems to be a promising project with a different approach to the same problem.

pdf.js is a technology demonstrator prototype to explore whether the HTML5 platform is complete enough to faithfully and efficiently render the ISO 32000-1:2008 Portable Document Format (PDF) without native code assistance.

Github repo is here

From what I understand the pdf.js project is to display PDF's, not generate them?

@nickdunn TCPDF looks amazing! You could definitely spit the HTML from FrontendOutputPostGenerate into a something.

I know of some service providers that show you an overview of your invoices on login, and then you can select to view them. Some offer actual pdf downloads, but others just a html page to view.
One might wonder: the visitor (on mac) can easily save the page as pdf by themselves. However Windows doesn't have a native way of saving a html page as pdf?...Or would those users be satisfied downloading a html page?...

I need to read threads... I just spent ages looking at HTML to PDF converters, and Nick already found the only decent one.

There is joliprint.com/get-the-button as a free off site idea for quick page to pdf creation. Not easily styled though.. TCPDF looks the best, I've only used it with self built php sites so not sure about the bridging option for symphony.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details