wkhtmltopdf: Is it possible to merge PDF files?
Asked Answered
I

2

12

Using this library wkhtmltopdf, is it possible to merge 2 pdf files. I need to generate a report and merge the report with some attached documents.

Generation of report is done, converting from HTML to PDF. But I need to merge the resulting PDF with some other PDFs

Intubate answered 11/9, 2013 at 8:47 Comment(1)
You can use PDFtk which has all kinds of options for merging PDFs.Alarcon
H
16

wkhtmltopdf doesn't provide support for merging PDF's. You can accomplish this using GhostScript. It's a pretty powerful tool and frequently used by Linux users.

You can use the following command:

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=out.pdf in1.pdf in2.pdf

You can try these links for further reading:

In case you want it for Linux refer

EDIT: As stated by @nenotelp there are other tools available as well. The part that @nentelp mentioned is regarding the handling of bookmarks which is better with iText or iTextSharp. If this is your requirement you can certainly opt for other tools.

P.S. - Google Ghostscript. You will find tons of references.

Hargeisa answered 11/9, 2013 at 9:11 Comment(3)
This is true, BUT I would highly recommend iText or iTextSharp for the merge - wkhtmltopdf bookmarks are not your dads bookmarks, they don't play well with GhostScript. They don't play well with pdftk either. I know that you are about tho say something like "Ghostscript with pdfmark can easily deal with that" - it should, but it won't :P.Granado
Also see https://mcmap.net/q/400529/-merge-pdf-39-s-with-pdftk-with-bookmarks with an awesome answer regarding this topic. When I tested it, it did not work with wkhtmltopdf bookmarks. Also the TOC get screwed, but there's nothing you can do about that - wkhtmltopdf TOC anchors are not unique ARGFHH! I have complained about this into the bug system but Antialize is too busy and nobody else has stepped up yet because of the QT mess.Granado
the problem with gs is sometimes thrown undefinedfilename error,Osrock
I
4

You can combine multiple html files to one output pdf file with this library. For e.g if u have:

my-html-file-nr-1.html
my-html-file-nr-2.html
....
my-html-file-nr-n.html

You can simply:

wkhtmltopdf my-html-file-nr-* output.pdf
Infusible answered 22/8, 2018 at 10:54 Comment(2)
He specifically asked about merging two PDFs.Decretal
if i create 1 pdf form 2 html-s do you know if this will restart the page count? so on the footer html1 shows the page count, then does the html2 restart the page count?Machute

© 2022 - 2024 — McMap. All rights reserved.