I’m having an issue converting 2 multi-page TIF’s to PDF’s. We do a lot of TIF to PDF conversions but this is the first time I’ve had this specific issue with no other way to resolve it.
The conversion process is working fine and the PDF is being created with no error messages or exceptions thrown, however the resulting PDF file is 0kb. The process to convert it isn’t still running or anything else because I can close the app and the file still stays 0kb. We have some other tools we use with image manipulation like compression, so I ended up compression the source image and trying again, but I still get a 0kb file.
Below is the code we are running to convert a TIF to PDF, hopefully someone has ran into this before and knows a solution or even some other tweaks we can try to get this working.
// Load the tif image into usable objects
using (FileStream fs = new FileStream(tifFilePath, FileMode.Open, FileAccess.Read))
{
byte[] tmpBytes = new byte[fs.Length];
fs.Read(tmpBytes, 0, Convert.ToInt32(fs.Length));
using (MemoryStream memoryStream = new MemoryStream(tmpBytes))
{
Bitmap bitmap = new Bitmap(memoryStream);
// Instantiate a Pdf object
Aspose.Pdf.Generator.Pdf pdfGenerator = new Aspose.Pdf.Generator.Pdf();
// Create a new section in the Pdf document
Aspose.Pdf.Generator.Section pdfSection = new Aspose.Pdf.Generator.Section(pdfGenerator);
// Set margins so image will fit, etc.
pdfSection.PageInfo.Margin.Top = 5;
pdfSection.PageInfo.Margin.Bottom = 5;
pdfSection.PageInfo.Margin.Left = 5;
pdfSection.PageInfo.Margin.Right = 5;
pdfSection.PageInfo.PageWidth = (bitmap.Width / bitmap.HorizontalResolution) * 72;
pdfSection.PageInfo.PageHeight = (bitmap.Height / bitmap.VerticalResolution) * 72;
// Add the section in the sections collection of the Pdf document
pdfGenerator.Sections.Add(pdfSection);
// Create an image object
Aspose.Pdf.Generator.Image pdfImage = new Aspose.Pdf.Generator.Image(pdfSection);
// Add the image into paragraphs collection of the section
pdfSection.Paragraphs.Add(pdfImage);
pdfImage.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Tiff;
// Set the ImageStream to a MemoryStream object
pdfImage.ImageInfo.ImageStream = memoryStream;
// Save the converted file
pdfGenerator.Save(convertedPdfFilePath);
}
}