We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Print .vs. PrintPreview in 2.0.5.0 still an issue.

Just installed 2.0.5.0 and all went well with the upgrade. However, I''m having problems with PrintPreview and Print showing and printing the same thing. (I still have an open issue in V1.6.1.6 with this issue.) I have a grid that fills a form. I use the standard print and print preview examples in the code with the exception that I set the page margins as follows: GridPrintDocument pd = new GridPrintDocument(this.gridDesigner, true); // If we have page settings apply them. if (m_pageSettings != null) { pd.DefaultPageSettings.Margins = m_pageSettings.Margins; } PrintPreviewDialog dlg = new PrintPreviewDialog(); dlg.Document = pd; dlg.ShowDialog(); The printer I''m using has a left hard margin of .25 inches. The PrintPreview will show correctly but the print through PrintPreview or just printing directly always add the page margin plus the hard margin so it is always offset. I''ve tried setting pd.OriginAtMargins and also creating a class that inherits from GridPrintDocument and overriding the OnPrintPage and check for screen print vs. printing to the printer and adjusting the margin in the event but still no luck. Thanks, Rick

5 Replies

AD Administrator Syncfusion Team April 26, 2004 11:09 AM UTC

There has been no change in the 2.0.5.0 to affect a problem such as this. Instead of trying to adjust the page margins in OnPrintPage, have you tried adjusting the margins in the DefaultPageSetting before calling the pd.Print? pd.PrinterSettings.DefaultPageSettings.Margins If you place a stop in your print routine and put the pd object in a Quick Watch window, is there something that reflects the value of your printer left hard margin? (maybe some gutter setting or something). If you could find this value, maybe you could reset it somehow???


AD Administrator Syncfusion Team April 26, 2004 11:36 AM UTC

I am having the same problem with my own PrintDocument (not GridPrintDocument). Just draw a rectangle around the margins and see the rectangle shifting. Is this a .NET issue? thanks, - Reddy


AD Administrator Syncfusion Team April 27, 2004 05:11 PM UTC

I fixed my problem looking at the following links. http://groups.google.com/groups?q=print+vs+printpreview&hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=eMw6xWfHCHA.2988%40tkmsftngp12&rnum=1 http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=u5Pt8h6PCHA.2380%40tkmsftngp12&rnum=2&prev=/groups%3Fq%3Dc%2523%2Bgetdevicecaps%26hl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3Du5Pt8h6PCHA.2380%2540tkmsftngp12%26rnum%3D2


RI Rick May 3, 2004 01:16 PM UTC

Clay, pd.PrinterSettings.DefaultPageSettings.Margins did not work but I did manage to find a solution by obtaining the hard margins for the printer. I tried hard margins before but couldn''t get it working. After looking closer at GridPrintDocument in 2.0.5.0 I finally found the solution. Here it is (hope it formats ok): Notes: 1) I''m print without the frame 2) I''ve tested clipping and it works. For example, I set the left margin to .2 but the printer has a hard margin of .25 resulting in a clipped page. Setting the left page margin to .25 printed right on the hard margin edge. 1) Create a new class derived from GridPrintDocument. (This is similar to the solutions found on the web where PrintDocument is the base class.) 2) Override OnPrintPage as follows: protected override void OnPrintPage(System.Drawing.Printing.PrintPageEventArgs ev) { // Original PrintPageEventArgs in the case we are doing a Print Preview. PrintPageEventArgs ppea = ev; // We need to check if this is the printer or screen. A screen will have VisibleClipBounds of X < 0 if (ev.Graphics.VisibleClipBounds.X >= 0) { // Obtain the hard margins. float left, top, right, bottom; System.IntPtr hDC = ev.Graphics.GetHdc(); DesignerTicketEditor.GetHardMargins((int)hDC, out left, out top, out right, out bottom); ev.Graphics.ReleaseHdc(hDC); // Modify the ev.MarginBounds by accounting for user requested page margins verses the hard margins. // Note: GridPrintDocument uses ev.MarginBounds so that is why we modify them. int x1 = ev.PageBounds.Left + ev.PageSettings.Margins.Left - (int)left; int y1 = ev.PageBounds.Top + ev.PageSettings.Margins.Top - (int)top; int x2 = ev.PageBounds.Right - ev.PageSettings.Margins.Right + (int)right; int y2 = ev.PageBounds.Bottom - ev.PageSettings.Margins.Bottom + (int)bottom; // We can''t override ev.MarginBounds so we create a new event with the new margin bounds. Rectangle newMargins = new Rectangle(x1, y1, x2-x1, y2-y1); ppea = new PrintPageEventArgs(ev.Graphics, newMargins, ev.PageBounds, ev.PageSettings); } base.OnPrintPage(ppea); } >There has been no change in the 2.0.5.0 to affect a problem such as this. > >Instead of trying to adjust the page margins in OnPrintPage, have you tried adjusting the margins in the DefaultPageSetting before calling the pd.Print? > >pd.PrinterSettings.DefaultPageSettings.Margins > > >If you place a stop in your print routine and put the pd object in a Quick Watch window, is there something that reflects the value of your printer left hard margin? (maybe some gutter setting or something). If you could find this value, maybe you could reset it somehow???


RI Rick May 3, 2004 01:22 PM UTC

I made a mistake. The width and height values for the new bounds are off by one unit. Rectangle newMargins = new Rectangle(x1, y1, x2-x1, y2-y1); should be Rectangle newMargins = new Rectangle(x1, y1, x2-x1+1, y2-y1+1); Rick >Clay, > >pd.PrinterSettings.DefaultPageSettings.Margins did not work but I did manage to find a solution by obtaining the hard margins for the printer. I tried hard margins before but couldn''t get it working. After looking closer at GridPrintDocument in 2.0.5.0 I finally found the solution. Here it is (hope it formats ok): > >Notes: >1) I''m print without the frame >2) I''ve tested clipping and it works. For example, I set the left margin to .2 but the printer has a hard margin of .25 resulting in a clipped page. Setting the left page margin to .25 printed right on the hard margin edge. > > >1) Create a new class derived from GridPrintDocument. (This is similar to the solutions found on the web where PrintDocument is the base class.) > >2) Override OnPrintPage as follows: > >protected override void OnPrintPage(System.Drawing.Printing.PrintPageEventArgs ev) >{ > // Original PrintPageEventArgs in the case we are doing a Print Preview. > PrintPageEventArgs ppea = ev; > > // We need to check if this is the printer or screen. A screen will have VisibleClipBounds of X < 0 > if (ev.Graphics.VisibleClipBounds.X >= 0) > { > // Obtain the hard margins. > float left, top, right, bottom; > System.IntPtr hDC = ev.Graphics.GetHdc(); > DesignerTicketEditor.GetHardMargins((int)hDC, out left, out top, out right, out bottom); > ev.Graphics.ReleaseHdc(hDC); > > // Modify the ev.MarginBounds by accounting for user requested page margins verses the hard margins. > // Note: GridPrintDocument uses ev.MarginBounds so that is why we modify them. > int x1 = ev.PageBounds.Left + ev.PageSettings.Margins.Left - (int)left; > int y1 = ev.PageBounds.Top + ev.PageSettings.Margins.Top - (int)top; > int x2 = ev.PageBounds.Right - ev.PageSettings.Margins.Right + (int)right; > int y2 = ev.PageBounds.Bottom - ev.PageSettings.Margins.Bottom + (int)bottom; > > // We can''t override ev.MarginBounds so we create a new event with the new margin bounds. > Rectangle newMargins = new Rectangle(x1, y1, x2-x1, y2-y1); > ppea = new PrintPageEventArgs(ev.Graphics, newMargins, ev.PageBounds, ev.PageSettings); > } > > base.OnPrintPage(ppea); >} > > > > > >>There has been no change in the 2.0.5.0 to affect a problem such as this. >> >>Instead of trying to adjust the page margins in OnPrintPage, have you tried adjusting the margins in the DefaultPageSetting before calling the pd.Print? >> >>pd.PrinterSettings.DefaultPageSettings.Margins >> >> >>If you place a stop in your print routine and put the pd object in a Quick Watch window, is there something that reflects the value of your printer left hard margin? (maybe some gutter setting or something). If you could find this value, maybe you could reset it somehow???

Loader.
Live Chat Icon For mobile
Up arrow icon