0

I want to create pdf file accordingly lastname alphabet order and then this PDF document will be used for double-sided printing. When creating a pdf file, there should be page breaks on the first letter of last name and then a blank sheet before starting the next letter. If 'A' letter finish printing on an even page, "B" letter can begin printing on the next odd page. If 'A' letter finish printing on an odd page, the next even page should be blank. 'B" letter should begin on the next odd page. Another way to say this is that every letter should begin printing on the next available odd page.

I have tried telerik report to generate pdf file but in telerik report I did not able to track page numbers when generate pdf file.

  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Jan 06 '23 at 08:40

3 Answers3

1

You could call the PDF tool kit pdftk as external process from your program:

With pdftk.exe yourfile.pdf dump_data, you can find the number of contained pages.

Example output:

c:\TEXTS>pdftk.exe example.pdf dump_data
InfoKey: Creator
InfoValue:
InfoKey: Title
InfoValue: Citations, mots célèbres 2
InfoKey: Producer
InfoValue: wkhtmltopdf
InfoKey: CreationDate
InfoValue: D:20130904112136+02'00'
NumberOfPages: 5

If NumberOfPages is odd, use a command like to following to append an empty page:

pdftk.exe A=yourfile.pdf B=empty_page.pdf cat A B output yourfile_even.pdf

Once you have evened all files, you can concatenate them:

pdftk.exe A=a.pdf B=b.pdf C=c.pdf cat A B C output result.pdf

A more recent alternative to pdftk is the open source tool qpdf.

Axel Kemper
  • 10,544
  • 2
  • 31
  • 54
1

You can produce each file separately, then run cpdf -pad-multiple 2 in.pdf -o out.pdf on each, to add a blank page if needed. Then you can merge them all with cpdf 1.pdf 2.pdf 3.pdf ... -o final.pdf.

johnwhitington
  • 2,308
  • 1
  • 16
  • 18
0

Generally using qpdf or cpdf executables the extra page can be added as required, https://stackoverflow.com/a/73575464/10802527 however it seems from the tone of this question you wish to do that "inline" during PDF building, In that case it is best NOT to build A.pdf B.pdf and add single blanks before merge it is better to build the full A-Z.pdf then inject the blanks as needed.

This requires you build a personalized solution where you extract page numbers so lets say without your example

  • Chapter A = page 1
  • Chapter B = page 4
  • Chapter C = page 6
  • Chapter D = page 9

so you know you need inject blank before page 4 to move 4 to 5 and that will move 6 to 7 so now you don't need to shift page 6 however page 9 is now page 10 so WILL now need inject blank before page 10. So you need to keep track of the previous up lifts.

You can write that as a simple subroutine to call one of the libraries that reports the page content as number and ideally also includes a blank page insertion, method.

in pseudo code you need 2 trackers

  • if last inject was even next is odd and vice versa (flip flop)
  • page inject is current + previous blanks (incremental value)

NOTE the later answer by JohnWhitington from cpdf shows that this will be easiest in above case by use
cpdf -pad-before in.pdf 4,9 -o output.pdf

cpdf will do the 2nd shifting incremental part so 4 becomes 5 (& 6 becomes 7) and also old 9 will then move to 11 but you will still need to determine the flip flop state (odd or even) of which pages need a blank before them.

roughly you need to

set flag=EVEN

loop NEXT PAGE
if page is last page then exit from loop
is page a section heading ?
  then if page odd and flag is ODD save page num and set flag as EVEN and go NEXT PAGE
       if page odd and flag is EVEN go next page
       if page even and flag is ODD go next page
       if page even and flag is EVEN save page num and set flag as ODD and go NEXT PAGE
else page not section heading go NEXT PAGE
  • 1 keeps flag as EVEN
  • 2 & 3 is not section
  • 4 is section, is even, flag is EVEN, save page num, set flag ODD
  • 5 is not section
  • 6 is section, is even, flag is ODD (skip save num)
  • 7 & 8 is not section
  • 9 is section, is odd, flag is ODD, save page num, set flag EVEN

... etc.

K J
  • 8,045
  • 3
  • 14
  • 36