logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
t3iv  
#1 Posted : 9 years ago
t3iv

Rank: Newbie

Groups: Registered
Joined: 2/16/2016(UTC)
Posts: 1
United States

Quote:
Hi,

I am trying to print a simple PDF page to the printer. It printed 5mm off from the top and 5mm from left. The same PDF file was printed correctly with Adobe Reader, Foxit Reader, etc. I have try OriginAtMargins but no effect. Here is the test code:

Code:

 public void PrintDocument(PdfDocument pdf)
        {
            //.Net Framework class from System.Drawing.Printing namespace
            PrintDocument pd = new PrintDocument();
            int pageForPrint = 0;
            

            pd.PrintPage += (s, e) =>
            {
                pd.PrinterSettings.FromPage = 1;
                pd.PrinterSettings.ToPage = 1;
                
                //set paper size and orientation
                e.PageSettings.PaperSize.RawKind = (int)PaperKind.Letter;
                e.PageSettings.Landscape = false;

                pd.OriginAtMargins = true;
                e.PageSettings.Margins.Top = 0;
                e.PageSettings.Margins.Left = 0;
                e.PageSettings.Margins.Bottom = 0;
                e.PageSettings.Margins.Right = 0;                

                //Calculate actual size in pixels that depends on current printer's DPI 
                int actualWidth = (int)(e.Graphics.DpiX * 8.5f); 
                int actualHeight = (int)(e.Graphics.DpiY * 11);
                

                //Render to PdfBitmap using page's Render method with FPDF_PRINTING flag
                pdf.Pages[pageForPrint].Render
                    (e.Graphics,
                    0,
                    0,
                    actualWidth,
                    actualHeight,
                    Patagames.Pdf.Enums.PageRotate.Normal, Patagames.Pdf.Enums.RenderFlags.FPDF_PRINTING);

                //Print next page
                if (pageForPrint < pdf.Pages.Count - 1)
                {
                    pageForPrint++;
                    e.HasMorePages = true;
                }
            };

            //start printing routine
            pd.Print();
        }
    }
}


Thanks.

Edited by moderator 9 years ago  | Reason: [code=cs]

Paul Rayman  
#2 Posted : 9 years ago
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,116

Thanks: 8 times
Was thanked: 130 time(s) in 127 post(s)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.