I'm currently using Spire.Office v6.12.1 as a licensed user. I'm trying to create a PdfImage from an existing Pdf Document and draw it onto a new Pdf Document.
This is the code block I'm using in order to accomplish this:
- Code: Select all
using (var imageStream = pdfDoc.SaveAsImage(i)) {
// Create a new page with the same size as the original pdf that the image is created from
var newPage = newDoc.Pages.Add(pdfDoc.Pages[i].Size);
var image = PdfImage.FromStream(imageStream);
float widthFitRate = image.PhysicalDimension.Width / newPage.Canvas.Size.Width;
float heightFitRate = image.PhysicalDimension.Height / newPage.Canvas.Size.Height;
float fitRate = Math.Max(widthFitRate, heightFitRate);
float fitWidth = image.PhysicalDimension.Width / fitRate;
float fitHeight = image.PhysicalDimension.Height / fitRate;
newPage.Canvas.DrawImage(image, 0, (newPage.Canvas.ClientSize.Height - image.Height), fitWidth, fitHeight);
}
The resulting image appears to have cropped off the bottom half of the document I am converting. If I switch the nuget package I am using to Spire.Office.NETCore v 6.12.1 and update the code above to this:
- Code: Select all
using (var image = pdfDoc.SaveAsImage(i)) {
// Create a new page with the same size as the original pdf that the image is created from
var newPage = newDoc.Pages.Add(pdfDoc.Pages[i].Size);
var pdfImage = PdfImage.FromImage(image);
float widthFitRate = pdfImage .PhysicalDimension.Width / newPage.Canvas.Size.Width;
float heightFitRate = pdfImage .PhysicalDimension.Height / newPage.Canvas.Size.Height;
float fitRate = Math.Max(widthFitRate, heightFitRate);
float fitWidth = pdfImage .PhysicalDimension.Width / fitRate;
float fitHeight = pdfImage .PhysicalDimension.Height / fitRate;
newPage.Canvas.DrawImage(pdfImage , 0, 0, fitWidth, fitHeight);
}
The resulting document has the full image on the page uncropped as expected.
What is going on with the current version of Spire.Office v6.12.1? Is it safe for me to just use the NETCore version of the library instead or is that too far behind with regards to bug fixes?
Please let me know when you can. I've attached the file I've been testing with and getting these results.
Thank you,
Zac