We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

The size differs when converting TIF to PDF

Hi,


We are using this snippet to convert TIF to PDF

Document doc = new Document();
Page page = doc.getPages().add();
Image image = new Image();
InputStream isImage = new FileInputStream(“sample.tif”);
image.setImageStream(isImage);

page.getPageInfo().getMargin().setBottom(0);
page.getPageInfo().getMargin().setTop(0);
page.getPageInfo().getMargin().setLeft(0);
page.getPageInfo().getMargin().setRight(0);
int width=0;
int height=0;
page.setCropBox(new com.aspose.pdf.Rectangle(0, 0, width, height));
page.getParagraphs().add(image);
doc.save(“sample.pdf”,com.aspose.pdf.SaveFormat.Pdf);

However we are not able to find out TIF’s width and height to substitute from standard JDK libraries.
page.setCropBox(new com.aspose.pdf.Rectangle(0, 0, width, height));

what we need is if we dont call
page.setCropBox(new com.aspose.pdf.Rectangle(0, 0, width, height)); then we want aspose.pdf to set the TIF’s width and height to the generated pdf.


Hi Pradeep,


Thanks for contacting support.

Do you mean you need to set the PDF page dimensions as per dimensions of input TIFF image ? If so is the case, then please get image dimensions and set same dimensions for Page instance.

page.setCropBox(new com.aspose.pdf.Rectangle(0, 0, image.getFixWidth(), image.getFixHeight()));

In case you face any issue, please share the input TIFF image, so that we can test the scenario in our environment. We are sorry for this inconvenience.
The width and height for tiff comes out to be 0

System.out.println(image.getFixWidth()+"---"+ image.getFixHeight());

I have attached the file called sample.tif and the Java program
Again here is the snippet of the code
Document doc = new Document();
Page page = doc.getPages().add();
Image image = new Image();
page.getPageInfo().getMargin().setBottom(0);
page.getPageInfo().getMargin().setTop(0);
page.getPageInfo().getMargin().setLeft(0);
page.getPageInfo().getMargin().setRight(0);
InputStream isImage = new FileInputStream("sample.tif");
image.setImageStream(isImage);
page.setCropBox(new com.aspose.pdf.Rectangle(0, 0, image.getFixWidth(), image.getFixHeight()));
System.out.println(image.getFixWidth()+"---"+ image.getFixHeight());
page.getParagraphs().add(image);
doc.save("sample.pdf",com.aspose.pdf.SaveFormat.Pdf);

Any update on this?

Hi Pradeep,


Thanks for sharing the details.

I have again tested the scenario and as per my observations, the Width and Height information is being returned as 0. However I have also observed that conversion process is generating java.lang.OutOfMemoryError: Java heap space when tested over Windows 10 (x64) using Eclipse Juno project with JDK 1.8. For the sake of correction, I have logged it as PDFJAVA-36664 in our issue tracking system. We will further look into the details of this problem and will keep you posted on the status of correction.

I have also observed that API is not returning dimensions for input TIFF image. Please be patient and spare us little time. We are sorry for this inconvenience.

Hi Pradeep,


Adding more to my previous comments, in case you need to get the dimensions of input TIFF image, please try Aspose.Imaging for Java. Please take a look over following code snippet. Use this information to set PDF page dimensions.

[Java]
com.aspose.imaging.fileformats.tiff.TiffImage image = (com.aspose.imaging.fileformats.tiff.TiffImage)com.aspose.imaging.Image.load(“path to image”);

int framesCount = image.getFrames().length;

for (int i = 0; i < framesCount; i++)
{
com.aspose.imaging.fileformats.tiff.TiffFrame frame = image.getFrames()[i];

System.out.println("Horizontal resolutions: ");
System.out.println(frame.getHorizontalResolution());

System.out.println("Height: " + frame.getHeight());

System.out.println("Vertical resolutions: ");
System.out.println(frame.getVerticalResolution());

System.out.println("Width: " + frame.getWidth());
}