Merge / convert multiple PDF files into one PDF

959,794

Solution 1

I'm sorry, I managed to find the answer myself using google and a bit of luck : )

For those interested;

I installed the pdftk (pdf toolkit) on our debian server, and using the following command I achieved desired output:

pdftk file1.pdf file2.pdf cat output output.pdf

OR

gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=output.pdf file1.pdf file2.pdf file3.pdf ...

This in turn can be piped directly into pdf2ps.

Solution 2

Considering that pdfunite is part of poppler it has a higher chance to be installed, usage is also simpler than pdftk:

pdfunite in-1.pdf in-2.pdf in-n.pdf out.pdf

Just make sure you remember to provide out.pdf, or else it will overwrite the last file in your command

Solution 3

Try the good ghostscript:

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=merged.pdf mine1.pdf mine2.pdf

or even this way for an improved version for low resolution PDFs (thanks to Adriano for pointing this out):

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -sOutputFile=merged.pdf mine1.pdf mine2.pdf

In both cases the ouput resolution is much higher and better than this way using convert:

convert -density 300x300 -quality 100 mine1.pdf mine2.pdf merged.pdf

In this way you wouldn't need to install anything else, just work with what you already have installed in your system (at least both come by default in my box).

UPDATE: first of all thanks for all your nice comments!! just a tip that may work for you guys, after googleing, I found a superb trick to shrink the size of PDFs, I reduced with it one PDF of 300 MB to just 15 MB with an acceptable resolution! and all of this with the good ghostscript, here it is:

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/default -dNOPAUSE -dQUIET -dBATCH -dDetectDuplicateImages -dCompressFonts=true -r150 -sOutputFile=output.pdf input.pdf

cheers!!

Solution 4

This is the easiest solution if you have multiple files and do not want to type in the names one by one:

qpdf --empty --pages *.pdf -- out.pdf

Solution 5

Also pdfjoin a.pdf b.pdf will create a new b-joined.pdf with the contents of a.pdf and b.pdf

Share:
959,794
alcohol
Author by

alcohol

"Common sense isn't all that common."

Updated on July 08, 2022

Comments

  • alcohol
    alcohol almost 2 years

    How could I merge / convert multiple PDF files into one large PDF file?

    I tried the following, but the content of the target file was not as expected:

    convert file1.pdf file2.pdf merged.pdf
    

    I need a very simple/basic command line (CLI) solution. Best would be if I could pipe the output of the merge / convert straight into pdf2ps ( as originally attempted in my previously asked question here: Linux piping ( convert -> pdf2ps -> lp) ).

    • sabujp
      sabujp over 8 years
      ymmv, but this doesn't seem to have as good of a resolution in the output file as pdfunite and it also results in a file size larger than the output from pdfunite
    • Franck Dernoncourt
      Franck Dernoncourt over 7 years
    • Clément
      Clément about 4 years
      Whenever links are preserved or not by those solutions is discussed in this post. If you want to preserve the links (probably along with other annotations), use pdftk if want a command-line interface, pdfsam if you want graphical user interface, sejda if you want a web interface.
    • Alexis Wilke
      Alexis Wilke over 2 years
      The convert command line is from ImageMagick and it converts the PDF to an image before doing whatever else it will be doing.
  • Nate Kohl
    Nate Kohl about 14 years
    Using ghostscript also might work: gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=out.pdf in1.pdf in2.pdf in3.pdf ...
  • alcohol
    alcohol about 14 years
    I'd have to look more into the possible options/flags (because I don't want output in a file), but probably yes. Thank you for the suggestion.
  • Thomas
    Thomas about 11 years
    It is worth to mention that pdftk can merge encrypted pdfs while pdfunite cant
  • taxilian
    taxilian almost 11 years
    Poppler is also very fast, from my tests
  • Danilo Bargen
    Danilo Bargen almost 11 years
    It is fast, but it seems to break hyperlinks. See blog.dbrgn.ch/2013/8/14/merge-multiple-pdfs
  • mlissner
    mlissner over 10 years
    Just make sure you remember to provide out.pdf, or else it will overwrite the last file in your command, sigh.
  • Jocelyn delalande
    Jocelyn delalande over 10 years
    package for pdfunite is poppler-utils in debian but may not be present in old debian releases.
  • Torben
    Torben over 10 years
    Cannot recommend this. The size of the the resulting PDF is far too big. For example: Pdfunite gives me a 75MB file while Ghostscript packs everything into 1MB.
  • Adriano P
    Adriano P over 10 years
    Nice tip, gs runs very fast and it compresses a lot. However, the quality improved a lot after I used this param: -dPDFSETTINGS=/prepress
  • Aaron R.
    Aaron R. over 10 years
    Hmmm... @Torben I just packed 300+ pdfs (total of 13MB) into a single PDF using this utility and I got a 12MB file at the end. Maybe it was the version you used? I am on OpenSUSE 12.2, using pdfunite version 0.20.0.
  • Torben
    Torben over 10 years
    @Aaaron My comment was a bit misleading. What I meant is that pdfunite doesn't optimize the filesize. For example: 10 similar pdfs (slides for a presentation) of 1MB result in a ~10MB pdf when I use pdfunite. With ghostscript the resulting pdf is <1MB.
  • Kiran K Telukunta
    Kiran K Telukunta about 10 years
    gives better resolution with pdftk compare to convert in default options.
  • ahrobins
    ahrobins about 10 years
    In my case pdfunite did not produce a usable PDF file. When I loaded it with evince I got lots of errors. The gs solution worked.
  • Ben Ruijl
    Ben Ruijl almost 10 years
    This is not lossless.
  • arielnmz
    arielnmz almost 10 years
    You can convert -compress lossless sub1.pdf sub2.pdf sub3.pdf merged.pdf, but the resulting file size's could be way too big. I'd suggest convert -compress jpeg -quality 90 sub1.pdf sub2.pdf sub3.pdf merged.pdf instead.
  • r_31415
    r_31415 almost 10 years
    I found that -dPDFSETTINGS=/prepress has the very nice effect of rotating pages that are too wide and force annoying horizontal scroll bars.
  • Julia Ebert
    Julia Ebert almost 10 years
    This involves converting everything to raster images, it seems, which is definitely not the best, especially when dealing with text-based PDFs.
  • bright-star
    bright-star over 9 years
    This is nice and succinct, but breaks hyperlinks.
  • mdrozdziel
    mdrozdziel over 9 years
    pdfjoin (pdflatex) fails with files with lots of pages. Failed to merge to 1k pages files.
  • lepe
    lepe over 9 years
    You can use: pdfunite *.pdf out.pdf assuming no other pdf exists in that directory and their order is preserved by "*". If its not preserved, using ranges: filename_{0..9}.pdf solves it.
  • Nathan Tuggy
    Nathan Tuggy about 9 years
    Given how similar this looks to the original question, it seems like this should have been a comment, not an answer. With a bit more rep, you will be able to post comments. Until then, please do not use answers as a workaround.
  • peterh
    peterh about 9 years
    @Silfheed No, it answers the question! Although the answer maybe should have more elaborated.
  • ryantm
    ryantm almost 9 years
    pdfunite worked much worse for my use case than pdftk. I was trying to combine together copies of a particular form into the same pdf. In pdfunite they were linked, in pdftk they were separated and could be filled out individually.
  • MariuszS
    MariuszS almost 9 years
    @Torben The file is smaller with gs because with default settings image has reduced quality (screen-view-only quality, 72 dpi images). With -dPDFSETTINGS=/printer file size is almost identical (high quality, 300 dpi images).
  • Torben
    Torben almost 9 years
    @MariuszS Even though you might be right for some special cases, you're wrong with you're general assumption. I just merged 133MB of PDFs (84 files exported from Inkscape), which contain bitmaps, vectorgraphics and text, into one PDF with a size of 1.6MB. I used /prepress for that and /printer even reduced the size to 1.3MB. Even though I zoomed in and printed a part, I couldn't find any visible difference between the single PDF and the merged version. I'm pretty sure Ghostscript compares the merged PDFs and stores shared content just for one time.
  • Torben
    Torben almost 9 years
    Add the following line to your .bash_profile and you have a nice shortcut: pdfmerge() { gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -sOutputFile=$@ ; } This saves you some typing, if you have to use the command a lot. The usage looks like this: pdfmerge merged.pdf mine1.pdf mine2.pdf
  • Michal Gonda
    Michal Gonda over 8 years
    I tried to find description for -dBATCH flag but couldn't. Even man gs doesn't say anything. But great and without any additional programs!
  • jmiserez
    jmiserez over 8 years
    pdftk file1.pdf file2.pdf cat output out.pdf will output the merged file as out.pdf
  • user829755
    user829755 over 8 years
    almost a copy of what the OP has described as not working
  • Sablefoste
    Sablefoste over 8 years
    Since Imagemagick is based upon Ghostscript, if you already have it, you can use it as well; convert file1.pdf file2.pdf outputfile.pdf.
  • markgalassi
    markgalassi over 8 years
    Do not use convert for postscript or PDF files unless you go from vector to raster and never go back. It is hard to overstate what a bad idea this is.
  • markgalassi
    markgalassi over 8 years
    Do not use convert for postscript or PDF files unless you go from vector to raster and never go back. It is hard to overstate what a bad idea this is.
  • markgalassi
    markgalassi over 8 years
    Do not use convert for postscript or PDF files unless you go from vector to raster and never go back. It is hard to overstate what a bad idea this is.
  • firegurafiku
    firegurafiku over 8 years
    What is the point of using $(ls *.pdf) in place of simple wildcard *.pdf?
  • sabujp
    sabujp about 8 years
    pdfjoin breaks annotations or additional non graphics items
  • a coder
    a coder about 8 years
    pdftk is not available for EL7 systems due to missing dependency libgcj.
  • Paul Rougieux
    Paul Rougieux about 8 years
    @DaniloBargen pdfunite doesn't break external hyperlinks. I have merged documents with links. Links were kept functional. But pdfunite might break internal hyperlinks as indicated in the blog you mentioned.
  • Mahendar Patel
    Mahendar Patel about 8 years
    @NateKohn @IcyFlame Unfortunately it did not work for me - said Unknown device: pdfwriter. Like you I preferred that approach because I had it installed already. pdftk worked like a charm though.
  • gaoithe
    gaoithe over 7 years
    pdfunite worked well for me. preserved resolution of original pdfs. pdf size simple addition of original pdfs. convert -compress lossless did the same as convert, resolution lost and file size much increased. pdfunite version 0.22.1 vs ImageMagick 6.7.8-9. 69k + 130k pdf => 198k with pdfunite, => 771k with convert. text+gfx(originally odt) + gfx(pdf print to pdf) pdf.
  • v_2e
    v_2e over 7 years
    The "URW Palladio L" font became invisible after pdfjoin'ing the pages.
  • Charles-Édouard Coste
    Charles-Édouard Coste over 7 years
    If you don't want to type each file name : pdftk ``ls *.pdf`` cat output out.pdf (with just one backticks instead of two, but I didn't manage to render it with the stackoverflow markdown parser)
  • JAB
    JAB over 7 years
    @RobertSmith Interestingly, when I tried the first command it rotated some pages (that seemed to be the same proportions as the others) while the /prepress version did no rotation.
  • Zelphir Kaltstahl
    Zelphir Kaltstahl over 7 years
    @Charles-EdouardCoste You can use two backticks as surrounding backticks if you want to use backticks inside. Or three, if you want to use double backticks. Not sure if it goes even higher. But backticks is not recommended anymore in Bash, so better would be to use $(ls *.pdf)
  • Zelphir Kaltstahl
    Zelphir Kaltstahl over 7 years
    @alcohol What does the cat in this command (not in general) do? I was able to merge two pdfs without that and don't see any issues with the resulting pdf.
  • Calaf
    Calaf over 7 years
    pdfunite usually works well, but if it says "Unimplemented Feature: Could not merge encrypted files ", pdfjoin is a nice alternative. For whatever reason, pdfjoin doesn't complain of encryption.
  • alcohol
    alcohol about 7 years
    @Zelphir cat is the operation here (that pdftk performs), not the shell command.
  • Bhoom Suktitipat
    Bhoom Suktitipat about 7 years
    Works for me natively (probably) without any installation on MacOs Sierra (OsX).
  • salotz
    salotz about 7 years
    Doesn't work with a pdf I have gives Unimplemented Feature: Could not merge encrypted files ('MR1418_introduction.pdf'). But pdftk was able to handle it, albeit admonishing me for not having some passwords you don't need.
  • z0r
    z0r almost 7 years
    pdftk is neat because you can easily select page ranges to merge: pdftk A=file1.pdf B=file2.pdf cat A1-3 B1 output out.pdf
  • awelkie
    awelkie almost 7 years
    I like this solution because it keeps section headers that I can use to jump around with my pdf software
  • Campa
    Campa almost 7 years
    Incredibly much faster than convert, and the resolution does not get worse. TOP
  • enkiv2
    enkiv2 over 6 years
    "Argument list too long" indicates that you're going over the shell's allocated buffer size for the environment -- it's not actually a limitation of the tool. In such a case, switching to Python may be overkill, since you can just batch: find input -name *.pdf | xargs -P1 -n500 sh -c 'pdfunite "$@" output-date +%s.pdf' && pdfunite output-*.pdf output.pdf (This will create batches of 500 files processed serially, make the resulting temporary files sort in the right order, and produce an appropriate output file; you'll need to clean up the temporary files after)
  • Mingwei Zhang
    Mingwei Zhang over 6 years
    For my usage, pdftk somehow just stuck and not producing anything, while gs gives perfect result. convert's resolution download is true (with default setting).
  • Nostradamnit
    Nostradamnit over 6 years
    Still works to perfection. I didn't see any size change either; 9.2 mb of files made a single 9.2mb file. Didn't have any hyperlinks, so can't comment on that aspect.
  • Diego 72
    Diego 72 over 6 years
    Since GCJ is deprecated link), pdftk is as well (most distros phased it out already). A nice alternative is pdfunite and the other poppler-utils.
  • palik
    palik over 6 years
    v2.08 of pdfjoin doesn't proper work for me. One of the input PDF-files contains filled forms. But no inputs appear in the result PDF-file.
  • bjd2385
    bjd2385 about 6 years
    Just put the following in a bash script: pdfunite $@ out.pdf
  • Antek
    Antek about 6 years
    gs for joining documents apparently created under Windows gave me this error Missing glyph CID=48, glyph=0030 in the font EAAAAB+Tahoma,Bold . The output PDF may fail with some viewers. and indeed, on the default Ubuntu viewer I couldn't browse it
  • Egel
    Egel almost 6 years
    Additionally with reference to @firegurafiku answer, with ls *.pdf wildcard you lose a control over the order of merged files. In an example, the following list: 1.pdf, 2.pdf, 3.pdf, ..., 10.pdf, ..., 100.pdf will actually be merged like 1.pdf, 10.pdf, 100.pdf, 2.pdf, 3.pdf (due to default Linux way of ordering files - here you have more details about this problem - stackoverflow.com/q/22948042/1977012).
  • Pysis
    Pysis almost 6 years
    Beautiful answer. I was having a ton of frustration ever since I heard Mac's Preview application could help, but I barely got it to work the first time, and none the second time I needed it. The biggest trouble was it not being determinant with its actions. I used to be able to drag entire PDF files over, but tried invidiual thumbnails, and also had saving issues between a new copy and at all! So this solution was a nice break. The only additional task I had was throwing in a GIF image at the end using Preview since Ghostscript could not handle that. Also installed from Homebrew!
  • k.stm
    k.stm over 5 years
    So much this. Parabola for instance doesn’t package pdftk anymore either because of its dependance on gcj, for which support has been dropped I believe. Despite searching for pdf manipulation tools via pacman -Ss pdf, I missed this. Thanks for this answer! I should receive way more upvotes, so it shows up right next to suggestions for pdfunite or pdftk.
  • Tom Russell
    Tom Russell over 5 years
    @AaronR Happy to report working well on openSuse Leap 42.3. Its speed is quite blazing, combining 100-odd pages in less than a second.
  • supergra
    supergra over 5 years
    This is perfect. Using gs (all variants listed above), a simple merge of two PDFs, 2MB and 500Kb, was taking minutes to complete and resulting in a 40MB file! pdftools completes instantaneously with identical file size.
  • Winny
    Winny over 5 years
    Breaks hyperlinks.
  • Winny
    Winny over 5 years
    This preserves hyperlinks. Nice!
  • adonese
    adonese over 5 years
    I'm just gonna run this command so that it will be saved to my fish history! I'll definitely need it in the future.
  • Jimbo
    Jimbo over 5 years
    The version from the official website doesn't work. This answer does as of January 2019 (still official).
  • mvreijn
    mvreijn over 5 years
    A note about PDF Forms. Thusfar, pdftk is the only tool I have tried that preserves my PDF forms exactly as they were (functional in any PDF reader plus Acrobat Reader).
  • Admin
    Admin over 5 years
    @Winny, for me it didn't preserve hyperlinks. any idea why?
  • Winny
    Winny over 5 years
    @EnanAjmain I used gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -sOutputFile=output.pdf a.pdf b.pdf c.pdf This worked for me
  • Admin
    Admin over 5 years
    I used it too. But in my case it didn't work. I then used an online service. Thanks for replying.
  • MiniMax
    MiniMax about 5 years
    The gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -sOutputFile=merged.pdf mine1.pdf mine2.pdf can be shortened to the gs -q -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -o merged.pdf mine1.pdf mine2.pdf. From Documentation: "As a convenient shorthand you can use the -o option followed by the output file specification as discussed above. The -o option also sets the -dBATCH and -dNOPAUSE options. This is intended to be a quick way to invoke ghostscript to convert one or more input files."
  • Wallace Kelly
    Wallace Kelly almost 5 years
    On my fresh install of Linux Mint, this ran in the Terminal window without requiring any installs or path adjustments. Nice!
  • Freedom_Ben
    Freedom_Ben over 4 years
    pdftk is deprecated and no longer available in Fedora repos for example. If you can't use pdfunite cause encryption, then try pdf-stapler: github.com/hellerbarde/stapler
  • JonShipman
    JonShipman over 4 years
    This also works well in windows with WSL. Install ghostscript from apt first.
  • doak
    doak over 4 years
    I was used to pdfunite, but it resulted today in a 850 MB PDF (original 24 MB). pdftk did it with 44 MB, gs with only 32 MB (both with top resolution as far as I can tell).
  • David Granqvist
    David Granqvist over 4 years
    qpdf seems to break hyperlinks in the document
  • Skippy le Grand Gourou
    Skippy le Grand Gourou over 4 years
    pdftk also allows to duplicate pages within a single document : pdftk input.pdf cat 1-10 10 10 10 10-20 output output.pdf would produce input.pdf with 5 times the page 10.
  • Jonathan Holvey
    Jonathan Holvey over 4 years
    Although difficult to get your head around the complex options to start with, qpdf is a very handy and powerful tool. Online documentation is available here
  • minexew
    minexew over 4 years
    It seems that page numbers from individual documents are also not preserved. (pdfunite version 0.73.0)
  • ostrokach
    ostrokach over 4 years
    sudo apt-get install poppler-utils
  • Yai0Phah
    Yai0Phah over 4 years
    Strange enough. After merging with gs, some of pages are rotated.
  • Siwoku Adeola
    Siwoku Adeola about 4 years
    This worked perfectly and also gave a clearer merged document that the other commands I tried out. Thanks for the post.
  • mario ruiz
    mario ruiz about 4 years
    OMHO the best to tool to do these type of tasks
  • alphaGeek
    alphaGeek almost 4 years
    gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -sOutputFile=merged.pdf mine1.pdf mine2.pdf This worked perfectly on cygwin @Win 10 64 bit machine. Thanks
  • Henrik Pingel
    Henrik Pingel almost 4 years
    pdfjam package doesn't include pdfjoin script anymore. You can find the script here
  • Hashim Aziz
    Hashim Aziz almost 4 years
    Came here looking for a qpdf solution but didn't want to wade through the documentation yet again to figure it out, thank you.
  • Gabriel Staples
    Gabriel Staples almost 4 years
    WATCH OUT! The last input parameter is where the program writes the output, so if you accidentally forget out.pdf and do pdfunite in1.pdf in2.pdf instead of pdfunite in1.pdf in2.pdf out.pdf, you'll have just accidentally written in1.pdf right on top of in2.pdf, ruining it! Don't do that.
  • lmat - Reinstate Monica
    lmat - Reinstate Monica over 3 years
    Using a shell wildcard is great as long as the order works for you! Check the order first with echo *.pdf | tr ' ' $'\n' or so!
  • qdread
    qdread over 3 years
    @Winny I needed to add dPrinted=false to preserve hyperlinks. Otherwise it broke the links for all but the first pdf. See tex.stackexchange.com/questions/245801/…
  • Rainb
    Rainb over 3 years
    pdftk is a hell to install
  • KCD
    KCD over 3 years
    Different pages size, want to "shrink to fit"? Try another tool included in poppler: pdftocairo -pdf -paper A4 in.pdf out.pdf ... and make backups as people point out you can override inputs
  • tejasvi88
    tejasvi88 over 3 years
    Or you can install it anyway. Total size of dependencies is < 100 kb.
  • tejasvi88
    tejasvi88 over 3 years
    pdftools is a wrapper for PyPDF2. See this answer.
  • pts
    pts over 3 years
    Ghostscript does many lossy transformations (e.g. page rotation, image quality degradation and dropping some metadata) during PDF-to-PDF conversion. If you want to have a peace of mind of having all PDF features intact, then don't use Ghostscript.
  • Rainb
    Rainb over 3 years
    @pts sure, or you can just use custom flags, so that ghostscript doesn't use lossy compression. superuser.com/questions/360216/…
  • caram
    caram over 3 years
    If pages in the even.pdf file are reversed (typical when you scan on a non-double-sided scanner), you will want to use this instead: qpdf --collate --empty --pages odd.pdf even.pdf z-1 -- merged.pdf
  • pts
    pts over 3 years
    @Rainb: The PDF output of Ghostscript is lossy even if it is configured to use lossless image compression, because Ghostscript ignores some PDF features (e.g. interactive).
  • Ethan Brown
    Ethan Brown over 3 years
    I did not find that pdfunite created unreasonably large files. My two input files were both about 500k and the resulting output file was about 1 MB as one would expect.
  • Antonin GAVREL
    Antonin GAVREL about 3 years
    Nice script. You can arrange the order by prefixing each page with "A_", "B_" etc or simply add 'z' if one document is at page 1 and you want it to be at the last page, assuming your files are named with letters and digits, and not starting with 'z'.
  • Charles D Pantoga
    Charles D Pantoga about 3 years
    can be installed with homebrew +1 havent tried yet
  • xZero
    xZero about 3 years
    I was fast to use it and not read the comments, so it overwrote the last file. Silly me run "pdfunite *.pdf" and then wondered where's the output file until I realized... Luckily I had a backup; It's always a good idea to have a backup.
  • Tarick Welling
    Tarick Welling about 3 years
    This is quite the undervalued answer. The qpdf tool is great
  • Andrea Vacondio
    Andrea Vacondio about 3 years
    This is no longer open source
  • Doberon
    Doberon about 3 years
    it's true, qpdf is multi platform, portable and possible used at scripts
  • Doberon
    Doberon about 3 years
    for extract qpdf "in.pdf" --pages . 1 -- "out.pdf"
  • Ingo Mi
    Ingo Mi almost 3 years
    What is the command for papersize A4? Thanks for your answer.
  • Admin
    Admin almost 3 years
    Qpdf is high in quality and actively maintained, which makes it a much better option than pdftk.
  • Admin
    Admin almost 3 years
    Pdftk is old, buggy, and not well maintained. It uses a fork of the iText library that is buggy. It has poor error handling and can fail on pdf 1.5 input files. Qpdf is a higher-quality alternative for most of its functionality.
  • tripleee
    tripleee almost 3 years
    "Likely to be installed" depends entirely on your Linux distro. It's probably true e.g. for Ubuntu and very probably not true for Alpine or Gentoo.
  • tripleee
    tripleee almost 3 years
    @bjd2385 An unquoted $@ is always an error; you want "$@". Without the quotes, it will break on file names which contain whitespace or shell metacharacters.
  • tripleee
    tripleee almost 3 years
    The package name probably refers to a Debian package.
  • rickhg12hs
    rickhg12hs over 2 years
    So far, qpdf seems to generate the best output where other viewing tools find no errors/issues.
  • Rainb
    Rainb over 2 years
    Ghostscript tends to fail if with some pdfs, what a shame
  • chillitom
    chillitom about 2 years
    In the case of an error about encrypted documents try the following first: ls *.pdf | xargs -I '{}' qpdf --decrypt {} --replace-input
  • Gabriel Staples
    Gabriel Staples about 2 years
    pdfunite broke my output PDF by deleting entire pages of fields I had filled in in this PDF here. I ran pdfunite in1.pdf in2.pdf out.pdf. I don't know why it did that, but it must be some issue with the metadata which stores the filled-in text fields inside the fillable PDF, or something. Using pdftk, as described here, however, worked perfectly: pdftk in1.pdf in2.pdf cat output out.pdf.
  • Gabriel Staples
    Gabriel Staples about 2 years
    I then ran my tool: pdf2searchablepdf out.pdf for good measure, to ensure the PDF metadata fillable fields get turned into an image and then OCRed back into a PDF, in order to remove the metadata fields to ensure I don't have problems printing it at Staples, which also was unable to print properly some of the metadata fields in the original PDF.
  • Gabriel Staples
    Gabriel Staples about 2 years
    pdftk worked when pdfunite did not. pdfunite erroneously removed metadata fields from a fillable PDF, as I described here. pdftk did not--it performed correctly.
  • Timo
    Timo about 2 years
    I had two files on Mac Monterey, each 1 M resulting in output of 15 M. I then used --object-streams=generate and the output size was normal.
  • Pavol Travnik
    Pavol Travnik about 2 years
    I wonder why it is so low. This is exactly what I was looking for. Thank you.
  • Doberon
    Doberon about 2 years
    QPDF is great. Use it this way to extract pages 1-10 from input.pdf and save it as output.pdf: qpdf input.pdf --pages . 1-10 -- output.pdf