PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Jul 04, 2024 5:18 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
PostPosted: Mon Feb 14, 2011 6:02 pm 
Offline

Joined: Fri Feb 08, 2008 4:29 pm
Posts: 1
I am trying to combine multiple PDFs into a single PDF. The PDFs come from SSRS, from some LocalReports that I processed. I am using PDFSharp, because it is already used through out the project. However, the outputDocument.addPage(page) methods throws an InvalidOperationException("Cannot change document.") exception. I have tried many different way of doing this, but I can't get it to work...

Here my method, where all the inputs have already been checked:

Code:
private static void saveFile(string fileName, params byte[][] bytes)
{
    try
    {
        PdfDocument outputDocument = new PdfDocument();
        for (int i = 0; i < bytes.Length; i++)
        {
            using (MemoryStream stream = new MemoryStream(bytes[i]))
            {
                PdfDocument inputDocument = PdfReader.Open(stream, PdfDocumentOpenMode.Import);
                foreach (PdfPage page in inputDocument.Pages)
                {
                    outputDocument.AddPage(page); //throws the exception !!!
                }
            }
        }
        outputDocument.Save(fileName); 
    }
    catch (Exception ex)
    {
        throw new Exception("Erreur lors de l'enregistrement du fichier", ex);
    }
}


From the examples I saw on the web, this seems to be the right way of doing this... I am opened to other suggestions for merging my PDFs, but I would rather not use another 3rd party lib, like ITextSharp, because PDFSharp is already used in the project.

If it matters, I am using VS2010 Pro on a Win7 machine.


Top
 Profile  
 
PostPosted: Tue Feb 15, 2011 9:32 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
Also discussed here:
http://stackoverflow.com/questions/4995 ... g-pdfsharp

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 46 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group