How do i convert a Multipage TIFF to a PDF


#1

Hi

How do i convert a Multipage TIFF to a PDF


Multi-page TIFF images to PDF problem
#2

@david.hancock.imagef

Thanks for contacting support.

Please use following code snippet, in order to convert multi-page TIFF into PDF.

Document pdf1 = new Document();
MemoryStream ms = new MemoryStream();
new FileStream(dataDir + @"WO02006172A1.tif", FileMode.Open).CopyTo(ms);
Bitmap myimage = new Bitmap(ms);

FrameDimension dimension = new FrameDimension(myimage.FrameDimensionsList[0]);
int frameCount = myimage.GetFrameCount(dimension);

for (int frameIdx = 0; frameIdx <= frameCount - 1; frameIdx++)
{
 Page sec = pdf1.Pages.Add();

 myimage.SelectActiveFrame(dimension, frameIdx);

 MemoryStream currentImage = new MemoryStream();
 myimage.Save(currentImage, ImageFormat.Tiff);

 Aspose.Pdf.Image imageht = new Aspose.Pdf.Image();
 imageht.ImageStream = currentImage;
 sec.Paragraphs.Add(imageht);
}
pdf1.Save(dataDir + "TifftoPDF.pdf");

In case you face any issue, please share your sample TIFF file with us, so that we can test the scenario in our environment and address it accordingly.


#3

Hello,

using this code i can only convert the first page to PDF. Is it possible that there is an issue with the code ?


#4

@panosk

Thanks for getting back to us.

We have tested above code snippet with one of our sample TIFF images and found it correct. Would you please share your sample TIFF image with us. We will test the scenario in our environment and address it accordingly.


#5

How can I do the same in Aspose.Pdf Java? I’m using 19.4 version.


#6

@pjanardhan

Please use following Java code to achieve functionality:

try {
     Document doc = new Document();
     // Add a page to pages collection of document
     Page page = doc.getPages().add();
     // Load the source image file to Stream object
     FileInputStream fs = new FileInputStream(dataDir + "input.TIF");

     java.awt.image.BufferedImage bImage = null;
     bImage = javax.imageio.ImageIO.read(new File(dataDir + "input.TIF"));

     page.getPageInfo().setHeight(bImage.getHeight());
     page.getPageInfo().setWidth(bImage.getWidth());
     // Set margins so image will fit, etc.
     page.getPageInfo().getMargin().setBottom(0);
     page.getPageInfo().getMargin().setTop(0);
     page.getPageInfo().getMargin().setLeft(0);
     page.getPageInfo().getMargin().setRight(0);
     Image image1 = new Image();
     // Add the image into paragraphs collection of the section
     page.getParagraphs().add(image1);
     // Set the image file stream
     image1.setImageStream(fs);

     doc.save(dataDir + "output.pdf");
}catch (Exception ex){
     ex.printStackTrace();
}

#7

Assuming the source tiff is “input.TIF”, what is “12-1735-0616-8-003.TIF”?


#8

@upacheco

We are sorry for the confusion.

Both names should be of same TIFF image. We have now edited the code snippet in our previous reply.