Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Tue Apr 23, 2019 9:29 pm

Is it possible to get the page size (to get the media size information .. a4, a3 and others ...) from a PDF file?
In the properties of the file is shown in millimeters (example: 210x297 mm).

I used the following code:
Dim ArquivoPdf As New PdfDocument
ArquivoPdf.LoadFromFile("filepdf.pdf")
Dim PaperSize As String = ArquivoPdf.PageSettings.Size.ToString

But it returns these values:
{Width=595, Height=842}

How to extract this information (210x297 mm) from the file using C # or VB?
Attached follows image of the properties screen and the desired information.
Right now, grateful

gafforelli
 
Posts: 37
Joined: Sat Sep 15, 2018 6:38 pm

Wed Apr 24, 2019 10:20 am

Hi,

Thanks for your inquiry.
Kindly note that the unit of page size in our Spire.PDF is Point. The unit of PDF page in your Adobe reader is Millimeter. Unit conversion from Point to Millimeter is around 1pt = 0.3527mm. Our Spire.PDF provides the PdfUnitConvertor class to do unit conversion. You could refer to the following code to obtain the page size in Millimeter unit. If there is any question, please feel free to write back.
Code: Select all
Dim ArquivoPdf As New PdfDocument()
ArquivoPdf.LoadFromFile("input.pdf")
Dim size As SizeF = ArquivoPdf.PageSettings.Size
Dim unitConvertor As New PdfUnitConvertor()
Dim widthMM As Single = unitConvertor.ConvertUnits(size.Width, PdfGraphicsUnit.Point, PdfGraphicsUnit.Millimeter)
Dim heightMM As Single=unitConvertor.ConvertUnits(size.Height, PdfGraphicsUnit.Point, PdfGraphicsUnit.Millimeter)

Sincerely,
Nancy
E-iceblue support team
User avatar

nancy.yang
 
Posts: 184
Joined: Wed Apr 03, 2019 2:33 am

Wed Apr 24, 2019 8:47 pm

Hi Nancy
First of all thank you for the quick return.
The calculation returned the A4 measurements correctly, but I find it strange that any document is returning the value of A4.
Attached is an example that was printed in A3 (842x1191) and the library returns the values ​​as if it were A4 (595x842).
What can it be?
Right now, grateful!

gafforelli
 
Posts: 37
Joined: Sat Sep 15, 2018 6:38 pm

Thu Apr 25, 2019 8:42 am

Hi,

Thanks for your feedback.
Sorry that I should point out earlier that the doc.PageSettings.Size is usually used to set a size of new page. To get the correct size of page, please use the following method instead.
Code: Select all
'get the width and height of the first page
Dim size As SizeF = ArquivoPdf.Pages(0).Size

Sincerely,
Nancy
E-iceblue support team
User avatar

nancy.yang
 
Posts: 184
Joined: Wed Apr 03, 2019 2:33 am

Thu Apr 25, 2019 1:48 pm

Hi Nancy
Worked perfectly!
Solved my problem!
Thank you very much for your attention and quick return.
:)

gafforelli
 
Posts: 37
Joined: Sat Sep 15, 2018 6:38 pm

Fri Apr 26, 2019 1:15 am

Hi,

Thanks for your feedback.
If there is anything we can do for you in the future, please do not hesitate to contact us.
Wish you all the best!

Sincerely,
Nancy
E-iceblue support team
User avatar

nancy.yang
 
Posts: 184
Joined: Wed Apr 03, 2019 2:33 am

Return to Spire.PDF