We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Saving each page as a document

Thread ID:





63208 Jun 29,2007 02:15 PM UTC Jul 4,2007 12:33 PM UTC ASP.NET Web Forms (Classic) 3
Tags: PDF
Asked On June 29, 2007 02:15 PM UTC

How do you save each page in a PDFDocument in a separate PDF file to disk? No matter how hard I try, I end up with a "Duplicated" ArgumentException thrown by Syncfusion.Pdf.Implementation.Utilities.SortedListEx`2.Add(TKey key, TValue value).

Here's my code:

PDFDocument document = new PDFDocument();
//Create a page in the document
document.LastPage.Graphics.DrawText(new Point(0, 0), "This is my first page", myfont);

//Create another page
document.LastPage.Graphics.DrawText(new Point(0, 0), "This is my second page", myfont);

//Save each page as a pdf file to disk
int i = 0;
foreach (IPDFPage page in document.Pages)
PDFDocument tempDocument = new PDFDocument();
IPDFPage tempPage = page;
tempDocument.Save(@"c:\MyFolder\PdfFile" + i.ToString() + ".pdf");

I have tried:
- Saving to a FileStream instead of directly to disk.
- Using for instead of foreach.

No matter what I do, I end up with the "Duplicated" ArgumentException thrown by SortedListEx`2.Add(). What am I doing wrong?

Here's the stack trace from ASP.NET:
Syncfusion.Pdf.Implementation.Utilities.SortedListEx`2.Add(TKey key, TValue value) +216
Syncfusion.Pdf.Implementation.Primitives.PDFDictionary.Add(String name, IPDFSaveable element) +60
Syncfusion.Pdf.Implementation.Objects.Fonts.PDFFont.AddRequiredItems() +64
Syncfusion.Pdf.Implementation.Objects.Fonts.PDFTrueTypeFont.AddRequiredItems() +10
Syncfusion.Pdf.Implementation.Objects.Fonts.PDFFont.Save(PDFWriter writer) +19
Syncfusion.Pdf.Implementation.Objects.PDFArchiveStream.SaveObject(IPDFSaveable obj, PDFReference reference) +220
Syncfusion.Pdf.Implementation.Collections.PDFRootCollection.DoArchiveObject(IPDFSaveable obj, PDFReference reference) +90
Syncfusion.Pdf.Implementation.Collections.PDFRootCollection.SaveIndirectObject(IPDFSaveable obj, PDFWriter writer) +369
Syncfusion.Pdf.Implementation.Collections.PDFRootCollection.Save(PDFWriter writer) +149
Syncfusion.Pdf.PDFDocument.Save(PDFWriter writer) +230
Syncfusion.Pdf.PDFDocument.Save(Stream stream) +83

Ajish [Syncfusion]
Replied On June 29, 2007 05:17 PM UTC

Hi Gustav,

Thank you for your interest in Essential Pdf.

It is possible to extract pages using Essential Pdf. The following code will take a pdf file and save each page of the pdf file as a seperate document,

using Syncfusion.Pdf;

PDFDocument ldoc = new PDFDocument(txtUrl.Text);

int i = 0;
foreach (IPDFPage page in ldoc.Pages)

PDFDocument doc = new PDFDocument();
doc.Save("Page" + i.ToString() + ".pdf");


Here is a sample for your reference,

Sample: http://websamples.syncfusion.com/samples/PDF.Windows/F63208/main.htm

Sample details:

1) The sample application takes a pdf document as input and saves each page as a seperate document.

Kindly take a look and let me know if you have any questions.


Replied On July 4, 2007 09:56 AM UTC

I'm sorry, this isn't working for me. The application just freezes when I try to load the PDF and has to be forcibly quit. It might be because of the PDF document I'm trying to load?

Anyhow, I have attached a simple Web application that tries to achieve what I'm discussing. On my development system (Windows XP, IIS, ASP.NET 2) it fails with the "Duplicated" exception I mentioned in my first post.

The first page is created without issues. It's the second page that fails.

You might need to set permissions on the SplitPdfDocuments folder.

FWIW, I'm using assemblies with version

Many thanks for assistance with this.


Melba Winshia [Syncfusion]
Replied On July 4, 2007 12:33 PM UTC

Hi Gustav,

Could you please open a new direct – trac incident with subject line as Forum 63208 - Saving each page as a document? So that it would be possible for us to provide more details regarding this issue.



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon