Converting from Aspose.Pdf.Facades.Form to Memory Stream

I’m trying to convert a stream to a PDF facades form via facades, rename the fields, and convert back. I’m able to do all but convert back to a stream. My code is below. What do I need to do to convert the updated form back to a stream in VB.NET?


Dim Stream As System.IO.Stream = createStreamFromPDF(DataUtil.GetInt64(JsonParams(“ObjectId”)), ApplicationId, PropertyId)
Dim pdfFacades As New Aspose.Pdf.Facades.Form(Stream)

Dim allfields() As String = pdfFacades.FieldNames
For Each field In allfields
Dim newfield As String = field.Remove(0, 2)
pdfFacades.RenameField(field, newfield)
Next

Hi Regan,


Thanks for using our API’s.

In order to accomplish your requirement, you can pass Steam object as an argument to Form.Save(…) method as shown below.

[VB.NET]

Dim Stream As FileStream = New FileStream(“c:/pdftest/ICP
Chart_07072010.pdf”
, FileMode.Open)<o:p></o:p>

' Dim Stream As System.IO.Stream = createStreamFromPDF(DataUtil.GetInt64(JsonParams("ObjectId")), ApplicationId, PropertyId)

Dim pdfFacades As New Aspose.Pdf.Facades.Form(Stream)

Dim allfields() As String = pdfFacades.FieldNames

For Each field In allfields

' Console.WriteLine(field.n)

Dim newfield As String = field.Remove(0, 2)

pdfFacades.RenameField(field, newfield)

Next

Dim memStream As MemoryStream = New MemoryStream()

pdfFacades.Save(memStream)

Console.WriteLine(memStream.Length)

My objective with this code is to remove the “0.” that for some reason is getting put in front of the field names, such as with field name “0.FirstName”. Hence the code below:


Dim newfield As String = field.Remove(0, 2)
pdfFacades.RenameField(field, newfield)

However, even after I remove it and save the updated pdf to a memory stream, they are still there. I verified this by saving the new output to a pdf. The entire block of code I’m using to convert and test is below. How do I save this file so the “0.” is gone?

Full code:

Dim Stream As System.IO.Stream = createTic(DataUtil.GetInt64(JsonParams(“ObjectId”)), ApplicationId, PropertyId)
Dim pdfFacades As New Aspose.Pdf.Facades.Form(Stream)

Dim allfields() As String = pdfFacades.FieldNames
For Each field In allfields
Dim newfield As String = field.Remove(0, 2)
pdfFacades.RenameField(field, newfield)
Next

Dim StreamOutput As MemoryStream = New MemoryStream()
pdfFacades.Save(StreamOutput)

Dim pdfFacades2 As New Aspose.Pdf.Facades.Form(StreamOutput)
pdfFacades2.Save(“C:\testfile\facades2.pdf”)

Hi Regan,


Thanks for sharing the details.

As per my understanding, once you have renamed a field, a 0 is added with field name. Can you please share some sample PDF form file and sample project so that we can test the scenario in our environment. We are sorry for this inconvenience.

Hi. Thank you for your assistance. Please find a sample pdf attached, as well as the code to replicate the issue and a clarification of the problem below.


The problem is this: if there is a “zero dot” as a part of the field name, then I’m unable to trim that off. (In the sample file, the only field present is called “O.originalfield”. After I run it through aspose, I want the field name to be “originalfield”.)

Note that in the sample pdf, if you rename the field to remove the “zero dot” and rerun the code, it will trim the first two characters as expected. How do I phrase the code so it trims the “zero dot”?

Dim Stream As System.IO.Stream = New FileStream(“C:\facadesOut\Test.pdf”, FileMode.Open)
Dim license As New Aspose.Pdf.License()
license.SetLicense(“Aspose.Total.lic”)
Dim pdfFacades As New Aspose.Pdf.Facades.Form(Stream)

Dim allfields() As String = pdfFacades.FieldNames

For Each field In allfields
Dim newfield As String = field.Remove(0, 2)
pdfFacades.RenameField(field, newfield)
Next

Dim StreamOutput As MemoryStream = New MemoryStream()
pdfFacades.Save(StreamOutput)

Dim pdfFacades2 As New Aspose.Pdf.Facades.Form(StreamOutput)
pdfFacades2.Save(“C:\facadesIn\facadesResult.pdf”)

Hi Regan,


Thanks
for using our API’s.
<o:p></o:p>

I
have tested the scenario and I am able to notice the same problem. For the sake
of correction, I have logged this problem as PDFNEWNET-39359 in
our issue tracking system. We will further look into the details of this
problem and will keep you updated on the status of correction. Please be
patient and spare us little time. We are sorry for this inconvenience.