I have a problem converting large images to PDF. Here is my code:
var doc = new Aspose.Words.Document();
var builder = new DocumentBuilder(doc);
try
{
using (var image = Image.FromStream(new MemoryStream(attachment.Bytes)))
{
// Get the number of frames in the image.
int framesCount = image.GetFrameCount(FrameDimension.Page);
// Loop through all frames.
for (int frameIdx = 0; frameIdx < framesCount; frameIdx++)
{
// Insert a section break before each new page, in case of a multi-frame TIFF.
if (frameIdx != 0)
builder .InsertBreak(BreakType.SectionBreakNewPage);
// Select active frame.
image.SelectActiveFrame(FrameDimension.Page, frameIdx);
// We want the size of the page to be the same as the size of the image.
// Convert pixels to points to size the page to the actual image size.
PageSetup ps = builder.PageSetup;
ps.PageWidth = ConvertUtil.PixelToPoint(image.Width, image.HorizontalResolution);
ps.PageHeight = ConvertUtil.PixelToPoint(image.Height, image.VerticalResolution);
// Insert the image into the document and position it at the top left corner of the page.
builder.InsertImage(image, RelativeHorizontalPosition.Page, 0, RelativeVerticalPosition.Page, 0, image.Width, image.Height, WrapType.None);
}
}
// Save the document to PDF.
return doc.SaveToPdfStream();
}
It is working - but the problem is, that when the picture is big I’m getting a blank white page.
I have attached two test images. They are the same, but the size is different.
One is 4160 x 2340 Pixels - it’s NOT working.
Another is 1500 x 844 Pixels it’s working.
Hope you can help me.
Best regards,
Emil Christiansen