Question

I'm trying to print on custom size paper which was designed and printed before. it's something like invoice. but it still print on a4 size. whats is wrong in my settings here in my code?

protected void PrintFormLS(object sender, EventArgs e)
{
    PrintDocument pd = new PrintDocument();
    pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);

     pd.PrinterSettings.PrinterName = "HP LaserJet P1005";
     pd.DefaultPageSettings.PaperSize.RawKind = 119;
     pd.DefaultPageSettings.PaperSize = new PaperSize("lsForm", 563, 1251);
     pd.PrinterSettings.DefaultPageSettings.PaperSize = new PaperSize("lsForm", 563, 1251);
     pd.OriginAtMargins = true;
     Margins margins = new Margins(1, 1, 1, 1);
     pd.DefaultPageSettings.Margins = margins;
     pd.DefaultPageSettings.Landscape = true;
     pd.Print();

}
Was it helpful?

Solution

i have solve this problem by creating custom size in printer properties and specify it's number in code.

pd.PrinterSettings.PrinterName = "HP LaserJet P1005";
pd.OriginAtMargins = true;
PaperSize pageSize = new PaperSize();
pageSize.RawKind = 512; //this is number of created custom size 563x1251
Margins margins = new Margins(1, 1, 1, 1);
pd.DefaultPageSettings.Margins = margins;
pd.DefaultPageSettings.Landscape = true;
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
pd.Print();

hope it will help somebody.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top