Open a document in PDFsharp
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
![Mihai Alexandru-Ionut](https://i.stack.imgur.com/f5vZc.jpg?s=256&g=1)
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, 2022Comments
-
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 usingSave
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 over 7 yearsThanks 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 over 7 yearsThe
XGraphics
object is associated with aPdfPage
object. After opening the PDF file you have a newPdfPage
and you will need a freshXGraphics
object for that page.