New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Improved] PdfMerger: Allow to select the pages when merging documents #248
Conversation
Codecov Report
@@ Coverage Diff @@
## master #248 +/- ##
==========================================
+ Coverage 64.39% 64.40% +0.01%
==========================================
Files 600 600
Lines 39714 39758 +44
==========================================
+ Hits 25572 25607 +35
- Misses 14142 14151 +9
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as i'm concerned, this looks great.
I can't pretend I know too much on the subject, so someone else should be looking into this
} | ||
|
||
/// <summary> | ||
/// Merge the set of PDF documents. | ||
/// </summary> | ||
public static byte[] Merge(IReadOnlyList<byte[]> files) | ||
public static byte[] Merge(IReadOnlyList<byte[]> files, IReadOnlyList<IReadOnlyCollection<int>> pagesBundle = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
worth considering, a IReadOnlyList<(byte[] File, IReadOnlyCollection<int> Pages)>
signature.
This looks really useful. PdfPig looks nice for text extraction but is missing some features such as splitting / merging documents, modify existing documents, etc. Looks like you've put a lot of work into these areas @InusualZ thanks for the effort and hope these get merged soon. |
} | ||
|
||
/// <summary> | ||
/// Merge the set of PDF documents. | ||
/// </summary> | ||
public static byte[] Merge(IReadOnlyList<byte[]> files) | ||
public static byte[] Merge(IReadOnlyList<byte[]> files, IReadOnlyList<IReadOnlyCollection<int>> pagesBundle = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IReadOnlyCollection
or ICollection
are probably the wrong types here, since they do not guarantee order iirc, I'd recommend IReadOnlyList
since order is important here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just the doubt on collection vs list types.
PdfMerger: Allow to select the pages when merging documents Supersede UglyToad#245
Plus, Use IReadOnlyList instead of IReadOnlyCollection
69806b4
to
82806b7
Compare
Supersede #245
This PR offers a much better option and flexible approach to allow a page selection when merging documents. Also, I address the drawback of the other PR which was related to copying pages out of order. As a by product we now allow a page to be copied multiple times (By repeating the page index multiple time in the selection)
Illustration of the problem (Copied)
This is my main document
Now, let's try to merge the selection of pages (1, 3, 2) in that order:
I solve that by copying the page from bottom to top, instead of top to bottom like it was before. By doing so, we got rid of one recursive method (
DocumentMerger::CopyPagesTree()
). I think thanks to this last bit, we can introduceParallelism
, but that's a topic for another day.I would like to comment, that I don't like the current state of public PdfMerger API
cc @Poltuu I think this would entirely resolve #244, any comments?