Skip to content

nasccped/pdmers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

66 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

pdmers. Merge it all in a fancy way!

crates io license: MIT

Download pdmers and merge it all in a fancy way πŸŽ‰πŸŽ‰πŸŽ‰

Requirements

You'll need the rust toolkit (rustc compiler + cargo package manager) to install this program.

Tip

You can find both from the rust's official webpage.

Download

You can download this program both from source (github method) or using cargo packages registries:

With github:

  • clone into your machine
git clone https://github.com/nasccped/pdmers
cd pdmers
  • build and install
cargo install --path .

With cargo: (easier)

  • just use install subcommand
cargo install pdmers

Usage

To see the help panel, use the pdmers --help command:

A rust tool for PDF merging

Usage: pdmers.exe [OPTIONS]

Options:
  -i, --input <FILES|DIRS>...  PDF files to be merged
  -o, --output <OUTPUT>        Where to place the output file
      --override               Override output file if it already exists
      --allow-repetition       Pass same input twice
  -d, --depth <N|*>            Merge PDFs until reaches the `N` directory layer (use `*` to infinity)
  -p, --parent                 Creates parent directories of the output file (if they don't exists)
  -h, --help                   Print help
  -V, --version                Print version

pdmers enforces you to use an option, otherwise it'll print a message at stderr and return an error exit code (1).

$ pdmers
error: no arguments provided

Try using `pdmers --help` to get usage tips!

This app gets PDF files as input and generates a merged PDF file as output:

          +----------+
inputs => | do stuff | => output
          +----------+
               |
        +--------------+
        | catch errors |
        +--------------+

Input

The input flag expects a list of file and/or directory paths:

# You can use the flag's long name
$ pdmers --input file.pdf files-dir

# or the alias too
$ pdmers -i file.pdf files-dir

Warning

The program's assumes that all paths passed as input exists, otherwise it'll raise an not-readable-entry or non-existing-file error.

Composed paths

The program can't read paths that contains white-spaces ( ) because it separates input values by the space delimiter:

# so this:
$ pdmers -i file1.pdf file2.pdf

# becomes this:
# > input = ["file1.pdf", "file.pdf"]

# and this:
$ pdmers -i 'composed name file.pdf'

# becomes this:
# > input = ["composed", "name", "file.pdf"]

In other words, this program can't deal with compose-named paths and returns error: input doesn't exists.

Path repetition

By default, the program doesn't allow path repetition:

# this command will fail
$ pdmers -i file.pdf file.pdf

This approach avoids content duplicates. A clearer example:

# curdir/
# └─ other-dir/
#    β”” inner-file.pdf
#
# accidental duplicate :^(
$ pdmers -i other-dir/inner-file.pdf other-dir

If you're sure about what you're doing, use the allow-repetition flag:

# this will work fine
$ pdmers -i file.pdf file.pdf --allow-repetition

Passing directories

When passing directory(ies) as input, the program need to know how deep to catch files. You should use depth flag for this

# curdir/ ---------------> depth 0
# β”œ layer-one/ ----------> depth 1
# β”‚ β”œ layer-two/ --------> depth 2
# β”‚ β”‚ β”” layer-two-file.pdf
# β”‚ β”” layer-one-file.pdf
# β”” layer-zero.pdf
$ pdmers -i layer-zero.pdf layer-one --depth 1
# the program will only catches the file path + all layer-one inner
# files, since it's depth 1 (passed through the depth flag)

Tip

The depth flag can be used both with long name (--depth) and its alias (-d). It must be greater than 0 (since 0 means curdir). Use * to represent "no-depth" (all files ahead).

Directory references

The program doesn't allow directory references as input, like: ../outside-file.pdf or up-dir/../curdir-file.pdf. This was thought to avoid path/privileges exploiting.

Note

Current directory references (.) still works, btw!

Input ordering

The merge order will follows the input flag's values. If any of values is a directory, it'll follows the PathBuf::read_dir iterator order (commonly alphabetical order):

# curdir/
# β”œ inner/
# β”‚ β”œ a.pdf
# β”‚ β”œ b.pdf
# β”‚ β”œ c.pdf
# β”‚ β”” ...
# β”” curdir.pdf

# this:
$ pdmers -i curdir.pdf inner
# becomes this:
# input = ["curdir.pdf", "inner/a.pdf", "inner/b.pdf", "inner/c.pdf", ...]

Important

I planned to insert sorting methods but I gave up since rust's metadata (created + updated) reading isn't well supported on all platforms.

Output

The output flag means where to place the merged file. It must always be an pdf extension file:

# this will works:
$ pdmers -i some.pdf file.pdf --output output.pdf

# this won't
$ pdmers -i some.pdf file.pdf --output output.txt

Tip

You can use the flag alias (-o) too!

Override

If the output file path already exists, you can force save by using the override flag:

# curdir/ 
# β”œ file1.pdf
# β”œ file2.pdf
# β”” output.pdf
# not allowed, output already exists
$ pdmers -i file1.pdf file2.pdf -o output.pdf

# warning: this is dangerous but allowed
$ pdmers -i file1.pdf file2.pdf -o output.pdf --override

Parent dir

Placing the output file within a directory is allowed but it'll fail if the parents dirs doesn't exists. To force parent dirs + file creation, you can use the parent flag:

# tree before:
# curdir/ 
# β”œ file1.pdf
# β”” file2.pdf

$ pdmers -i file1.pdf file2.pdf -o output/file.pdf --parent

# tree after:
# curdir/ 
# β”œ output/
# β”‚ β”” file.pdf
# β”œ file1.pdf
# β”” file2.pdf

You can also use the flag alias (-p)!

License

This project is under the MIT license!

The logo was developed by me using graphite editor and it's under the Creative Commons Attribution-ShareAlike 4.0 International License Creative Commons License BY-SA 4.0.

About

πŸ“ƒ a rust tool for PDF merging

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages