0

I am trying to create a PDF for a system that is a merge of reports and letters for a print run.

Basically I have a folder full of PDF report forms and then a PDF full of cover letters. The cover letters are generated using an SSRS rdlc file, which has page breaks between each letter. What I need to end up with is a single PDF which goes:

Cover letter / Report / Cover letter / Report etc etc

Now I've found code to Merge PDFs from this thread:

Merging PDFs with ITextSharp

(Thanks Tommy)

This is great and I can easily adapt this to interlace the letters and reports, but I cannot 100% guarantee that the cover letter is a single page.

Is there a way for me to scan a PDF using iTextSharp during the merge process to detect the page breaks? That way I can wait until after the break to add the report.

Thanks in advanced,

J

Community
  • 1
  • 1
  • I don't understand in which way the code you refer to doesn't do what you want, even for multi page documents. – mkl Mar 02 '16 at 13:53
  • (1) That code is old. One can use the `addDocument()` method now instead of having to loop over the pages. (2) One can always ask a `PdfReader` for the total number of pages in the document: `reader.NumberOfPages`, so what's your problem? *I'm voting to close this question because it's unclear what you're asking.* – Bruno Lowagie Mar 02 '16 at 16:02
  • I'll try again: I have one PDF document which contains 10 cover letters. Each cover letter matches up to a PDF report, which is fetched from a folder with 1000s of these reports. What I want is to take the PDF with the cover letters and split them out into another single PDF which goes Cover Letter -> Matching Report, Cover Letter -> Matching Report etc etc. Once this single (large) PDF is generated it's sent to a printer, which prints, folds and stuffs them into envelopes. The code I have included works fine, but only when the cover letter is a single page. I cannot guarantee it will be. – user2819833 Mar 03 '16 at 16:18

1 Answers1

0

If you are looking to separate document combined from multiple reports then you may use these strategies:

  1. Check for some predefined phrase (like cover page) on every page to decide if this page is the cover page or not. So you should just iterate page by page, rea text using PdfTextExtractor.GetTextFromPage(), search for given keywords in this text to find if this page is the cover page (separator page) or not.

  2. More reliable way (if you are able to control how initial documents are generated) are based on barcodes stamped on cover pages to detect start of new document during batch scan. In addition, barcode (QR Code, for example) may contain some additional information about the next sub-document.

Eugene
  • 2,820
  • 19
  • 24