davidOhara
davidOhara

Reputation: 1008

Printersettings in C#

I am creating a PDF File in my application, and then I print it (works fine.)

When I print this pdf on another computer/Printer it doesn't look the same! I want it so that it always looks the same, on whichever printer I print on.

Maybe I have to set the borders? Like this:

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

But HardMargin is not writable. Have you guys got some ideas?

Upvotes: 0

Views: 7103

Answers (1)

speti43
speti43

Reputation: 3046

Try to set up this way:

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

Handler function:

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

Upvotes: 1

Related Questions