I am using PDFsharp to read / write PDF in our application. I am trying to get the paper size of a page to show in metadata window. I am using following code to do the same:
// read PDF document into memory
var pdfDocument = PdfReader.Open(pdfPath);
// if PDF document has 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'.
I also created a PDF from HTML but then also page size comes as undefined.
static void Main(string[] args)
{
// create PDF config to generate PDF
var config = new PdfGenerateConfig()
{
PageSize = PageSize.Letter,
PageOrientation = PageOrientation.Landscape
};
// load the HTML file
var html = System.IO.File.ReadAllText(@"C:\Users\mohit\Desktop\Temp\Ekta\Test.html");
// generate the PDF
var pdf = PdfGenerator.GeneratePdf(html,
PageSize.Letter);
// get the paper size of first page
var size = pdf.Pages[0].Size;
// save the pdf document
pdf.Save(@"C:\Users\mohit\Desktop\Temp\Ekta\A13.pdf");
Console.ReadKey();
}