0

我正在我的应用程序中创建一个 PDF 文件,然后打印它(工作正常。)

当我在另一台计算机/打印机上打印此 pdf 时,它看起来不一样!我希望它在我打印的任何打印机上看起来总是一样的。

也许我必须设置边界?像这样:

PrinterSettings ps = new PrinterSettings();
ps.DefaultPageSettings.HardMarginX = 0;
ps.DefaultPageSettings.HardMarginY = 0;

但是 HardMargin 是不可写的。你们有什么想法吗?

4

1 回答 1

1

尝试这样设置:

 PrintDocument printDocument1 = new PrintDocument();

        var printerSettings = new System.Drawing.Printing.PrinterSettings();
        printerSettings.PrinterName = "Printer name";// optional
        //printerSettings.PrinterName = "HP Officejet J6400 series";

        printDocument1.PrinterSettings = printerSettings;

        printDocument1.PrintPage += printDocument1_PrintPage;
        PrintDialog printDialog1 = new PrintDialog();
        printDialog1.Document = printDocument1;
// in the dialog, you can set up the paper size, etc.
        printDialog1.UseEXDialog = true;
        if (printDialog1.ShowDialog() == DialogResult.OK)
        {
        printDocument1.Print();
        }

处理函数:

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
    {
//This print form a rich textbox, but you can render pdf here.
        //e.Graphics.DrawString(richTextBox1.Text, richTextBox1.Font, Brushes.Black, 100, 20);
        //e.Graphics.PageUnit = GraphicsUnit.Inch;
    }
于 2012-08-01T09:46:00.937 回答