[Interest] Combine PDF files into a single PDF File

d3fault d3faultdotxbe at gmail.com
Thu Mar 28 20:27:26 CET 2013


On Thu, Mar 28, 2013 at 11:06 AM, Michael Jackson
<imikejackson at gmail.com> wrote:
> I would like to take a bunch of PDF files and combine them into a single PDF file. Would this be possible with Qt? I see where I can print an HTML file to a PDF but I have 60 html files that I want to convert into a single PDF file.
>
> Thanks for any pointers
> ---
> Mike Jackson
>

Hi Mike, Qt 5 includes QPdfWriter [0] that makes generating multi-page
PDFs a breeze. I haven't used it myself, but the documentation makes
it look easy. I'm surprised there's no corresponding QPdfReader
(perhaps it's still a WIP?), but since you're using HTML as input you
can simply use QtWebKit to load the files and then render them to a
QPaintDevice (image, pdf, etc). There's an example in the docs showing
you how to do just that [1], but you're going to have to glue the
pieces together yourself to iterate over your 60 HTML files, rendering
and calling QPdfWriter::newPage() where appropriate.


d3fault

[0] - http://qt-project.org/doc/qt-5.0/qtgui/qpdfwriter.html
[1] - http://qt-project.org/doc/qt-5.0/qtwebkitexamples/webkitwidgets-framecapture.html



More information about the Interest mailing list