PdfSharp - a free component for editing pdf in .Net

June 23rd, 2008 by ganton | Print

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. 

[sourcecode language="csharp"]   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);
   }[/sourcecode]

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.

5 Responses to “PdfSharp - a free component for editing pdf in .Net”

  1. Hassan Nasir Says:

    tell me if it can edit existing text in pdf not fields

  2. ganton Says:

    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

  3. Danno Says:

    Ganton, I know this post is a year old, but did you ever find a solution for the issue with the data not being visible. I’m having the same problem and this issue doesn’t seem to have a documented fix.
    Thanks,
    Danno

  4. ganton Says:

    Hi Danno,

    Unfortunatelly, I didn’t find a solution of the problem at that time.

    -Anton

  5. ahmed rabie Says:

    Hi,

    Kindly examine this free library
    http://sourceforge.net/projects/itextsharp/

    I used it a lot before and it was very useful.

    thanks

Leave a Reply