// 设置缩放比例
pd.DefaultPageSettings.Landscape = false;
pd.DefaultPageSettings.PaperSize = new PaperSize("A4", 827, 1169);
pd.DefaultPageSettings.Margins = new Margins(100, 100, 100, 100); // 左上右下边距
试一试
using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
public class PrintExample : Form
{
private PrintDocument printDocument;
private Button printButton;
public PrintExample()
{
printDocument = new PrintDocument();
printDocument.PrintPage += new PrintPageEventHandler(printDocument_PrintPage);
printButton = new Button();
printButton.Text = "Print";
printButton.Click += new EventHandler(printButton_Click);
Controls.Add(printButton);
}
private void printButton_Click(object sender, EventArgs e)
{
PrintDialog printDialog = new PrintDialog();
printDialog.Document = printDocument;
if (printDialog.ShowDialog() == DialogResult.OK)
{
// 获取用户选择的打印机
PrinterSettings printerSettings = printDialog.PrinterSettings;
// 设置打印机首选项,这里设置缩放为0.5(50%)
printerSettings.DefaultPageSettings.Scale = 0.5f;
// 开始打印
printDocument.Print();
}
}
private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
{
// 在打印页面上绘制内容
Graphics g = e.Graphics;
Font font = new Font("Arial", 12);
g.DrawString("Hello, World!", font, Brushes.Black, 100, 100);
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new PrintExample());
}
}
PageSettings 没有 Scale属性呀