We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

PDF.Save not saving to memorystream

Hi I wonder if you can help me please.


I’m trying to build functionality where someone selects a pdf form (template) and then generates another pdf with fields filled in on it.

1) I have setup a pdf form with 3 fields in it.
2) This is loaded into a memorystream.
3) Foreach field in the form I do a fillfield call.
4) I do pdf.save() then write the new memorystream to a pdf.

None of the fields are filled in and I’m at a loss as to what i’m missing.

Debugging my c# code I can see it calling the fillfield method successfully.

Heres some code.

Form pdfForm = new Form(_workingMemoryStream, tempMemStream);

string[] fieldNames = pdfForm.FieldNames;

foreach (string fieldName in fieldNames)
{
if (partTwoFieldName.StartsWith(“IMAGE-”))
{
pdfForm.FillImageField(fieldName, getPDFImageUrl(TemplateImageName));
}
else
{
pdfForm.FillField(fieldName, fieldValue.Trim());
}
}

pdfForm.Save();

MergedContent = _workingMemoryStream.ToArray();

I really hope someone can help because a client is waiting for this functionality.

thanks in advance

vincent

Hello vincent,

Thanks for using our products.

When filling the data inside PDF form fields, please make sure that the name of the field provided in FillField(...) method is same as present over the PDF form. More along, instead of saving the updated/filled PDF form inside MemoryStream, can you please try saving the file over some physical location over system and see if the updated file contains the data.

In case you still face any problem, please share the source PDF form so that we can test the scenario at our end.

You may also check the following article on Identifying form fields names

We apologize for your inconvenience.

Hi.


I’ve double check and this is one of the fields I’m filling

form1[0].#subform[0].IMAGE-HeaderImage[0]

it comes from the foreach loop

string[] fieldNames = pdfForm.FieldNames;

foreach (string fieldName in fieldNames)
{
}

I’m attaching the pdf form i’m trying to use.

it’s got a couple of fields on it

Thanks for the quick response

vincent

Hello Vincent,

Thanks for sharing the information.

Once I have filled the data inside PDF form and I have tried viewing the document, I am getting an error prompt that some rights over the document have been updated and also I have observed that the fields have become flatten. Please take a look over the following error message that I am getting while viewing the document.

We are looking into the details of this problem and will keep you updated on the status of correction. We apologize for your inconvenience.

Hi.


Any update on this ?

Our client was expecting a fix at the end of this week for this.

thanks

Vincent

Hi Aspose.


Can I please ask for an update of this issue ?

My client is expecting to use pdf templates and if we cannot deliver this functionality I have to go through my code to remove the ability to use pdfs. Now I’ve spend a considerable amount of time writing the code in the first place so would only want to do this as an absolute last resort.

We’ve also at considerable cost upgraded our words license to a total licence for this particular functionality.

At the moment you guys aren’t even acknowledging if it’s fixable.

Can I please get an update on this issue.

thanks

Vincent

Hi Vincent,

I have again tested this issue using your input PDF file and the latest version of Aspose.Pdf.Kit for .NET (4.9.0), but I couldn’t notice any problem. The fields are successfully filled. Could you please make sure that you’re using the latest version? Moreover, please try to use the following constructor for testing purposes:


Form pdfForm = new Form(“Testing vinny.pdf”, “output.pdf”);


If it still doesn’t resolve your issue then please share a small sample application which can help us reproduce the issue at our end. We’ll update you with the results accordingly.

We’re sorry for the inconvenience.
Regards,

Hi shahzad,


Thanks for your reply but if could you please look at the original post i did.

your solution doesn’t solve my problem which is using memorystreams.

I am using the latest version 4.9.0.

I also provided sample code in the first or second post.

thanks

vincent

Hi Vincent,

I have again tested the issue using your sample - with MemoryStream - but couldn’t notice any problem. The output file was successfully generated and fields were filled properly. Please try the following code snippet which reads the input file into memory stream and then saves the output to the disk from the memory stream:



FileStream inFile = new FileStream(“Testing+vinny.pdf”, FileMode.Open);

FileStream outFile = new FileStream(“output.pdf”, FileMode.Create);


byte[] data = new byte[inFile.Length];


inFile.Read(data, 0, data.Length);


MemoryStream inStream = new MemoryStream(data, 0, data.Length);

MemoryStream outStream = new MemoryStream();


Form pdfForm = new Form(inStream, outStream);


string[] fieldNames = pdfForm.FieldNames;


foreach (string fieldName in fieldNames)

{

//if (partTwoFieldName.StartsWith(“IMAGE-”))

//{

// pdfForm.FillImageField(fieldName, getPDFImageUrl(TemplateImageName));

//}

//else

//{

pdfForm.FillField(fieldName, “some value to be filled”);

//}

}


pdfForm.Save();


outStream.Seek(0, SeekOrigin.Begin);

outStream.WriteTo(outFile);

outFile.Close();




I hope this helps. If it still doesn't resolve your issue then please share a small working sample application which can help us reproduce the same issue at our end.

We're sorry for the inconvenience and looking forward to help you out.
Regards,