Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set the printing paper size #14

Open
buWenXin opened this issue Nov 21, 2023 · 1 comment
Open

How to set the printing paper size #14

buWenXin opened this issue Nov 21, 2023 · 1 comment

Comments

@buWenXin
Copy link

image
The printed paper seems to be A4, how do I set the paper size?
This is my code, I have set the size of the PDF, but it will not affect the paper size.

`var printerName = "pdfFactory Pro";

var printFile = "D:\MyProject\Electron\electron-print\PDF\test04.pdf";

var pdfDocument = PdfDocument.Load(printFile);

var printDocument = pdfDocument.CreatePrintDocument();

var s = printDocument.PrinterSettings = new PrinterSettings()
{
PrinterName = printerName
};

double pdfWidth = 40 / (25.4 / 100);
double pdfHeight = 30 / (25.4 / 100);
printDocument.DefaultPageSettings = new PageSettings()
{
Margins = new Margins(0, 0, 0, 0),
PaperSize = new PaperSize("size", (int)pdfWidth, (int)pdfHeight)
};

PaperSize updatedPaperSize = s.DefaultPageSettings.PaperSize;
Console.WriteLine(updatedPaperSize.Height);
printDocument.PrintController = new StandardPrintController();
printDocument.Print();`

I tried using PrinterSettings.PaperSizes sets the size of the printed paper, but this property is read-only and I cannot set it.
image

@zhyueyueniao
Copy link

设置纸张大小应该是printDocument.PageSettings.PaperSize

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants