Free Support Forum - aspose.com

Issue with Aspose.Pdf.Kit.FormEditor corrupting PDF file

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

Hi Mike,

I have logged this issue as PDFKITNET-24039 in our issue tracking system. Our team will further investigate it and you’ll be notified via this forum thread as soon as it is resolved.

We’re sorry for the inconvenience.
Regards,

Thanks

Could you give me an estimate on when the fix for this will be out? Being a developer myself I certainly understand that resolutions to issues like this can be difficult to estimate. But, could you give me an idea on how high this is on the priority list? The software date for my project is coming up and I need to know if I need to start looking for another solution.

Thanks in advance,

Mike

Hi Mike,

I have asked our team to share the ETA of this issue. You’ll be updated as soon as the ETA is available.

We’re sorry for the inconvenience.
Regards,

Since this fix could take a while, maybe we can find a work around.

I noticed that in a lot examples show the FormEditor class building forms from the ground up. So, I'm guessing that the issue is that Adobe is putting symbols in the PDF file that FormEditor does not expect to find. So, using it to update existing documents can cause issues.

Is it possible to have the FormEditor class create a new PDF and have another class iterate through all of the objects in the source PDF and just copy the property values from the source PDF to the new one? That way FormEditor can control everything that is added to the new file. Then, I could just have my code modify the PDF generated by FormEditor. It shouldn't run into issues with a PDF that it created itself.

If you could give me the code to do this, then I would be satisfied.

Thanks,

Mike

Hi Mike,

You can use Aspose.Pdf.Kit to create the form fields in an existing PDF file. Please find the details on this link. The fields can later be filled using the details in this help topic.

As far as the issue PDFKITNET-24039 is concerned, our team has investigate it in detail and we would be able to provide you a fix for this issue at the end of March or early April 2011. You’ll be notified via this forum thread once it is resolved.

If you have any further questions, please do let us know.
Regards,

I've actually already seen code samples like the one at http://www.aspose.com/documentation/.net-components/aspose.pdf.kit-for-.net/how-to-create-and-decorate-form-fields-with-api.html. This code shows the FormEditor adding fields of a certain sizes at certain locations. The sizes and locations in this example are hard coded and are already known. In my application, I have no way of knowing the sizes or locations or even the names of the fields. The PDF documents that my app will be loading will be created by the user. So, I have no way of knowing what will be in them.

Can you show me how to use Aspose to iterate through all of the objects on the source document and get all of the property values? So, for each control the code would need to supply the size, location, font, etc. so it can be reconstructed. The code would also need to supply the properties of other elements as well such as background images, headers, and footers. Is it possible to do all of the that? What class could I use to get all of that information.

Thanks,

Mike

Hi Mike,

As I understand, you want to get all the objects of the original PDF and then recreate the whole new PDF based on the information extracted from the original PDF. I’m afraid, this is not feasible at the moment. Aspose.Pdf.Kit can allow you to extract certain objects from the PDF files, but it is not possible to recreate the whole new document based on that information.

I would suggest that you wait for a fix for the original issue. This way, you won’t have to go through all the process of recreating the whole document.

We’re sorry for the inconvenience. If you have any further questions or concerns, please do let us know.
Regards,

The issues you have found earlier (filed as 24039) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.