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.
You can install
itextsharp
from nuget and copy and paste this code in a c# app Call theSplitPDFByBookMark()
method and pass the pdf filename. This code is going to search for you bookmarks and done!GroupDocs.Merger allows to split source document into several resultant documents. Document splitting can be performed in different ways by specifying page numbers array or start/end page numbers and setting different PageSplitOptions modes. Lets see how to split the document to several one-page documents (by exact page numbers):
This code snippet will produce:
Document Name Page Numbers
document_0 3
document_1 6
document_2 8
Learn more here.
Disclosure: I work as a developer evangelist at GroupDocs.
This code is based on the PDFsharp library
http://www.pdfsharp.com/PDFsharp/
If you want to split by Book Mark then here is the code.
call this function where ever you want and pass the source and destination folder path
I met the same question, you can use itextsharp component tools to split the document
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