PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Unable to get the page size from PDF document
https://forum.pdfsharp.net/viewtopic.php?f=2&t=3472
Page 1 of 1

Author:  EktaBhardwaj [ Wed Oct 12, 2016 3:11 pm ]
Post subject:  Unable to get the page size from PDF document

I am using PdfSharp to read / write pdf in our application. I am trying to get the paper size of the page to show in metadata window. I am using following code to do the same:

Code:
      // read PDF document into memory
      var pdfDocument = PdfReader.Open(pdfPath);

      // if PDF document have more than one page, then try to get the page size from first page
      if (pdfDocument.Pages.Count > 0)
      {
        var pageSize = pdfDocument.Pages[0].Size.ToString();
      } // if


But every time it returns 'Undefined', I even tried to create A4 page document for MS Word. But still, it returns 'Undefined'.

Author:  Thomas Hoevel [ Thu Oct 13, 2016 8:33 am ]
Post subject:  Re: Unable to get the page size from PDF document

Answered on SO:
http://stackoverflow.com/a/40015845/162529


The properties you have to use are Width and Height. Convert them to millimeter or inch if you do not want to show the size in points.

The property Size is a convenient way to set standard page sizes for new pages as you can specify A4 or Letter. It will not be set for imported PDF files.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/