Free Support Forum - aspose.com

Multiple actions

I create in ASP.NET (2.0) a PDF-form with the function form.fillfield.



In some cases, I create a second PDF-file (also with filling fields)



These 2 forms are than concatenated. Afterwards I set the security.



The way I do it now, I create files and save them, gives me 4 PDF-files. Afterwards I have to delete 3 of them.



Is there a way to this at once? Or do I have to work with streams?



Second question: sometimes the files are not closed properly. In that case i can’t overwrite or delete the file, which will end in an error in case of creating a new file (with the same filename). I have to stop-and-restart the ‘defaultapppool’ in IIS to free the file. Is there a workaround for this, or is this a minor bug?

Thanks for considering Aspose.

  1. You can use two MemoryStreams to store the result after filled. Please refer the API doc: http://www.aspose.com/Products/Aspose.Pdf.Kit/Api/Aspose.Pdf.Kit.FormConstructor4.html http://www.aspose.com/Products/Aspose.Pdf.Kit/Api/Aspose.Pdf.Kit.PdfFileEditor.Concatenate2.html
  2. I think the unclosed file issue is caused by the wrong FileStream Constructor you call, not by Aspose.Pdf.Kit.

Here I give you a sample for illustration:

==============================================

MemoryStream ms1 = new MemoryStream();

MemoryStream ms2 = new MemoryStream();

FileStream fs = new FileStream("FinallResult.pdf", FileMode.OpenOrCreate);

//First a input pdf file should be assigned
Aspose.Pdf.Kit.Form form1 = new Aspose.Pdf.Kit.Form("Doc1.pdf", ms1);

//Fill Form1 Fields

form1.Save();

//First a input pdf file should be assigned
Aspose.Pdf.Kit.Form form2 = new Aspose.Pdf.Kit.Form("Doc2.pdf", ms2);

//Fill Form2 Fields

form2.Save();

//Read the content from memory streams from the very beginning.

ms1.Position = 0;

ms2.Position = 0;

PdfFileEditor editor = new PdfFileEditor();

editor.Concatenate(ms1,ms2,fs);

ms1.Close();

ms2.Close();

fs.Close();

================================================


Thanx,

Although I use vb.NET, I’ll try this workaround tonight.

Thanx for the example. Most imoprtant; it’s even faster now compared working with different files.