Convert Multipage tiff to multipage pdf

Hi,

I am trying out Aspose Imaging for Java. I am trying to convert to multi page/frame tiff to multi page PDf. Can’t find any example.

Can any help with an example to how to do this

Thanks!

@sachin1988,

I have observed your requirements and suggest you to please visit this link to export each Tiff frame inside Tiff image to separate image. You can export to PDF using Pdfoptions while using tifframe.Save() method call.

Hi Mudassir,

Thanks for your reply.
The code sample you have linked is for .NET. I am looking for Java example.
Even in .NET example it is exporting individual images. and we will need to use Aspose PDF dependency just to be able to that. I need a simple export option like you have for djvu format with DjvuMultiPageOptions
Example :
" Converting DjVu to PDF Format" section in

And we want it to be single pdf with multiple page (1 page per frame). Not one PDF per tiff frame

@sachin1988

Thank you for elaborating your requirements.

You may convert a multi-frame TIFF image to single multi-page PDF document using below code snippet with Aspose.PDF for Java.

// instantiate Document instance
Document doc = new Document();

// add blank page to pages collection of Document instance
doc.getPages().add();

// create Image object
com.aspose.pdf.Image image = new com.aspose.pdf.Image();
image.setFile(dataDir + "TestImage.tiff");

// add image to paragraphs collection of PDF page
doc.getPages().get_Item(1).getParagraphs().add(image);

// save resultant file
doc.save(dataDir + "Test_18.10.pdf");

We hope this will be helpful. Please feel free to contact us if you need any further assistance.

Thanks @Farhan.Raza

Though the solution works, It doesn’t set proper page size and in my case images were stretched on page.
Before seeing your reply i already found a solution which sets page size also properly.

Adding my code also, this may help someone else on this forum in future looking for similar solution. This will allow them to choose any of these solutions as per their needs.

TiffImage image = (TiffImage) Image.load(imagePath);
		String pdfPath = imagePath + ".pdf";
		Document pdf = new Document();
		for (TiffFrame f : image.getFrames()) {
			com.aspose.pdf.Page page = pdf.getPages().add();
			com.aspose.pdf.Image img = new com.aspose.pdf.Image();
			page.getParagraphs().add(img);
			page.setPageSize(f.getWidth(), f.getHeight());
			ByteArrayOutputStream output = new ByteArrayOutputStream();
			f.save(output, new JpegOptions());
			img.setImageStream(new ByteArrayInputStream(output.toByteArray()));
		}
		pdf.save(pdfPath);

Also, This seems to be working for me. Still if you see anything that may cause problem please suggest a change as for now I have tested it with very limited set of images

@sachin1988

Thank you for your valuable feedback.

We are glad to know that things are now working fine in your environment. Please keep using our APIs and in event of any further query, feel free to ask.