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

Free Support Forum - aspose.com

isLandscape

Hi,

if we try to convert a landscape pdf to an image, we resulting image is strechted to a portrait mode.
Document().getPages().get_Item(0).getPageInfo().isLandscape() is false and values for height and width are interchanged.
This was seen in java aspose.pdf-17.6, 17.7 and 17.8.

Kind regards, Josef

1 Like

@josef.auer1,
We have saved a single page Word document (landscape) into the PDF format, and then tested with the latest version 17.8 of Aspose.Diagram for Java API. We managed to replicate the problem of incorrect width, height and landscape information in our environment. It has been logged under the ticket ID PDFJAVA-37048 in our bug tracking system. We have linked your post to this ticket and will keep you informed regarding any available updates.

However, the output JPG image is saved with the landscape orientation. If the output image orientation is not landscape in your environment, then kindly share the complete details of the use case, including source PDF and code. We will investigate and share our findings with you.

Hi,
we only work with bytestreams. in this streams, image orientation is also incorrect. please see attacht source sample.
king regards, josef
sample.zip (708 Bytes)

@josef.auer1,
Your code is incomplete because the definition of getPageDimension and findRatio methods are not available. Please review and share the complete executable code. We will investigate and share our findings with you.

Hi,
we’ve attached a sample project.
kind regards, josef
landscape.zip (335.1 KB)

@josef.auer1,
You are modifying the size of image by calculating the ratio, but still the orientation is not being changed. This is the output image of your code: test.jpg (732.9 KB), and when we saved into the image format without calculating ratio by calling the following code:

[Java]

ByteArrayOutputStream stream = new ByteArrayOutputStream();
converter.getNextImage(stream);
byte[] data = stream.toByteArray();
File file = new File(dataDir + "testwithoutRatio.jpg");
FileUtils.writeByteArrayToFile(file, data);
Image img =Image.load(new ByteArrayInputStream(data));
System.out.println(img.getWidth() + "x" + img.getHeight());

This is the output image: testwithoutRatio.jpg (802.9 KB)

In reference to ticket ID PDFJAVA-37048, please note that the PageInfo properties are being used for PDF generation only. Please, use the code snippet below for existing documents:

[Java]

String dataDir = "C:\\Pdf\\test269\\";		
Document document = new Document(dataDir + "Input.pdf");
System.out.println("PageWidth " + document.getPages().get_Item(1).getRect().getWidth() /72 );
System.out.println("PageHeight " + document.getPages().get_Item(1).getRect().getHeight() /72);
  
if (document.getPages().get_Item(1).getRect().getWidth() > document.getPages().get_Item(1).getRect().getHeight()) {
  System.out.println("Landscape");
} else {
  System.out.println("Portrait");
}

PS: the linked ticket ID PDFJAVA-37048 has been closed.

We’ve changed converter.getDocument().getPages().get_Item(pageNumber).getPageInfo() to converter.getDocument().getPages().get_Item(pageNumber).getRect() to get width and height.

PdfConverter converter = new PdfConverter();
converter.bindPdf(new ByteArrayInputStream(jcrFile.getContent()));
System.out.println(converter.getDocument().getPages().get_Item(1).getRect().getWidth() + “x” + converter.getDocument().getPages().get_Item(1).getRect().getHeight());
result: 595.0x842.0

As we have to downscale some pdf, we need to modify the size of the pdf. Does the next release return correct width & height?
Kind Regards, Josef

@josef.auer1,
The basic unit of measurement in Aspose.Pdf for .NET API is Point where 1 inch = 72 points, so please divide the width and height of the page with 72 to get the page size in inches.

if we use the code above for a landscape pdf, we get width and height like a portrait pdf. Does the next release returns correct width & height?
King Regards, Josef

@josef.auer1,
The page inside the PDF is landscape and Aspose.Pdf for Java 17.8 does not recognize it as portrait. Please try the following code:

[Java]

PdfConverter converter = new PdfConverter();
converter.bindPdf(dataDir + “Input.pdf”);
System.out.println("Page Width: " + converter.getDocument().getPages().get_Item(1).getRect().getWidth()/72);
System.out.println("Page Height: " + converter.getDocument().getPages().get_Item(1).getRect().getHeight()/72);
if (converter.getDocument().getPages().get_Item(1).getRect().getWidth()/72 > converter.getDocument().getPages().get_Item(1).getRect().getHeight()/72)
{
System.out.println(“Landscape”);
} else {
System.out.println(“Portrait”);
}

Result:

Page Width: 11.0
Page Height: 8.5
Landscape

PdfConverter converter = new PdfConverter();
converter.bindPdf(“c:/temp/landscape.pdf”);

System.out.println("Page Width: " + converter.getDocument().getPages().get_Item(pageNumber).getRect().getWidth()/72);
System.out.println("Page Height: " + converter.getDocument().getPages().get_Item(pageNumber).getRect().getHeight()/72);

Result:
Page Width: 8.26388888888889
Page Height: 11.694444444444445

landscape.pdf (339.0 KB)

@josef.auer1,
We managed to replicate the problem of incorrect width and height in our environment. It has been logged under the ticket ID PDFJAVA-37072 in our bug tracking system. We have linked your post to this ticket and will keep you informed regarding any available updates.

Is there a planned release date for these issues?
Kind regards, Josef

@josef.auer1,

In reference to the ticket ID PDFJAVA-37048, please download the latest version 17.10 of Aspose.Pdf for Java API and try the following code:

[Java]

String dataDir = "C:\\Pdf\\test269\\";		
Document document = new Document(dataDir + "Input.pdf");
System.out.println("PageWidth " + document.getPages().get_Item(1).getRect().getWidth() /72 );
System.out.println("PageHeight " + document.getPages().get_Item(1).getRect().getHeight() /72);
  
if (document.getPages().get_Item(1).getRect().getWidth() > document.getPages().get_Item(1).getRect().getHeight()) {
  System.out.println("Landscape");
} else {
  System.out.println("Portrait");
} 

In reference to the ticket ID PDFJAVA-37072, for cases Rotation.on90 and Rotation.on270, the height value should be read as the width and width value should be read as the height. Please try the following code:

[Java]

//please add the following code chack
if (com.aspose.pdf.Rotation.on90 == converter.getDocument().getPages().get_Item(1).getRotate())
            System.out.println("Page is rotated on 90 degrees clockwise");

Checking rotation and changing width/height solved our problem!
Kind regards, Josef

@josef.auer1,

Thank you for the confirmation. It is nice to hear from you that the problem has been resolved.