Search code examples
c#pdfpdfsharp

Open a document in PDFsharp


I have a method called Save which saves a PDF document at a specified location.

PdfDocument Document=new PdfDocument();
public void Save(string pathWithFileName)
{
     Document.Save(pathWithFileName);
}

Now I draw some paragraphs, using XGrahics class. Then I save the document using Save method. It works perfectly.

Now I want to reopen document, add some stuff and again save the document. How can I do this?


Solution

  • To open an existing document, use Open() with the correct pathname:

    PdfDocument document = PdfReader.Open(filenameDest); 
    

    Then make the changes. Finally save it as you already do:

    document.Save(filenameDest); 
    

    PDFsharp comes with several samples.
    You can download the complete sample code here:
    http://pdfsharp.codeplex.com/releases/view/618773

    Sample snippets and explanations can be found here:
    http://www.pdfsharp.net/wiki/PDFsharpSamples.ashx