I'm trying to create a new PDF from a starting one which has an editable form: I want to fill the form fields and to save it to a given folder.
Here you can find the code I wrote: I wasn't able to make it work.
Any help would be appreciated.
Many thanks
Regards
Stefano
string ContainerFolder = @"C:\temp";
string sourceFile = "test.pdf";
string targetFile = string.Format("{0}_{1}{2}_antrag.pdf", DateTime.Now.ToString("yyyyMMddhhmmss"), Lead.SecondName, Lead.FirstName);
//create input and output file streams
FileStream sourceStream = new FileStream(ContainerFolder + "sources\\" + sourceFile, FileMode.Open, FileAccess.ReadWrite);
FileStream targetStream = new FileStream(ContainerFolder + targetFile, FileMode.Create, FileAccess.Write);
byte[] data = new byte[sourceStream.Length];
sourceStream.Read(data, 0, data.Length);
//create input and output memory streams
MemoryStream inputms = new MemoryStream(data, 0, data.Length);
//MemoryStream outputms = new MemoryStream();
inputms.Seek(0, SeekOrigin.Begin);
using (var licenseStream = System.IO.File.Open(ContainerFolder + "sources\\" + "Aspose.Pdf.Kit.lic", System.IO.FileMode.Open))
{
Aspose.Pdf.Kit.License license = new Aspose.Pdf.Kit.License();
license.SetLicense(licenseStream);
}
Aspose.Pdf.Kit.Form form = new Aspose.Pdf.Kit.Form(inputms, targetStream);
Here I get the following exception:
Read pdf error:The type initializer for 'Aspose.Pdf.Kit.PdfFileInfo' threw an exception.
[IOException: Read pdf error:The type initializer for 'Aspose.Pdf.Kit.PdfFileInfo' threw an exception.]
xeb116a323308e2f7.x7759a935a2782a02.readPdf() +316
Aspose.Pdf.Kit.Form.xedff4d4fd296f454() +141
I also tried the following code
Aspose.Pdf.Kit.Form form = new Aspose.Pdf.Kit.Form(ContainerFolder + sourceFile, ContainerFolder + "sources\\" + targetFile);
but I get a SecurityException (FileIOException).
Googling, I found out that I need to set the FullTrust level in the web.config. I've done it, but nothing changed.
I'd like to focus on the fact that I was able to read the license, but I wasn't able to create the Form object.
We are using WS2008 with IIS7, .Net3.5
Thanks