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.
Unfortunately, activation email could not send to your email. Please try again.

Saving each page as a document

Thread ID:

Created:

Updated:

Platform:

Replies:

63208 Jun 29,2007 10:15 AM Jul 4,2007 08:33 AM ASP.NET Web Forms (Classic) 3
loading
Tags: PDF
Gustav
Asked On June 29, 2007 10:15 AM

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.CreatePage();
document.LastPage.Graphics.DrawText(new Point(0, 0), "This is my first page", myfont);

//Create another page
document.CreatePage();
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)
{
i++;
PDFDocument tempDocument = new PDFDocument();
IPDFPage tempPage = page;
tempDocument.Pages.Add(tempPage);
tempDocument.Save(@"c:\MyFolder\PdfFile" + i.ToString() + ".pdf");
tempDocument.Close();
}

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 01:17 PM

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.Pages.Add(page);
i++;
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.

Regards,
Ajish.

Gustav
Replied On July 4, 2007 05:56 AM

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 5.102.0.51.

Many thanks for assistance with this.

pdftest3.zip

Melba Winshia [Syncfusion]
Replied On July 4, 2007 08:33 AM

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.

Thanks,
Melba

CONFIRMATION

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.

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.

;