I’m trying to convert the following tiff to a pdf.
./Aspose_Slides_Java/Examples/src/main/resources/com/aspose/slides/examples/Presentation/PresentationToTIFF/customsize/demo.tiff (I can't upload the tiff as the file update for the forum prevents adding tiff attachments)
From another forum post I've got two version but both have issues;
Using the document version I get two pages in the PDF, using the pdf version I get the 1st page of the TIFF in the 1st page of the PDF but not a 2nd page for the 2nd page in the TIFF.
Also the width and height don't match the original TIFF. How do I change each pdf page to match that of the TIFF width and size?
Using Document;
public ConvertTiffToPdfViaDocument(final String sourceImageFile, final String outputPdfFile) {
// instantiate Document object
com.aspose.pdf.Document document = new com.aspose.pdf.Document();
// add page to PDF file
document.getPages().add();
// create Image object
com.aspose.pdf.Image image = new com.aspose.pdf.Image();
// load TIFF image
image.setFile(sourceImageFile);
// add image to paragraphs collection of first page
document.getPages().get_Item(1).getParagraphs().add(image);
// save resultant PDF
document.save(outputPdfFile);
}
Using PDF;
public ConvertTiffToPdfViaPDF(final String sourceImageFile, final String outputPdfFile) {
aspose.pdf.Pdf pdf = new aspose.pdf.Pdf();
aspose.pdf.Section section = pdf.getSections().add();
aspose.pdf.Image image = new aspose.pdf.Image(section);
// java.net.URL url = new java.net.URL(“file:///D:/pdftest/TIF.tif”);
// BufferedImage bufferImage=ImageIO.read(url);
image.getImageInfo().setFile(sourceImageFile);
image.getImageInfo().setTiffFrame(-1);
image.getImageInfo().setImageFileType(aspose.pdf.ImageFileType.Tiff);
section.getParagraphs().add(image);
pdf.save(outputPdfFile);
}