Printing Issues

198 views
Skip to first unread message

Shenoy, Vinod

unread,
May 11, 2012, 11:56:20 AM5/11/12
to pdfne...@googlegroups.com

Hi,

 

We do use the PDFTron’s PDFNet SDK to print PDFs. We are having issues with the printing where it is cutting off at the right and bottom margin. I have tried all possible solution that is out there on the site. I have pasted the code that we use currently. I would appreciate if anyone could help me identify what I am doing wrong.

 

static void PrintPage(object sender, PrintPageEventArgs ev)

        {

            Graphics gr = ev.Graphics;

            gr.PageUnit = GraphicsUnit.Inch;

 

            Rectangle rectPage = ev.PageBounds;         //print without margins

            //Rectangle rectPage = ev.MarginBounds;     //print using margins       

 

            //RectangleF rectPage = GetBestRectangle(ev);

            //Rectangle rectPage = GetRealPageBounds(ev, 2);  //Option 1 or Option 2

 

                  float dpi = gr.DpiX;

                  if (dpi>300) dpi = 300;

 

                  double left, right, top, bottom;

                 

                  left= rectPage.Left / 100.0;

                  right = rectPage.Right / 100.0;

                  top = rectPage.Top / 100.0;

                  bottom= rectPage.Bottom / 100.0;

 

            LogUtil("rectPage.Left " + left.ToString(), verboseLogs);

            LogUtil("rectPage.right " + right.ToString(), verboseLogs);

            LogUtil("rectPage.top " + top.ToString(), verboseLogs);

            LogUtil("rectPage.bottom " + bottom.ToString(), verboseLogs);

                 

            // One page unit is 1/72 of an inch.

            // For a 'letter' size page (8.5 x 11 inches) the dimensions will be:

            // width = 612 units = 612 * 1/72 = 8.5 inches

            // height = 792 units = 792 * 1/72 = 11 inches

 

            // ============================================================

                  // The above page dimensions are in inches. We need to convert the page

                  // dimensions to PDF units (or points). One point is 1/72 of an inch.

                  var rect = new pdftron.PDF.Rect(left*72, bottom*72, right*72, top*72);

               

                  try

                  {

                        pdfdraw.SetDPI(dpi);

                        pdfdraw.DrawInRect(pageitr.Current(), gr, rect);

               

                  }

                  catch (Exception ex)

                  {

                LogUtil("PDF printing Error: " + ex.ToString());

                  }

                 

                  pageitr.Next();  // Move to the next page, if any

                  ev.HasMorePages = pageitr.HasNext();

        }

 

Thanks,

Vinod Shenoy H.N.

Sr. Application Developer

Output Solutions

Fiserv

Direct: 314-387-2553

Cell: 314-363-3287

Fax: 314-387-2700

Email: vinod....@fiserv.com

P Please consider the environment before printing this email.

 

 

Ryan - PDFNet Developer

unread,
May 11, 2012, 4:36:27 PM5/11/12
to pdfne...@googlegroups.com
The PDF format is actually device neutral, and is independent of a physical size. 

To map from PDF space to a physical space, which is needed to render the PDF on a screen or printer, each page in the PDF document has a user space to translate. While it's true that the default is 1/72 inch, this can be a different value (e.g. 1/96).

Perhaps the problem is that your source page has a different UserUnit (an optional key on a Page, see 7.7.3.3 in PDF32000_2008).

Instead of using 72, try multiplying (or dividing) 72 by page.GetUserUnitSize().

Support

unread,
May 11, 2012, 4:43:14 PM5/11/12
to pdfne...@googlegroups.com
 
 
You may also want to use 'pdftron.PDF.Print.StartPrintJob()' instead of PDFDraw. The use of this API is illustrated in PDFPrint sample:
 
If you need more control you can convert PDF to XPS (new Windows spool format) using pdftron.PDF.Convert.ToXps() and print the file using Microsoft XPS Print API (http://msdn.microsoft.com/en-us/library/windows/desktop/ff686814(v=vs.85).aspx).
Reply all
Reply to author
Forward
0 new messages