Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

split PDF into multiple files in C#

Tags:

c#

pdf

We have a C# Windows service that currently processes all the PDFs by reading the 2D barcode on the PDF using a 3rd party component and then updates the database and stores the document in the Document repository.

Is there a way I can cut the files after reading the barcode and store it as another document?

For example if there is a 10 page document, it should split into 10 different files.

Thanks.

like image 659
acadia Avatar asked Aug 26 '10 11:08

acadia


1 Answers

You can use a PDF library like PDFSharp, read the file, iterate through each of the pages, add them to a new PDF document and save them on the filesystem. You can then also delete or keep the original.

It's quite a bit of code, but very simple and these samples should get you started.

http://www.pdfsharp.net/wiki/Default.aspx?Page=ConcatenateDocuments-sample&NS=&AspxAutoDetectCookieSupport=1

like image 164
Marko Avatar answered Sep 27 '22 22:09

Marko