I’ve attached a simple landscape document…
TestLandscapeDocPDF.pdf (33.0 KB)
… created with MS word. When loaded using Aspose PDF PageInfo.IsLandscape is resolving to false and page.PageInfo.Width seems to actually be the height of the document and page.PageInfo.Height seems to be the width.
As I’m attempting to render something in the PDF the width of the page, this is a blocking issue for me.
The issue is replicated with the following code.
[TestMethod]
public void TestLandscape()
{
Document document = new Document(@"D:\Temp\TestLandscapeDocPDF.pdf");
foreach (Page page in document.Pages)
{
Assert.IsTrue(
page.PageInfo.IsLandscape ||
(
page.PageInfo.Width > page.PageInfo.Height
));
}
}
@support-1
We have logged this problem in our issue tracking system as PDFNET-53059. You will be notified via this forum thread once this issue is resolved.
We apologize for your inconvenience.
@support-1
The PageInfo properties Width, Height, IsLandscape used in the attached code snippet are intended for using a PDF file generator and are not filled in when reading file.
To reliably determine the orientation of the page, use the MediaBox property of the page.
If the width there is less (or equal) than the height, the page has a portrait orientation, otherwise landscape.
Page sizes can be determined using UserUnit (if specified) and MediaBox.Width, MediaBox.Height.
using (Document document = new Document(fileName))
{
foreach (Page page in document.Pages)
{
var pageMediaBox = page.MediaBox;
var isLandscape = pageMediaBox.Width > pageMediaBox.Height; // reliably determined.
double userUnit = 72.0; // pixels per inch
if (page.EnginePage.PageInformation.UserUnit != null)
{
userUnit = 72.0 * page.EnginePage.PageInformation.UserUnit.ToDouble();
}
double k = 25.4 / userUnit;
var pageWidth = k * pageMediaBox.Width;
var pageHeight = k * pageMediaBox.Height;
Console.WriteLine("Height: " + pageHeight + ", Width: " + pageWidth + ", Landscape: " + isLandscape);
}
}