PdfSharp - a free component for editing pdf in .Net
By ganton ~ June 23rd, 2008. Filed under: .Net tools.
As i wrote in my previous post ABCpdf is a nice component but I need something for free. I searched for some free component and I found PdfSharp. During the search I found a documentwhich is a good starting point when one starts to look for a .Net pdf component.
As i wrote I need a component only for editing fields in an existing pdf. PdfSharp seems to be a right component but I had some problems with it. The first problem is the data is not visible in the field and it appears only when the field is focused. Sawan wrote about the same problem. The second problem I still have is with displaying Cyrillic letters (????? are displayed). The first problem has a decision but the second I think no at the moment.
string outputFile = @"c:\_anton\output_test.pdf";
// open target pdf file
using (PdfDocument doc = PdfReader.Open(@"c:\_anton\test.pdf", PdfDocumentOpenMode.Modify))
{
int count = doc.Pages.Count;
// it doesn't work. The value is not shown untill field is focused.
doc.AcroForm.Fields["firstNameTextField"].Value = new PdfString("Some Name");
// it works as it is expected
(doc.AcroForm.Fields["firstNameTextField"] as PdfTextField).Text = "Some Name";
doc.Save(outputFile);
}
It still has a small problem with displaying I still can not solve. The field’s data is displayed using one font and when the field is focused the font is changed. It is OK for my case but it is a really unpleasant effect.
For me PdfSharp is an acceptable pdf component but it is still not finished and has problems.
July 15th, 2008 at 9:21 pm
tell me if it can edit existing text in pdf not fields
July 16th, 2008 at 4:35 pm
Hi Hassan,
The only way to edit a text I know is to redraw it over the existing one. I think, You also can edit a text into a table cell if you use tables.
You can found more information at PdfSharp samples website - http://pdfsharp.wikihost.org/wiki/samples or at their forum http://pdfsharp.s3.bizhat.com/.
Regards,
Anton