We use an in house software to generate html templates for our clients. We spend to much time teaching our clients how to save the templates. We are trying to track down a way to export the html into a .oft template.
It is easy enough to create the files but the encryption or encoding of the file is throwing us through a loop.
Is there a library or code that we can use to convert an html file? We would prefer to work with php but we can work with other languages if needed.
You can try to use Redemption for that (it can be used from PHP - I am its author) - create an instance of the RDOSesssion object, call RDOSession.CreateMessageFromMsgFile (returns RDOMail object), set the RDOMail.HTMLBody property, save it as an OFT file (RDOMail.SaveAs(..., olTemplate)
Related
I am making an app that creates an invoice.
It is created in HTML and PHP using different data from a database.
I need to create a function that converts the page into a PDF and send it to a client.
I can not store it on server as it would mean to create a few hundred everyday. I need something like "http://FreeHTMLtoPDF.com/?convert=".$strBillURL; but it's not working any more.
Many thanks if you can help me!
I prefer to generate PDF files using some library that converts HTML/CSS to PDF. One of the libraries that provides this and is very easy to use is mPDF:
https://github.com/mpdf/mpdf
I have no information regarding what type of PDFs you generate, but in my projects I tend to generate them on the fly from the data in the database and do not store them at all.
There are also other options available for converting HTML to PDF, like wkhtmltopdf, but they might require additional knowledge in set up: https://github.com/wkhtmltopdf/wkhtmltopdf
I am doing a bulk generation of pdf files based on templates and I ran into big performance issues pretty fast.
My current scenario is as follows:
get data to be filled from db
create fdf based on single data row and pdf form
write .fdf file to disk
merge the pdf with fdf using pdftk (fill_form with flatten command)
continue iterating over rows until all .pdf's are generated
all the generated files are merged together in the end and the single pdf is given to the client
I use passthru to give the raw output to the client (saves time writing file), but this is just a little performance improvements. The total operation time is about 50 seconds for 200 records and I would like to get down to at least 10 seconds in some way.
The ideal scenario would be operating all these pdfs in memory and not writing every single one of them to separate file but then the output would be impossible to do as I can't pass that kind of data to external tool like pdftk.
One other idea was to generate one big .fdf file with all those rows, but it looks like that is not allowed.
Am I missing something very trivial here?
I'm thanksfull for any advice.
PS. I know I could use some good library like pdflib but I am considering only open licensed libraries now.
EDIT:
I am up to figuring out the syntax to build an .fdf file with multiple pages using the same pdf as a template, spent few hours and couldn't find any good documentation.
After beeing faced with the same problem for a long time (wanted to generate my pdfs based on LaTeX) i finally decided to switch to another crude but effective technique:
i generate my pdfs in two steps: first i generate html with a template engine like twig or smarty. second i use mpdf to generate pdfs out of it. I tryed many other html2pdf frameworks and ended up using mpdf, it's very mature and is developed since a long time (frequent updates, rich functionality). the benefit using this technique: you can use css to design your documents (mpdf completely features css) - which comes along with the css benefit (http://www.csszengarden.com) and generate dynamic tables very easy.
Mpdf parses the html tables and looks for the theader, tfooter element and puts it on each page if your tables are bigger than one page size. Also you have the possibility to define page header and page footer elements with dynamic entities like page nr and so on.
i know, using this detour seems to be a workaround, but to be honest, no latex, pdf whatever engine is as strong and simple as html!
Try a different less complex library like fpdf (http://www.fpdf.org/)
I find it quite good and lite.
Always find libraries that are small and only do what you need them to do.
The bigger the library the more resources it consumes.
This won't help your multiple-page problem, but I notice that pdftk accepts the - character to mean 'read from standard input'.
You may be able to send the .fdf to the pdftk process via it's stdin, in order to avoid having to write them to disk.
I've used a couple of days to think of a best practice to generate a PDF, which end users can customize the layout for themselves. The PDF output needs to be saved on the server or sent back to the PHP file so the PHP file can save it, and the PHP file needs to know that it went OK.
I thought the best way to do this was to use XML, XSLT and Apache Cocoon. But I'm not sure if this is possible or if it's a good idea since I can't find any information of people doing anything similar. It cannot be an uncommon problem.
The idea came when I read about Cocoon converting XML through XSLT to PDF:
http://cocoon.apache.org/2.1/howto/howto-html-pdf-publishing.html
and being able to take in variables:
http://old.nabble.com/how-to-access-post-parameters-from-sitemap-td31478752.html
This is what I had in mind:
A php file gets called by a user, the php file generates a source XML file with a specific name
The php file then makes a request to Cocoon (on the same web server) to apply the user defined XSLT on the XML file. A parameter will be needed here to know which XSLT to apply.
The request is handled by the PHP file and then saved as a PDF on the server, and can later be mailed away.
Will this work at all? Is there a better way to handle this?
The core problem is that the users need to be able to customize the layout on the PDFs themselves, and I need the server to save the PDF and to mail it later on. The users will use it for order confirmations, invoices, etc. And I wouldn't like to hard code the layout for each user.
I've had some good results in the past by setting up JasperReports Server and creating reports using iReport Designer. They're both available in F/OSS ("community") editions, though you can pay for support and value-adds if you need those things.
This was a good solution for us, since we could access it via the Java API for our Java system, and via SOAP for our PHP system. The GUI designer made tweaking reports very easy for non-technical business staff too.
I use webkithtml2pdf to generate my PDF:s. Just create a document with HTML and CSS for printing like you would usually do, the run it through the converter.
It works great for generating things like invoices. You can use SVG for logos and illustrations, and they will look great in print since they are vector based. Even rounded corners with dotted outlines works perfectly.
A minor gotcha is that the input html must have th htm or html file name suffix, so you can't use the default tempfile functions.
Given some user data.
Depending on the controller this data should be rendered either into a PDF or into a HTML file.
I really like the Zend way of the .phtml views combine HTML with very basic PHP.
Is there a similar approach for PDF and/or XLS that allows co-workers without strong programming background to change the PDF / XLS output?
Well, not really for people without a strong programming background.
Basically, rendering a PDF or an Excel view is the same as rendering an HTML View, so you could put the generating code into .phtml files, generate the appropriate output and serve it with the appropriate content-type. It's just a different representation of the data in the Model then. You can utilize ZF's context switch helper for this.
But, HTML is markup and PHP was designed to be embedded in it, so this is cake to do - if you know the appropriate frontend technolgies, like HTML, CSS and JavaScript.
With Excel, you could use the Microsoft's SpreadsheetML and embed PHP into it the same way. This requires the co-worker to have some knowledge of that markup language and XML in general though.
I am not aware of any markup for PDF files, so this has to be generated through an API (likely Zend_PDF) completely. Well, you could probably invent something to define which data goes where in XML, but that would take some thought.
Edit since this is tagged Zend Framework, you might also want to consider using the LiveDocX service, which uses a template based approach and can create PDF and Excel.
Use WKHTMLtoPDF to create a PDF from the HTML rendered view.
HTML and PDF are different planets. Making output libraries that supports both media-types and their respective strengths is almost undoable.
The best solution I can think of is pandoc, http://johnmacfarlane.net/pandoc/
It's not a MVC of it's own, but used as library it may suit your needs.
regards
//t
In an MVC world, the PDF would just be another view. So if you had /controller/action/view.phtml then you should theoretically be able to have a URL like /controller/action/view.pdf.
It's similar to how you can choose your output format with an API such as, say Twitter's. Hitting http://api.twitter.com/version/statuses/public_timeline.json will return the result in JSON; hitting http://api.twitter.com/version/statuses/public_timeline.xml in XML; and so on.
Some of the PDF libraries also include the ability to import/display HTML in the PDF contents, several with advanced properties for handling various formats and unsupported tags. Most that I've used have had strict stipulations about which DTD you need to adhere to.
I have a PDF document with some external links.
I'd like to parse the document, replace the destination of the links then close (and serve) the PDF document, all using PHP
I know I can do this with PDFLib but I don't want to incur this cost.
I could re-write the document with FPDF or DomPDF, but some of these PDFs are quite complex so this would be a major time investment.
Surely there must be a way to do this directly to PDF docs, using native PHP?
TIA
I don't think there is a text/hyperlink changer class for PHP. The closest products, like pdftk, only does higher-level stuff like merging, splitting and applying watermarks.
Changing a pdf is much more difficult than generating it, so you need to use a pdf editor like Nitro PDF (untested), or why not Acrobat/Illustrator/InDesign.
If you must use PHP, regenerating the PDF:s with one of the free classes seems to be your best choice. I like FPDF very much, it gets my recommendation. If you decide to use it, check out FPDI as well, it can use existing PDF files as a template, maybe it will help you. Good luck!