PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.de/

Problem setting Font of PdfTextField
http://forum.pdfsharp.de/viewtopic.php?f=2&t=2641
Page 1 of 1

Author:  Christoph [ Tue Nov 12, 2013 6:58 am ]
Post subject:  Problem setting Font of PdfTextField

Hello,

I Want to Fill a pdf form. the pdf-document is from an external sources, so have no influence of the design.

I have extracted a PdfTextfield.
But Wenn I Set the Font and save the document it has no effect

wenn I step through the code after setting the Font to the PdfTextField it shows the right Values but in the generated document the text has a other Fontname/size.

What am I doing wrong?

(I've tried it with Version 1.3 pdfsharp and pdfsharp-wpf)

Code:

        PdfDocument document = PdfReader.Open(@"D:\Testzeugs\Test_doc.pdf", PdfDocumentOpenMode.Modify);

        PdfTextField currentField = (PdfTextField)(document.AcroForm.Fields["SOMEFIELD"]);

        //This section makes the text visible
        if (document.AcroForm.Elements.ContainsKey("/NeedAppearances"))
        {
          document.AcroForm.Elements["/NeedAppearances"] = new PdfBoolean(true);
        }
        else
        {
          document.AcroForm.Elements.Add("/NeedAppearances", new PdfBoolean(true));
        }

        //test
        string caseName = "Hallo Welt";
        PdfString caseNamePdfStr = new PdfString(caseName);
        currentField.Font = new XFont("Arial", 8);

        //set the value of this field
        currentField.Value = caseNamePdfStr;

        // Save the document...
        document.Save(@"D:\Testzeugs\test.pdf");

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/