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

Free Support Forum - aspose.com

An incorrect structure was found in the PDF file

Dears,

we have the following code to save image & text over PDF document

the function save image and add text over PDF pages ok

but when we open PDF document on PDF Professional and try to add page or delete page

we get the following exception from PDF Professional Professional

"An incorrect structure was found in the PDF file"

public static bool SaveImageOnPDF(MemoryStream source, MemoryStream dest, MemoryStream image)
{
bool state1 = true;
try
{
int x = 2, y = 2;
PdfFileMend mender = new PdfFileMend(source, dest);
PdfFileInfo info = new PdfFileInfo(source);
for (int i = 1; i <= info.NumberOfPages; i++)
{
// don't generate barcode for small pages
if (info.GetPageWidth(i) < 422 || info.GetPageHeight(i) < 299)
continue;
bool state = mender.AddImage(image, i, x, y, (x + 530), (y + 50));
state = mender.AddText(new FormattedText(DateTime.Now.ToString("dd/MMM/yyyy hh:mm tt")), i, x, y);
if (!state) state1 = false;
}
mender.Close();
info.ClearInfo();
image.Close();
// save image over document
ECMFile.Replace(dest);
}
catch (Exception ex)
{
state1 = false;
throw new Exception("ECMFile:SaveImageOnPDF " + ex.Message, ex);
}
return state1;
}

Regards

Ahmad AbulMagd

Hi Ahmad,


Thanks for your inquiry. I am afraid we can test your sample code because of missing reference of ECMFile. We will appreciate if you please share a working code and also your sample output. So we will look into it and will provide you more information accordingly.

We are sorry for the inconvenience caused.

Best Regards,

Hi Ahmad,


Thanks for contacting support.

Adding more to Tilal’s comments, I have tested the scenario using Aspose.Pdf for .NET 9.3.0 where I have removed the last code line ECMFile.Replace(dest); and I am unable to notice any issue while adding/inserting pages using Adobe Acrobat 11.0.0 to PDF file generated as a result of PdfFileMend. For your reference, I have also attached the resultant PDF generated over my end.

Can you please try using the latest release and in case the problem still persists, please share the resource files.

[C#]

int x = 2, y = 2;<o:p></o:p>

PdfFileMend mender = new PdfFileMend("c:/pdftest/Web+URL (1).pdf", "c:/pdftest/Web+URL (1)_pdfMend.pdf");

PdfFileInfo info = new PdfFileInfo("c:/pdftest/Web+URL (1).pdf");

for (int i = 1; i <= info.NumberOfPages; i++)

{

// don't generate barcode for small pages

if (info.GetPageWidth(i) < 422 || info.GetPageHeight(i) < 299)

continue;

bool state = mender.AddImage("c:/pdftest/image001.png", i, x, y, (x + 530), (y + 50));

state = mender.AddText(new FormattedText(DateTime.Now.ToString("dd/MMM/yyyy hh:mm tt")), i, x, y);

//if (!state) state1 = false;

}

mender.Close();

info.ClearInfo();