metaist / pdfmerge

Command-line utility for merging, splicing, and rotating PDF documents.
http://metaist.github.io/pdfmerge/
Other
121 stars 24 forks source link

In which order does the script merge files when the path specified is a directory containing PDF files ? #31

Closed Xsmael closed 2 months ago

Xsmael commented 3 months ago

Hi, i'd like to know In which order does the script merge files when the path specified is a directory containing PDF files ?

Cause i used it on a dir containing hundreds of files named this way: page-1.pdf, page-2.pdf, page-3.pdf and so on. but i realised that it didn't follow that order and pages are mixed up in the merged pdf.

How to control the order ?

metaist commented 3 months ago

It merges them in the order they appear on the command line. Are you running it something like:

pdfmerge *.pdf

Glob patterns like that are sorted by the shell (explanation), but it's alphabetically sorted so it's page-1.pdf, page-10.pdf, page-100.pdf.

You can fix this by adding some zeros in the names of your PDFs so that they sort correctly: page-0001.pdf, page-0002.pdf, ..., page-0010.pdf, ..., page-0100.pdf, etc.

Let me know if that works for you.

metaist commented 2 months ago

Closing for now. If you still have issues, let me know.

Xsmael commented 2 months ago

It merges them in the order they appear on the command line. Are you running it something like:

pdfmerge *.pdf

Glob patterns like that are sorted by the shell (explanation), but it's alphabetically sorted so it's page-1.pdf, page-10.pdf, page-100.pdf.

You can fix this by adding some zeros in the names of your PDFs so that they sort correctly: page-0001.pdf, page-0002.pdf, ..., page-0010.pdf, ..., page-0100.pdf, etc.

Let me know if that works for you.

Oh that makes sense now. I assumed it was alphabetically sorted but forgot about this weird thing when sorting numbers. I ended up using vscode emmet to generate a comma separed list of the file names in the right order which i could just copy and past in the CLI. And it worked. I think your suggestion would work too.

As for the command, i was just running this being inside of the directory where my pdf files were:

   pdfmerge .