- Home
- Forum
- ASP.NET MVC
- Splitting a big pdf by each page
Splitting a big pdf by each page
The following signature shall be provided "public static List SplitThatPDF(byte[] myFile)", how to do this ? (e.g. a document with 30 pages, shall be splitted into 30 single pages returning as List)
SIGN IN To post a reply.
3 Replies
SK
Surya Kumar
Syncfusion Team
February 20, 2017 12:41 PM UTC
Hi Syress,
We appreciate your interest towards Syncfusion products.
We can split all the pages in a document and it can be stored in a list, We have attached code snippet for saving each page to list as individual PDF document. Please find the code snippet below
|
//Converting loaded file to Byte array
byte[] dataBytes = File.ReadAllBytes("loaded.pdf");
//Saving individual pages as PdfDocument
List<PdfDocument> seperatePDF = SeperateAsPDF(dataBytes); |
Code snippet for saving each page to list as individual PdfDocument:
|
public static List<PdfDocument> SeperateAsPDF(byte[] myFile)
{
//Load document.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(myFile);
List<PdfDocument> PdfList = new List<PdfDocument>();
for(int i = 0; i < loadedDocument.Pages.Count; i++)
{
PdfDocument doc = new PdfDocument();
doc.ImportPageRange(loadedDocument, i, i);
PdfList.Add(doc);
}
return PdfList;
} |
Essential PDF also allows to split the pages of an existing PDF document into multiple individual PDF documents. The following code snippet explains the same.
|
//Load document.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Output.pdf");
//Sets pattern.
const string destFilePattern = "Output" + "{0}.pdf";
//Split the pages into separate documents.
loadedDocument.Split(destFilePattern);
//close the document
loadedDocument.Close(true); |
Please let us know if you need any further information regarding this.
Regards,
Surya Kumar.
SS
Syress Sumartha
February 27, 2017 11:16 AM UTC
The Return type should be List<byte[]> . Can you adjust this ?
SK
Surya Kumar
Syncfusion Team
February 28, 2017 11:06 AM UTC
Hi Syress,
Thanks for your update.
Please find the modified code snippet as you requested, please let us know if this satisfies your requirement.
|
//Converting loaded file to Byte array
byte[] dataBytes = File.ReadAllBytes("loaded.pdf");
//Saving individual pages as PdfDocument
List<byte[]> seperatePDF = SeperateAsPDF(dataBytes); |
Code snippet for saving each page to list as individual Byte array:
|
public static List<byte[]> SeperateAsPDF(byte[] myFile)
{
//Load document.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(myFile);
List<PdfDocument> pdfBytes= new List<PdfDocument>();
for(int i = 0; i < loadedDocument.Pages.Count; i++)
{
MemoryStream stream = new MemoryStream();
PdfDocument doc = new PdfDocument();
doc.ImportPageRange(loadedDocument, i, i);
doc.Save(stream);
pdfBytes.Add(stream.ToArray());
stream.Dispose();
}
return pdfBytes;
} |
Regards,
Surya Kumar
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
-
SS Syress Sumartha
- Feb 17, 2017 01:38 PM UTC
- Feb 28, 2017 11:06 AM UTC