J-F-Liu / lopdf

A Rust library for PDF document manipulation.
MIT License
1.67k stars 176 forks source link

Add the merging PDFs together example as a crate function #273

Open DaniD3v opened 7 months ago

DaniD3v commented 7 months ago

I think that merging two PDFs together is a very common use case. Would you mind adding that code to the library instead of just adding it as an example? I more or less copy-pasted it for now but that's not exactly a great solution.

I'm aware that this is a low-level library and a PDF merger doesn't exactly fit that category. If you're worried about that (or the unnecessary bloat it would add to the library) could you make it a new crate?

I know that I'm asking for a lot here but there's currently not really a crate that does that well. I even tried the more high level lopdf crates but they didn't work out for me.

J-F-Liu commented 7 months ago

I'm aware that this is a low-level library and a PDF merger doesn't exactly fit that category. If you're worried about that (or the unnecessary bloat it would add to the library) could you make it a new crate?

I don't have this worry, PR is welcome

williamdes commented 3 months ago

@Heinenen How do you view this request? It would definitely be a great feature to replace existing pdf mergers at work for example.

If some features are not implemented here, will this break while merging?

Heinenen commented 3 months ago

Sounds good.

I think this issue only aims to have the second example in the README "Merge PDF documents" wrapped in some library function. This would not add any functionality to lopdf, only convenience.

I can't speak to the current quality of the merging.

einoj commented 1 month ago

Not sure if this resolves the issue, but I added merge (by copying the code from example/merge.rs) functionality to the pdfutil so it can merge pdfs by running pdfutil --merge A.pdf B.pdf --output C.pdf. I did this because I was unhappy with how slow pdftk was when merging pdfs. It used over 1 second while pdfutil uses 14ms when merging the same pdfs!

https://github.com/J-F-Liu/lopdf/pull/340