Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open a document in PDFsharp

Tags:

c#

pdf

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?

like image 705
Mihai Alexandru-Ionut Avatar asked Aug 03 '26 04:08

Mihai Alexandru-Ionut


1 Answers

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

like image 137
I liked the old Stack Overflow Avatar answered Aug 05 '26 20:08

I liked the old Stack Overflow