Open a document in PDFsharp

10,608

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

Share:
10,608
Mihai Alexandru-Ionut
Author by

Mihai Alexandru-Ionut

Husband, Father and Experienced Full Stack Software Engineer, focused on .NET technologies with a demonstrated history of working in the information technology and services industry. I consider programming an art and I improve my source-code until I no longer see the difference between profession and art. Bachelor and Master Degree in Computer Science, Babes-Bolyai University

Updated on August 11, 2022

Comments

  • Mihai Alexandru-Ionut
    Mihai Alexandru-Ionut almost 2 years

    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?

  • Mihai Alexandru-Ionut
    Mihai Alexandru-Ionut over 7 years
    Thanks a lot. One question more: When I open the document again for adding some text, I must to updated the XGraphics, isn't it ?
  • I liked the old Stack Overflow
    I liked the old Stack Overflow over 7 years
    The XGraphics object is associated with a PdfPage object. After opening the PDF file you have a new PdfPage and you will need a fresh XGraphics object for that page.