ststeiger / PdfSharpCore

Port of the PdfSharp library to .NET Core - largely removed GDI+ (only missing GetFontData - which can be replaced with freetype2)
Other
1.05k stars 234 forks source link

Pdf.AcroForms PdfTextField setText fails! #371

Open CarlBKullman opened 1 year ago

CarlBKullman commented 1 year ago

set { Elements.SetString(Keys.V, value); RenderAppearance(); } //HACK in PdfTextField

System.ArgumentNullException: 'The size of the XPdfForm is to small. (Parameter 'viewBox')'

test:

let document = PdfReader.Open( templateFile, PdfDocumentOpenMode.Modify ) in let acroForm:PdfAcroForm = document.AcroForm in // Find the field you want to modify by name there is only one field! let fieldName = "Text" in let fields:PdfAcroField.PdfAcroFieldCollection = acroForm.Fields in let my = fields.[0] in //GetByFullFieldName( "asd") in <<<< missing let currentField = my :> PdfAcroField in // Check if the field exists and update its value match currentField with | :? PdfTextField as textField -> textField.Text <- "New Field Value"; <<<<<<<<< fails | _ -> () ;

AlexW68 commented 1 month ago

I don't know how far you got with this? but I have been battling this for a while, I will give you a bit of background.

A lot of my PDF's were originally created in Foxit, I moved away from them because I had a number of font issues, I moved to Acrobat Standard, this looked like it was working ok, I was getting a number of issues when combining PDF's where some fields were giving errors I put this down to the combining process which seemed to work better with the online tools than the application running on my Mac.

I was getting enough of these issues with PDF sharp that contacted Adobe and they had a look at one of the files, they said it's been created with a 3rd party tool there is an incompatibility, the PDF document I sent them has never been touched with PDFsharp so that is not the issue although that is where I see the problems.

I wrote a tool that opens a PDF finds all the acrofields and attempts to write to them telling me all the errors, this code is written using PDFsharp, it's pretty simple and once I have finished the code I will stick it in a public repo for anyone who needs it.

Looking at all the fields that are broken and there are several in each document, they are all new fields that have been added using Acrobat Standard either from scratch or a copied field, all have been created in the last few months I believe that a combination of the original file created in Foxit and acrobat in my case is enough to break some of these fields.

The fix for me is to delete the fields with issues and re-create them with the same properties, save the document and run the test again and the errors have gone.

What I also noticed a few times was acrobat opening a document and saying is corrupted and fixing it automatically, so this issue is an Adobe issue, but they are not going to help unless I create a PDF from scratch using their tools and then still have a problem.