merge2pdf icon indicating copy to clipboard operation
merge2pdf copied to clipboard

Improved page selection

Open ajaxray opened this issue 4 years ago • 0 comments

The Problem

Currently, this library supports the following format for specifying page numbers of input PDF document:

input-pdf-name.pdf~<page-number>[,<page-number>]*
That means comma-separated page numbers after the file name joined with a ~. For example -

merge2pdf output.pdf input1.pdf~1 input2.pdf input3.pdf~2,3,4

This will merge 1st page of input1.pdf, full input2.pdf and 2nd, 3rd, 4th page of input3.pdf.

So we have to mention every page number specifically. It's fine when the command is being executed from an application. But this is not an easy option in case of running the command manually, especially when we have a large number of pages.

Proposal for improvement

To make it easy to provide page numbers, we can add support for the following formats to specify input pages.

  1. Fixed range of inclusive sequence numbers separated with -. Example: 2-7 will mean 2nd to 7th pages
  2. Open-ended range. To indicate the last page, $ will be used as the anchor character. Example: 4-$ will mean 4th page to last page
  3. Combining page number formats. All supported formats (including current one) can be used combinedly Example: 1,2,5-7,11-$ will include 1,2,5,6,7 and 11 to last page

Notes:

  1. The current page number format is parsed in this function.
  2. Based on #1 by @JohnnyMclain12

ajaxray avatar Jan 05 '20 17:01 ajaxray