Hi,
We have updated our Aspose.Pdf from version 4.7.0.0 to newer version 5.2.0.0 and we now have major problems building a PDF.
In our application we build a PDF from images that are stored on disk. (they are .png images generated by a printprocessor from a PrintDocument). So each image is a page. Following code has always work well !! up until our latest update.
Aspose.Pdf.Pdf pdf1 = new Aspose.Pdf.Pdf();
Aspose.Pdf.Section sec1 = pdf1.Sections.Add();
sec1.IsLandscape = true;
//In our code this is a loop for files to add the files one by one.
Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();
image1.ImageInfo.ImageFileType = Aspose.Pdf.ImageFileType.Png;
image1.ImageInfo.File = @".\img0.png";
sec1.Paragraphs.Add(image1);
pdf1.Save(@".\pdf.pdf");
I have attached a solution and 2 pdf files. (pdfold.pdf and pdfnew.pdf). In the solution i have one project refering to the Aspose.Pdf version 4.7.0.0 and one project referring to Aspose.Pdf version 5.2.0.0
Please fix as soon as possible.
Many thanks in advance.
Jan Stolk
Hello Jan,
Thanks for using our products.
Please try using the following code snippet to correct this problem. In following code, I have used generic approach to place image inside Section object. Also please take a look over the attached PDF document that I have generated over my end. In case the problem still persists or you have any further query, please feel free to contact. We apologize for your inconvenience.
[C#]
Aspose.Pdf.Pdf pdf1 = new Aspose.Pdf.Pdf();
Aspose.Pdf.Section sec1 = pdf1.Sections.Add();
// create MarginInfo object
MarginInfo pagemargin = new MarginInfo();
// specify the Top margin information
pagemargin.Top = 5;
pagemargin.Bottom = 5;
pagemargin.Left = 5;
pagemargin.Right = 5;
// set the Margin information for page
sec1.PageInfo.Margin = pagemargin;
sec1.IsLandscape = true;
//In our code this is a loop for files to add the files one by one.
Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();
image1.ImageInfo.ImageFileType = Aspose.Pdf.ImageFileType.Png;
image1.ImageInfo.File = @"d:/pdftest/img0.png";
// set Image height according to Page height (subtracting Top and Bottom Margin)
image1.ImageInfo.FixHeight = sec1.PageInfo.PageHeight - sec1.PageInfo.Margin.Top -sec1.PageInfo.Margin.Bottom;
// set Image Width according to Page height (subtracting Left and Right Margin)
image1.ImageInfo.FixWidth = sec1.PageInfo.PageWidth- sec1.PageInfo.Margin.Left- sec1.PageInfo.Margin.Right;
sec1.Paragraphs.Add(image1);
pdf1.Save(@"d:/pdftest/img0.pdf");
PS, If you change the page orientation to Portrait, the image is properly placed inside it. I have tested the scenario over Windows XP SP3 in Visual Studio 2005.
Hi,
Thank you for your advice. It worked well.
Kind regards,
Jan.