Hi,
I want to detect if a PDF page is in horizontal or portrait format.
I tried:
if (page.Rect.Width > page.Rect.Height)
and:
if (page.TrimBox.Width > page.TrimBox.Height)
but for some PDF files, it doesn’t work… (I have a PDF file with only one horizontal page, and it gives me Height>Width… but for other files, it can work…)
Any help appreciated
Hi Raphael,
Hi,
Here is the PDF horizontal doc:
https://www.sendspace.com/file/t4j1jg
and my code:
for (int pageCount = 1; pageCount
{
using (FileStream imageStream = new FileStream(path + “/” + pageCount + “.jpg”, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
{
// Create Resolution object
Resolution resolution = new Resolution(100);
var page = pdfDocument.Pages[pageCount];
// Create JPEG device with specified attributes (Width, Height, Resolution, Quality)
JpegDevice jpegDevice;
if (page.TrimBox.Width > page.TrimBox.Height)
{
jpegDevice = new JpegDevice(877, 620, resolution, 100);
}
else
{
jpegDevice = new JpegDevice(620, 877, resolution, 100);
}
// Convert a particular page and save the image to stream
jpegDevice.Process(page, imageStream);
// Close stream
imageStream.Close();
}
}
(it’s a web page we use to convert PDF into images)
Thanks in advance
Hi Raphael,
Aspose.Pdf.Document
doc = new Aspose.Pdf.Document(myDir
- “Invoices_FR_PG rental_app_M+1.pdf”);<o:p></o:p>
foreach (Aspose.Pdf.Page page in doc.Pages)
{
Aspose.Pdf.Rectangle rect = page.GetPageRect(true);
Console.WriteLine("Page {0} width is {1} and heigth is {2}, rotation: {3}, size considering rotation: widht {4} : height {5}", page.Number, page.Rect.Width, page.Rect.Height, page.Rotate.ToString(), rect.Width, rect.Height);
if (rect.Width > rect.Height)
Console.WriteLine("Page no{0}: Landscape",page.Number);
else
Console.WriteLine("Page no{0}: Portrait", page.Number);
}
Please feel free to contact us for any further assistance.
Best Regards,
Thanks, it works perfectly now
Hi Raphael,