I'm using version 5.2.0 of Aspose.PDF.kit.
I'm trying to have Aspose do two things to an existing PDF file.
- Print the name of each field in each field using Aspose.Pdf.Kit.Form
- Turn the border of each field red using Aspose.Pdf.Kit.FormEditor
The names are being populated. But, the FormEditor corrupts the PDF file when I try to use it to change the border color.
Here is my code.
My.Computer.FileSystem.WriteAllBytes(“c:\temp\Original.pdf”, objPDFStream.ToArray, False)
'Create a new PDF form
objPDFForm = New Aspose.Pdf.Kit.Form(objPDFStream, objPDFStream)
'Get a list of all of the fields on the form
strPDFFieldNames = objPDFForm.FieldNames
'Label each field with its name
For Each strPDFFieldName In strPDFFieldNames
objPDFForm.FillField(strPDFFieldName, strPDFFieldName)
Next 'For Each strPDFFieldName In strPDFFieldNames
'Save the changes
objPDFForm.Save()
objPDFForm = Nothing
My.Computer.FileSystem.WriteAllBytes(“c:\temp\AfterTextEdit.pdf”, objPDFStream.ToArray, False)
'Create a form edited
objPDFFormEditor = New Aspose.Pdf.Kit.FormEditor(objPDFStream, objPDFStream)
'Create the Missing fields facade
objFieldMissingFacade = New Aspose.Pdf.Kit.FormFieldFacade
objFieldMissingFacade.BorderWidth = 2
objFieldMissingFacade.BorderStyle = Aspose.Pdf.Kit.FormFieldFacade.BorderStyleSolid
objFieldMissingFacade.BorderColor = Drawing.Color.Red
objPDFFormEditor.Facade = objFieldMissingFacade
'Mark all fields as “Not Found”. Then, we will go back and mark each found field
For Each strPDFFieldName In strPDFFieldNames
objPDFFormEditor.DecorateField(strPDFFieldName)
Next 'For Each strPDFFieldName In strPDFFieldNames
objPDFFormEditor.ResetFacade()
objPDFFormEditor.Save()
My.Computer.FileSystem.WriteAllBytes(“c:\temp\AfterFacadeEdit.pdf”, objPDFStream.ToArray, False)
BTW, my code saves out three versions of the PDF file. It save the original version before anything happens. Then, it saves it after the text edit. Then, it saves it after the facade edit. The first two files are fine. But, the one after the facade edit is corrupt. I have attached each version of the file.
Thanks, Mike