Thanks for your inquiry. I have tested the scenario using new DOM approach for Image to PDF conversion with Aspose.Pdf for .NET 10.7.0 and unable to notice the reported issue. Please use DOM approach it will resolve the issue.
Please feel free to contact us for any further assistance.
Hi - We tried the code suggested and whilst it worked for a single page image, it’s a bit too simplistic for us.
Our TIFF images are usually multi-page and often a mix of portrait and landscape pages in the same document.
We previously used the Aspose.Imageing.Image.Load call to load the Tiff image and then iterated through the frames to determine the page layout etc. The frames are then added individually to the PDF object.
This Aspose.Imageing.Image.Load call is the one one throwing the exception.
The demo code only looks at the bitmap from the first page, so it won’t help.
Do you have better sample code or a different method to access each page in the Tiff?
In a previous response, you have mentioned that Aspose.Imaging.Image.Load method throws the said exception, however, when we tested the load operation while using the latest version of Aspose.Imaging for .NET 3.0.0, we were not able to observe any exception. Moreover, your provided code file is of 0 bytes in size therefore we have tested the frame splitting operation using the following piece of code and found no issues. Please check the attached archive for the resultant images.
In case you are using any older revision of Aspose.Imaging for .NET we suggest you to upgrade the API to 3.0.0 and retest the scenario on your side. If the problem persists even after upgrading the Aspose.Imaging for .NET API, please provide the code (covering your complete scenario) or a sample application with required input document(s) for further investigation in this regard.
C#
TiffImage image = (TiffImage)Image.Load(“D:/testimage.tif”); int index = 0; foreach (TiffFrame frame in image.Frames)
{
frame.Save(“D:/output” + index++ + “.tiff”, new TiffOptions(TiffExpectedFormat.TiffLzwBW));
}
When using legacy Aspose.Pdf.Generator (as shared in your code snippet) to insert TIFF image inside PDF file, I encountered an exception. However as recommended earlier, please try using new Document Object Model (DOM) for TIFF to PDF conversion but during my testing, I have observed that an OutOfMemoryException is being generated when converting TIFF image to PDF file. For the sake of correction, I have logged this problem
as PDFNEWNET-39347 in our issue tracking system. We will further
look into the details of this problem and will keep you updated on the status
of correction. Please be patient and spare us little time. We are sorry for
this inconvenience.
[C#]
FileStream fs = new FileStream("c:/pdftest/TestImage.TIF", FileMode.Open, FileAccess.Read);
byte[] tmpBytes = new byte[fs.Length];
fs.Read(tmpBytes, 0, Convert.ToInt32(fs.Length));
MemoryStream mystream = new MemoryStream(tmpBytes);
// Instantiate BitMap object with loaded image stream
Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(mystream);
var pdf = new Aspose.Pdf.Document();
pdf.PageInfo.Height = (float)Math.Ceiling(Aspose.Words.ConvertUtil.PixelToPoint(image.Height, 96.0) + pdf.PageInfo.Margin.Top + pdf.PageInfo.Margin.Bottom);
pdf.PageInfo.Width = (float)Math.Ceiling(Aspose.Words.ConvertUtil.PixelToPoint(image.Width, 96.0) + pdf.PageInfo.Margin.Left + pdf.PageInfo.Margin.Right);
var section = pdf.Pages.Add();
var pdfImage = new Aspose.Pdf.Image();
section.Paragraphs.Add(pdfImage);
var tiffImage = image as Aspose.Imaging.FileFormats.Tiff.TiffImage;
string tempPath = "c:/pdftest/TestImage_temp.TIF";
File.Copy("c:/pdftest/TestImage.TIF", tempPath, true);
for (int i = 0; i < tiffImage.Frames.Length; i++)
{
var frame = tiffImage.Frames[i];
Aspose.Pdf.Image framePdfimage;
Aspose.Pdf.Page frameSection;
if (i == 0)
{
framePdfimage = pdfImage;
frameSection = section;
}
else
{
frameSection = pdf.Pages.Add();
//frameSection.IsNewPage = true;
framePdfimage = new Aspose.Pdf.Image();
frameSection.Paragraphs.Add(framePdfimage);
}
if (frame.Height > 0 && frame.Width > 0)
{
var frameHeight = (float)Aspose.Words.ConvertUtil.PixelToPoint(frame.Height, (frame.VerticalResolution > 0 ? frame.VerticalResolution : 96.0));
var frameWidth = (float)Aspose.Words.ConvertUtil.PixelToPoint(frame.Width, (frame.HorizontalResolution > 0 ? frame.HorizontalResolution : 96.0));
frameSection.PageInfo.Height = frameHeight + frameSection.PageInfo.Margin.Top + frameSection.PageInfo.Margin.Bottom;
frameSection.PageInfo.Width = frameWidth + frameSection.PageInfo.Margin.Left + frameSection.PageInfo.Margin.Right;
framePdfimage.FixHeight = frameHeight;
framePdfimage.FixWidth = frameWidth;
}
else
{
framePdfimage.ImageScale = 1.0F;
}
framePdfimage.File = tempPath;
//framePdfimage.TiffFrame = i;
}
using (var pdfMs = new MemoryStream())
{
// THIS CALL NOW FAILS
pdf.Save(pdfMs);
var filestream = new FileStream("c:/pdftest/TestImage.pdf", FileMode.Create);
pdfMs.WriteTo(filestream);
}
Thanks for your inquiry. Please note your reported issue(PDFNEWNET-39347) is Aspose.Pdf related issue and it has to be fixed in Aspose.Pdf for .NET. Your reported issue is still not resolved as we have recently noticed it. It is pending for investigation in the queue with other issues. We will notify you as soon as we made some significant progress towards issue resolution.
Thanks for your inquiry. I am afraid your above reported issue is still not resolved as product team is busy in resolving other issues in the queue, reported earlier. However I have raised your issue priority and requested our team to share an ETA at their earliest. We will notify you as soon as we made some significant progress towards issue resolution.