Converting MultiPage TIFF to PDF

Good Morning,

We have a problem converting multipage TIFF to PDF.

When we perform a conversion of a multi-page tiff image to PDF, only the first page is displayed. We tried different things, but always with negative results. Aspose.Pdf version we are using is the 4.7.

We searched all the threads that refer this issue and none of the solutions has helped us.

This is the code we're using:

string outDir = @"C:\BizTalk\SCO.Sistemas.BizTalk\SCO.Sistemas.BizTalk.IndexadorGD\Port\";

Aspose.Pdf.License licpdf = new Aspose.Pdf.License();
licpdf.SetLicense("Aspose.Total.lic");

//Instantiate a Pdf object
Aspose.Pdf.Pdf pdf1 = new Aspose.Pdf.Pdf();


FileStream fs = new FileStream(@"C:\BizTalk\SCO.Sistemas.BizTalk\SCO.Sistemas.BizTalk.IndexadorGD\Port\Multi TIF.TIF", FileMode.Open);


fs.Read(tmpBytes, 0, Convert.ToInt32(fs.Length));
StreamReader mystream = new StreamReader(fs);

Aspose.Pdf.Section sec1 = pdf1.Sections.Add();


Aspose.Pdf.Image image1 = new Aspose.Pdf.Image(sec1);


image1.ImageInfo.ImageFileType = Aspose.Pdf.ImageFileType.Tiff;
image1.ImageInfo.TiffFrame = -1;


sec1.Paragraphs.Add(image1);


image1.ImageInfo.ImageStream = mystream.BaseStream;

//Save the Pdf
pdf1.Save(outDir + "OutputFile.pdf");

We have also tried with: image1.ImageInfo.IsAllFramesInNewPage = True. When we do this only the first page is still being converted and the rest appear in blank.

Thanks in advance,

Guillermo Tato

Hello Guillermo,

Thanks for using our products.

Can you please share the source TIFF image so that we can test the scenario at our end. We apologize for your inconvenience.

Good morning,

first of all, thanks for your quickly reply.

Attached is one of the multipage TIFF that is causing the problem. Hope it helps

regards,

Guillermo

Hello Guillermo,

Thanks for sharing the resource image file.

I have tested the scenario using Aspose.Pdf for .NET 4.7.0 (which can be downloaded from here) over Windows7 Enterprise 64Bit and as per my observations, all the frames of TIFF image are properly being converted into PDF format. Please take a look over the attached PDF document that I have generated using following code snippet.

[C#]

//Instantiate a Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
//Create a section in the Pdf object
Aspose.Pdf.Section sec1 = pdf1.Sections.Add();
//Create an image object in the section
Aspose.Pdf.Image image1 = new Aspose.Pdf.Image(sec1);
//Add image object into the Paragraphs collection of the section
sec1.Paragraphs.Add(image1);

//Set the path of image file
image1.ImageInfo.File = "d:/pdftest/test2.tif";
//Set the type of image using ImageFileType enumeration
image1.ImageInfo.ImageFileType = ImageFileType.Tiff;
//Set image title
image1.ImageInfo.Title = "TIFF image";
// Set the value to -1 so that all the frames of TIFF image are included in PDF document
image1.ImageInfo.TiffFrame = -1;
//Save the Pdf
pdf1.Save("d:\\pdftest\\TIFFtoPDFConversion_test.pdf");

In case it does not resoled your problem or you have any further query, please feel free to contact. We apologize for your inconvenience.

Hi codewarrior,

The problem becomes when we load the image from a memory stream as you can see in the code attached in previous posts.

I reattach you the code we're using:

FileStream fs = new FileStream(@"C:\BizTalk\SCO.Sistemas.BizTalk\SCO.Sistemas.BizTalk.IndexadorGD\Port\Multi TIF.TIF", FileMode.Open);


fs.Read(tmpBytes, 0, Convert.ToInt32(fs.Length));
StreamReader mystream = new StreamReader(fs);

Aspose.Pdf.Section sec1 = pdf1.Sections.Add();


Aspose.Pdf.Image image1 = new Aspose.Pdf.Image(sec1);


image1.ImageInfo.ImageFileType = Aspose.Pdf.ImageFileType.Tiff;
image1.ImageInfo.TiffFrame = -1;


sec1.Paragraphs.Add(image1);


image1.ImageInfo.ImageStream = mystream.BaseStream;

thanks,

Guillermo

Hello Guillermo,

Thanks for the information.

I have tested the scenario and I am able to reproduce the same problem. For the sake of correction, I have logged it in our issue tracking system as PDFNET-20854. We will investigate this issue in details and will keep you updated on the status of a correction. <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

We apologize for your inconvenience.

Has there been any resolution to this issue? I am having the same problem.

Hello Micheal,

Thanks for using our products.

We have made some progress towards the resolution of this problem. However, in order to cater the particular issue that you are facing, we would be requiring the source TIFF file so that we can test the scenario at our end. We apologize of your inconvenience.

I’m sorry but I can’t provide you with the source tiff as it contains sensitive information. If you would like I can provide you with my code. I may can see if it is possible to send it to you redacted but I am guessing I still want be able to do this.

Hello Micheal,

Until or unless we have tested the scenario, we might not be able to figure out the actual reasons for this problem. The source file that will share will only be used for testing purpose and will be removed after the resolution of this problem. More along, you may also send the source file directly to us without uploading it over this forum thread. Please follow the steps specified over following link to share the source file. How to send a license?

In case I can be of any further assistance, please let me know. We apologize for your inconvenience.

I have the same problem…

After adding image to Pdf object and saving it, the output pdf file contains only one page.

Here the code:

Pdf doc = new Pdf();

Section section = doc.Sections.Add();
Aspose.Pdf.Image image = new Aspose.Pdf.Image(section);
image.ImageInfo.ImageStream = sourceStream; // (multipage tiff - included)
image.ImageInfo.ImageFileType = ImageFileType.Tiff;
section.Paragraphs.Add(image);
image.ImageInfo.TiffFrame = -1;

doc.Save(@“C:\test.pdf”);

I have added IsAllFramesInNewPage = True,

and now the output pdf file contains required number of pages, but all of them except the first one are empty.


By the way: If I am trying to create pdf from file (not from stream) - everythins is fine (even without IsAllFramesInNewPage)

Hi,

Thanks for using our products.

I have tested the scenario using Aspose.Pdf for .NET 4.7.0 and as per my observations, the PDF document is properly being generated. I have used the following code snippet to test the scenario. The resultant PDF that I have generated is in attachment. Please take a look.

[C#]

// Instantiate an object PDF class
Pdf pdf = new Pdf();
// add the section to PDF document sections collection
Aspose.Pdf.Section section = pdf.Sections.Add();
// create an image object
Aspose.Pdf.Image image = new Aspose.Pdf.Image(section);
// provide the path for TIFF image file\
image.ImageInfo.File = @"c:/pdftest/Постановление+Правительства+РФ+N583(4467070_7904-Вх_16_11_2010).tif"; // (multipage tiff - included)
// specify the input image file type
image.ImageInfo.ImageFileType = ImageFileType.Tiff;
// add image to paragraphs collection of section
section.Paragraphs.Add(image);
// specify the value to include all the frames of image file into resultant PDF
image.ImageInfo.TiffFrame = -1;
//Save the pdf document
pdf.Save(@"C:\pdftest\Tiff_Conversion_Issue.pdf");

Hi Nayyer,

thanks for your reply.
As I mentioned earlier, the problem occures only if I pass a stream object to Image.ImageImageInfo.ImageStream. With physical file there is no problem. Check it please with tiff file that I’ve attached in my previous post. I am using version 4.7 too.

P.S. For getting stream object from tiff file I am using File.ReadAllBytes and the pass it to MemoryStream constructor.

Hi,

Thanks for sharing the information.

I have tested the scenario while using Stream object and I am able to notice the problem. However, I have also tested it with the upcoming release version of Aspose.Pdf for .NET 4.8.0 and as per my observations, the PDF document is properly being generated (all the frames of TIFF image are present over the PDF document). Please be patient and wait for the new release version. As soon as it becomes available, we will let you know.

We apologize for your inconvenience.

PS, I have used FileStream object to test the scenario

Hi Nayyer,

thanks for your reply.
The problem is that I can’t wait untill the new release will be published.
We choose Aspose’s solution as one of the most powerfull and flexible solutions and purchased a Total license. But now we are stuck here with Tiff2Pdf convertion problem and can’t move on.
I’ll be very grateful if you’ll find a way to provide us some update for 4.7 version that fixes the bug.
Thank you in advance.

Hi,

Thanks for your patience.

I am pleased to inform you that Aspose.Pdf for .NET 4.8.0 is released. Please download the version from this link and in case you encounter any problem, please feel free to contact.

Thank you very much. Works fine.

The problem is that from the second page, the images are very small, do not retain the original size of the tiff.

This is the code of our method and attached is the resulting pdf

static private MemoryStream ConvertirImagenToPDF(MemoryStream inStream, string tipo)
{
//Instantiate a Pdf object by calling its empty constructor
Aspose.Pdf.ImageFileType imageType = Aspose.Pdf.ImageFileType.Unknown;
System.Drawing.Imaging.ImageFormat formato = ObtenerFormato(tipo);
if (formato == System.Drawing.Imaging.ImageFormat.Bmp) imageType = Aspose.Pdf.ImageFileType.Bmp;
if (formato == System.Drawing.Imaging.ImageFormat.Gif) imageType = Aspose.Pdf.ImageFileType.Gif;
if (formato == System.Drawing.Imaging.ImageFormat.Jpeg) imageType = Aspose.Pdf.ImageFileType.Jpeg;
if (formato == System.Drawing.Imaging.ImageFormat.Png) imageType = Aspose.Pdf.ImageFileType.Png;
if (formato == System.Drawing.Imaging.ImageFormat.Tiff) imageType = Aspose.Pdf.ImageFileType.Tiff;
if (formato == System.Drawing.Imaging.ImageFormat.Icon) imageType = Aspose.Pdf.ImageFileType.Icon;
Aspose.Pdf.Pdf pdf = new Aspose.Pdf.Pdf();
pdf.PageSetup.Margin.Left = 0;
pdf.PageSetup.Margin.Right = 0;
pdf.PageSetup.Margin.Top = 0;
pdf.PageSetup.Margin.Bottom = 0;
pdf.HtmlInfo.Margin.Left = 0;
pdf.HtmlInfo.Margin.Right = 0;
pdf.HtmlInfo.Margin.Top = 0;
pdf.HtmlInfo.Margin.Bottom = 0;
System.Drawing.Image imageDrawing = System.Drawing.Image.FromStream(inStream, true, true);
//Create a section in the Pdf object //crea una pgina nueva
Aspose.Pdf.Section sec = pdf.Sections.Add();
//Create an image object in the section
Aspose.Pdf.Image image = new Aspose.Pdf.Image(sec);
if (sec.PageInfo.PageHeight < imageDrawing.Height)
{
sec.PageInfo.PageHeight = imageDrawing.Height;
image.ImageHeight = sec.PageInfo.PageHeight;
}
if (sec.PageInfo.PageWidth < imageDrawing.Width)
{
sec.PageInfo.PageWidth = imageDrawing.Width;
image.ImageWidth = sec.PageInfo.PageWidth;
}
sec.PageInfo.Margin.Top = 0;
sec.PageInfo.Margin.Bottom = 0;
sec.PageInfo.Margin.Left = 0;
sec.PageInfo.Margin.Right = 0;
imageDrawing.Dispose();
image.ImageInfo.Alignment = Aspose.Pdf.AlignmentType.Center;
//Add image object into the Paragraphs collection of the section
sec.Paragraphs.Add(image);
image.ImageInfo.ImageFileType = imageType;
if (imageType == Aspose.Pdf.ImageFileType.Tiff)
{
image.ImageInfo.IsAllFramesInNewPage = true;
image.ImageInfo.TiffFrame = -1;
image.ImageInfo.IsBlackWhite = true;
}
image.ImageInfo.ImageStream = inStream;
//Save the Pdf
MemoryStream outStream = new MemoryStream();
pdf.Save(outStream);
outStream.Seek(0, SeekOrigin.Begin);
return outStream;
}

Hi,

I have tested the scenario using following code snippet and I am unable to notice the problem. The resultant PDF that I have generated is in attachment. Please take a look.

[C#]

//Instantiate a Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
//Create a section in the Pdf object
pdf1.PageSetup.Margin.Left = 0;
pdf1.PageSetup.Margin.Right = 0;
pdf1.PageSetup.Margin.Top = 0;
pdf1.PageSetup.Margin.Bottom = 0;

Aspose.Pdf.Section sec1 = pdf1.Sections.Add();
// Create a FileStream object to read the imag file
FileStream fs = File.OpenRead(@"c:\pdftest\Постановление+Правительства+РФ+N583(4467070_7904-Вх_16_11_2010).tif");

// Read the image into Byte array
byte[] data = new byte[fs.Length];
fs.Read(data, 0, data.Length);

// Create a MemoryStream object from image Byte array
MemoryStream ms = new MemoryStream(data);
//Create an image object in the section
Aspose.Pdf.Image imageht = new Aspose.Pdf.Image(sec1);
//Set the type of image using ImageFileType enumeration
imageht.ImageInfo.ImageFileType = ImageFileType.Tiff;
// Specify the image source as MemoryStream
imageht.ImageInfo.ImageStream = ms;

//Add image object into the Paragraphs collection of the section
sec1.Paragraphs.Add(imageht);
imageht.ImageInfo.TiffFrame = -1;
imageht.ImageInfo.IsAllFramesInNewPage = true;

//Save the Pdf
pdf1.Save("c:\\pdftest\\TIFFtoPDFConversion_test.pdf");
// Close the MemoryStream Object
ms.Close();

In case you face any problem or you have any further query, please feel free to contact. We apologize for your inconvenience.