开发者

Recommendation? for our specific HTML -> PDF project

I have a question which I see from googling has been discussed at length.. but I want to know what you would recommend based on our particular needs. I want to be on the right track before I find out a-week-of-work later that I chose the wrong tool (a tool which works, but whose peculiarity, in the end, would rule it out for our project).

I read some good threads on Stack Overflow already on this topic.. but they have people making recommendations all over the map.. as I would expect - generally, our needs and experiences are all over the map. And again, here I want to know what you would recommend given our specific situation.

We have a dynamic HTML page that displays 30 "address labels" within the dimensions of one single US-letter-size document. We want the user to be able to print the single letter-sized page and have the content line up perfectly (as it does in the browser) for the Avery address label (printed) sticker paper which they will use to then peel the 30 stickers and affix to physical product. The HTML page is ~ 200k worth of HTML (divs and tables), text, gifs, jpgs, a barcode PNG graphic, and heavy use of exacting CSS - CSS2 as well as a touch of CSS3 (CSS3 property transform), i.e. this:

/* --- for firefox, safari, chrome, etc. --- */
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
开发者_运维百科/* --- for ie --- */
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=1);

...which I use to rotate (90 degrees) a barcode which I grab off of this site/service: http://www.barcodesinc.com/generator/index.php

We could drop that barcode PNG/service only if I could easily replace it with another... and the barcode must be rotated 90 degrees - to thus fit in its tiny (vertically-oriented) alloted slot on each of the 30 "address label cells".

  • I wish we had budget for the server version of PrinceXML ;-) ... but no luck.
  • I have never used any PHP libraries like FPDF or TCPDF, but am concerned about speed; corporate users (on various browsers) will need the pdf in real time. They may be patient and wait for the final PDF if keep the solution free.. but if it takes minutes to generate, that is a minus point.

    Also I am not sure how good these are for HTML -> PDF (as opposed to straight PDF from scratch).. plus not sure how good is the CSS support. Our page is a bit of an HTML/CSS kludge.

  • I have used the command-line tools HTMLDOC and wkpdf, but the former lacked the CSS I need now, and the latter introduces margin that kills it for exact address-label formatting (plus this project is on Linux).

My PHP skills are not super strong yet.. but I am willing to do whatever it takes to pull any solution together. In case you have any familiarity with any PDF generation tools that you feel would fit the need here, then please advise!


If you're looking for something like Prince XML but without the expense, I would try DocRaptor.com. It's an online pdf generator that converts from HTML. I used the free plan and it was pretty easy.

Good luck!

Nate


My usual suggestion for such things is wkhtmltopdf. Your webkit-transform thing should still work, as will anything else that works across web kit browsers.

Fair Warning: I haven't used it myself.


Are you set on an HTML->PDF solution? I would not go down that path: HTML was never meant for printing ... it has no concept of pages, and differences in OS, browser, installed fonts, etc. can all make something as precise as label printing a nightmare. Why not generate the PDF directly, and bypass HTML altogether?

Unfortunately, I've never done the sort of automated PDF generation you are talking about. If I had to hack something together quickly, the first two things that pop into my head are:

  • Generate PS output, and feed to a utility like ps2pdf
  • Generate TeX output, and feed to pdflatex

I would worry about the robustness and speed of both of those: it would depend heavily on how many requests you're processing per second.

Looking at the ldd output for gs (ps2pdf), it would appear it might use Cairo for PDF generation. There are PHP, C, Python, etc. bindings available for Cairo.


I do not recommend that you try to convert your HTML to PDF. As exact as you have been able to get it in HTML, the conversion will never preserve that precision.

I have used FPDF and find that it is easily fast enough for realtime PDF generation of even complex documents. FPDF allows precise placement (measured in inches, or your preferred units) of elements on a PDF page, so alignment should not be a problem. I suspect you will find it substantially easier to generate the PDF than it was to generate the HTML.

There are user-contributed scripts for barcode generation so that you can do that within FPDF if you choose. Or you can embed an image that you've generated elsewhere.

EDIT: Just to follow up, I checked the FPDF site and there is a user-contributed script to generate labels in common Avery formats. It's less than 200 lines of code, so even if you want to write your own, I suspect you can do it quite easily.


In the end, we did give PrinceXML a go (through the pay-as-you-go service "docRaptor". Thanks to Nate for that tip). As of now Prince does not recognize the CSS3 transform I needed for rotating the barcode in our pdf.. but I found another barcode generator that rotates it at the time of drawing, before serving.. so that worked out. There may be better ways to generate pdfs.. but for those of us who spend all our time hacking web pages, there is something very satisfying about having pdfs generated formatted exactly as HTML/CSS source. All the fuss over Prince is well earned, I discovered. Thanks to all who replied.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜