By converting multi page tif to Pdf- the first pdf page will be smaller than the others

Hello,

I am using Aspose.Pdf to convert tifs to pdf with this code:

foreach (string tif in tifs){

using (Bitmap bmp = (Bitmap) Image.FromFile(tif)){


Aspose.Pdf.

Section section1 = pdf.Sections.Add();


// creat an image object


Aspose.Pdf.

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


image1.ImageInfo.File = tif;


image1.ImageInfo.ImageFileType =

ImageFileType.Tiff;


if (bmp.Width > bmp.Height){


section1.IsLandscape =

true;


pdf.PageSetup.Margin.Bottom = 0;


pdf.PageSetup.Margin.Top = 0;


pdf.PageSetup.Margin.Left = 0;


pdf.PageSetup.Margin.Right = 0;


}



else{


section1.IsLandscape =

false;


pdf.PageSetup.Margin.Bottom = 0;


pdf.PageSetup.Margin.Top = 0;


pdf.PageSetup.Margin.Left = 0;


pdf.PageSetup.Margin.Right = 0;


}


// add the image to paragraphs collection of the PDF document


section1.Paragraphs.Add(image1);


}


}


pdf.Save(pdfFile);

All my pdf pages are A4, the Margin for the first page is different and it is smaller than the other pages.

can you please help me in solving this problem?

Thanks a lot

Mohamed

v

Hello Mohamed,

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.

Hello Support,

attached are the input file (tif) and the output (pdf)

Regards

Mohamed

Hello Mohamed,

Please try using the following code snippet as during my testing, all the frames of TIFF image are being displayed in same dimensions. Please take a look over the attached resultant PDF that I have generated using Aspose.Pdf for .NET 5.3.0. In case you still face any problem, please feel free to contact. We are sorry for your inconvenience.

[C#]

// create a PDF object
Pdf pdf = new Pdf();
// create a section and add it to pdf document
Aspose.Pdf.Section MainSection = pdf.Sections.Add();

//Add the radio form field to the paragraphs collection of the section
// create an image object
Aspose.Pdf.Image sample_image = new Aspose.Pdf.Image();
// specify the image file path information
sample_image.ImageInfo.File = @"d:/pdftest/E_5870768.att_1.tif";
// specify the image file type
sample_image.ImageInfo.ImageFileType = ImageFileType.Tiff;
// specify the image width information equal to page width
sample_image.ImageInfo.FixWidth = MainSection.PageInfo.PageWidth - MainSection.PageInfo.Margin.Left - MainSection.PageInfo.Margin.Right;
// specify the image Height information equal to page Height
sample_image.ImageInfo.FixHeight = MainSection.PageInfo.PageHeight- MainSection.PageInfo.Margin.Top- MainSection.PageInfo.Margin.Bottom;
// specify the option to include all the frames of TIFF image
sample_image.ImageInfo.TiffFrame = -1;
// add image to paragraphs collection of section
MainSection.Paragraphs.Add(sample_image);
// save the resultant PDF
pdf.Save(@"d:/pdftest/Image-to-PDF-Conversion.pdf");

Hallo Shahbaz,

I checked the pdf that you attached and i saw that it is not ok, it is smaller.

I attached 2 screenshots, one with yours and the other one how it should be.

Our tifs are not all in the same format, some of the pages can be in landscape format, that's why I have to split the tif and then as single images to pdf adding, is there a better way to do that?

is that implemented in your code?

Thanks a lot

Regards

Mohamed

Hello Mohamed,

In my previous attempt, I have specified the Width and Height information for TIFF frames less than Page Width and Height therefore the images are appearing as smaller in size. However I have observed that if I increase the Image Height and Width, the first page is being displayed in proper size but the subsequent pages are having smaller image size. It seems to be an issue with this specific TIFF image. For the sake of correction, I have logged this problem as PDFNET-28214 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.

Besides this, we already have logged a requirement to "access specific frame of TIFF image" so that we can specify the dimension information for individual tiff frame. It has been logged with an ID PDFNET-24181 in our issue tracking system. The development team is working hard to get this feature implemented and as soon as we have made some definite progress towards its resolution, we would be more than happy to share this information with you. Please be patient and spare us little time.

In your above comments, you have specified that you are splitting the TIFF file into various images and then you are adding them to PDF. I think in this particular scenario, you may try using the code snippet share over following link to Set the page orientation according to image dimensions.

FYI, Aspose.Words also supports the feature to include image file into word document and then you may try using the Direct-to-PDF save method of Aspose.Words to convert word file into PDF format. For more information, please visit How-to: Convert an Image to PDF