When I previously generated PDFs using Aspose.Pdf for .NET 220.127.116.11 and Aspose.Pdf.Kit for .NET 18.104.22.168, everything was working perfectly alright.
Recently, i.e. on 11th Oct 2011 we have purchased the Aspose.Pdf for .NET (in which Aspose.Pdf.Kit for .NET is also merged). After adding the Aspose.Pdf.dll 22.214.171.124 and the license file in the project, when I try to create the Pdf file, I get the following error:
System.Xml.XmlException - Data at the root level is invalid. Line 1, position 1.
I have added the sample code below which generates error on the Save method.
I have also attached the Pdf file that is being used.
protected void Button1_Click(object sender, EventArgs e)
FileStream fs1 = new FileStream(@“E:\TestPDF.pdf”, FileMode.Open);
FileStream fs2 = new FileStream(@“E:\TestPDF_Flatten.pdf”, FileMode.OpenOrCreate);
Aspose.Pdf.Facades.Form pdfForm = new Aspose.Pdf.Facades.Form(fs1, fs2);
fs1 = new FileStream(@“E:\TestPDF_Flatten.pdf”, FileMode.Open);
fs2 = new FileStream(@“E:\TestPDF_New.pdf”, FileMode.OpenOrCreate);
//create PdfPageEditor object
PdfPageEditor pEdit = new PdfPageEditor();
//bind pdf file
//and assign it to PageSize property of the PdfPageEditor class
pEdit.PageSize = Aspose.Pdf.Facades.PageSize.A4;
pEdit.Alignment = AlignmentType.Center;
pEdit.VerticalAlignment = VerticalAlignmentType.Center;
//save the file
pEdit = null;
catch (Exception ex)
Please let me know the solution at the earliest as we got to implement the project tomorrow.
Hi Priya,<span style=“font-size:10.0pt;font-family:“Arial”,“sans-serif””>
have tested the scenario and have managed to reproduce the same problem. For the
sake of correction, I have logged it in our issue tracking system as <span style=“font-family:“Arial”,“sans-serif””>PDFNEWNET-31306. We
will investigate this issue in details and will keep you updated on the status
of a correction.<span style=“font-size:10.0pt;font-family:“Arial”,“sans-serif””><span style=“font-size:10.0pt;font-family:“Arial”,“sans-serif””>
apologize for your inconvenience.
Thanks for your patience.
We have further investigated this issue and have found that XMP metadata in source PDF is corrupted and its causing an exception when accessing the file. However in your code you have handled the exception and tried to save the resultant file. The final output is empty and therefore it seems to be corrupted. The fix will be included in upcoming release version of Aspose.Pdf for .NET which is expected to be released by early next month. Please be patient and spare us little time. Your patience and comprehension is greatly appreciated in this regard. We are really sorry for the delay and inconvenience that you are facing.
PS, If you simply open the source file with Aspose.Pdf.Facades.Form object, call FlattenAllFields(); method and save the document, you will be able to notice this problem.