首页 新闻 会员 周边 捐助

winforms中怎么用C#代码设置打印机首选项的缩放

0
悬赏园豆:50 [待解决问题]

A4的文档 打印之前 先设置缩放到A5 打印完成后还原为实际尺寸不缩放

TopStop的主页 TopStop | 初学一级 | 园豆:104
提问于:2024-01-31 11:08
< >
分享
所有回答(2)
0

// 设置缩放比例
pd.DefaultPageSettings.Landscape = false;
pd.DefaultPageSettings.PaperSize = new PaperSize("A4", 827, 1169);
pd.DefaultPageSettings.Margins = new Margins(100, 100, 100, 100); // 左上右下边距

试一试

SonyXbox | 园豆:370 (菜鸟二级) | 2024-01-31 18:41
0

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());
}

}

mlhello-world | 园豆:204 (菜鸟二级) | 2024-02-01 17:17

PageSettings 没有 Scale属性呀

支持(0) 反对(0) TopStop | 园豆:104 (初学一级) | 2024-02-07 08:39
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册