We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Problem Converting TIF Image to PDF - File is 0kb

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);
	}
}

@bscharf

Thank you for contacting support.

We have noticed that you are using outdated version of the API. Please upgrade to Aspose.PDF for .NET 19.2 as latest versions include more features and bug fixes, and support is available based on latest version.

Please try using below code snippet and if you still face the issue then share source and generated ZIP files so that we may try to reproduce and investigate it in our environment.

// Instantiate Document Object
Document doc = new Document();
// Add a page to pages collection of document
Page page = doc.Pages.Add();
// Load the source image file to Stream object
FileStream fs = new FileStream(@"Test.tif", FileMode.Open);
// Set margins so image will fit
page.PageInfo.Margin = new MarginInfo(0, 0, 0, 0);
// Create an image object
Image image1 = new Image();
// Add the image into paragraphs collection of the section
page.Paragraphs.Add(image1);
// Set the image file stream
image1.ImageStream = fs;
// Save resultant PDF file
doc.Save(dataDir + "TIFF2PDF_DOM.pdf");