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

System.Drawing.Printing.PaperSize -> PdfSharp.PageSize?
https://forum.pdfsharp.net/viewtopic.php?f=4&t=1143
Page 1 of 1

Author:  scotchfaster [ Tue Apr 13, 2010 8:49 pm ]
Post subject:  System.Drawing.Printing.PaperSize -> PdfSharp.PageSize?

My client has asked that we use the the currently selected paper size when we print a PDF file.

The problem is that the source value is of the type System.Drawing.Printing.PaperSize, and PdfPage.Size is of the type PdfSharp.PageSize. There doesn't seem to be any way to convert between the two that I can see.

Am I missing something? I guess I can write a big switch statement or use a map, but I'd rather not bother if this feature is already present.

Thanks in advance.

Author:  Thomas Hoevel [ Wed Apr 14, 2010 8:20 am ]
Post subject:  Re: System.Drawing.Printing.PaperSize -> PdfSharp.PageSize?

scotchfaster wrote:
Am I missing something?

You have papersize.Height and papersize.Width.

Use Unit.FromInch(papersize.Height / 100d) to set the Height of the PdfPage (with PageSize.Undefined). Same formula for Width.

Author:  scotchfaster [ Wed Apr 14, 2010 5:59 pm ]
Post subject:  Re: System.Drawing.Printing.PaperSize -> PdfSharp.PageSize?

Thanks, that was helpful. Here's my actual code:

Code:
PdfPage page = document.AddPage();
page.Width = XUnit.FromInch(((double)printDoc.PrinterSettings.DefaultPageSettings.PaperSize.Width) / 100d);
page.Height = XUnit.FromInch(((double)printDoc.PrinterSettings.DefaultPageSettings.PaperSize.Height) / 100d);

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