This is a migrated thread and some comments may be shown as answers.

Programatic Printing Wrong Size

11 Answers 663 Views
PdfViewer and PdfViewerNavigator
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 24 Jun 2013, 03:45 AM
When I use RadPdfViewer1.Print() or RadPdfViewer1.Print(True) to print, the printed document has been shrunk. If I use the Navigator it prints fine.


I did some testing this morning and have discovered that I get the same results with using RadPrintDocument to print using RadPrintDocument1.Print. 

What do I need to do to make this work properly?

11 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 27 Jun 2013, 06:59 AM
Hello Jeff,

Thank you for reporting this to us.

By default RadPdfViewerNavigator sets the DefaultPageSettings's Margins to zero:
radPdfViewerNavigator.printDocument.DefaultPageSettings.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);

The PrintDocument's Margin property have for default values 100 pixels and when you use directly RadPrintDocument it is prints with default margins values. I suggest when use directly RadPrintDocument to set manually margins before print to derided for you values.

I hope you find this useful.

Regards,
Peter
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Jeff
Top achievements
Rank 1
answered on 02 Jul 2013, 04:28 PM
Thank you for the reply.Setting the margins on the RadPrintDocument works perfectly.
0
willi
Top achievements
Rank 1
answered on 30 Apr 2014, 02:43 PM
When Printing with 

radPdfViewerNavigator.printDocument.DefaultPageSettings.Margins = newSystem.Drawing.Printing.Margins(0, 0, 0, 0);

The printed document has a margin for about 5mm from Top and Left compared to the same document printed with Acrobat. 
Its not allowed to apply negative margins (error).

no error with this code (but margins still 0)

newPdfViewerNavigator.PrintDocument.DefaultPageSettings.Margins = New System.Drawing.Printing.Margins(-0.19685, 0, -0.19685, 0)
 
Tested on PdfViewer 2014.1.226.40

Regards

Willi

0
George
Telerik team
answered on 01 May 2014, 02:24 PM
Hi Willi,

Thank you for writing.

Printers do not print to the end of the paper. They leave a margin which you cannot change with software. Margins of 0, 0, 0, 0 is the lowest possible margin you can set. On the other hand the constructor for the Margins type (which is from the System.Drawing.Printing) namespace does not allow values less than zero which shows us that by design .NET framework does not accept negative margins.

I hope that this information is helpful.

Regards,
George
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
willi
Top achievements
Rank 1
answered on 06 May 2014, 07:26 AM
[quote]George said:Hi Willi,

Thank you for writing.

Printers do not print to the end of the paper. They leave a margin which you cannot change with software. Margins of 0, 0, 0, 0 is the lowest possible margin you can set. On the other hand the constructor for the Margins type (which is from the System.Drawing.Printing) namespace does not allow values less than zero which shows us that by design .NET framework does not accept negative margins.

I hope that this information is helpful.

Regards,
George
Telerik
 [/quote]
So, this means, that printing with the pdf-viewer ist buggy, becaus printing the same document with acrobat produces the correct margins.

Also we found out, that there are rendering-errors. When rendering Lines - the lines are wrong displayed - for example: Dottet lines are solid aso.

Best
Willi
0
George
Telerik team
answered on 09 May 2014, 06:58 AM
Hello Wilfrid,

Thank you for replying.

I have tested printing the same document with both - RadPdfViewer and AdobeReader. Both printed exactly the same way on an xps document. It is up to the printer and its settings how the document will be printed on paper. You can find the two xps documents attached below.

As to the problems with rendering, I will need the problematic document in order to be able to assist you further on this matter.

Looking forward to your response.

Regards,
George
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Gøran
Top achievements
Rank 2
answered on 16 May 2014, 10:21 AM
Hi Telerik Team,

We're experiencing same results as Willi reported. 

The following Code produces the attached JPG of the shrunk PDF. Same result if we print it via an common printer on paper.

01.using System;
02.using System.IO;
03.using System.Linq;
04.using Telerik.WinControls.UI;
05. 
06.namespace afos2care.POCs
07.{
08.    public class gui_tester
09.    {
10.        RadPdfViewer pdf;
11.        RadPdfViewerNavigator nav;
12.        Stream stream;
13. 
14.        public gui_tester()
15.        { }
16. 
17.        public void printpdf(string path)
18.        {
19.            this.pdf = new RadPdfViewer();
20.            this.pdf.DocumentLoaded += pdf_DocumentLoaded;
21. 
22.            this.nav = new RadPdfViewerNavigator();
23. 
24.            string pdfFile = @"C:\Program Files (x86)\Telerik\UI for WinForms Q1 2014\Examples\QuickStart\PdfViewer\Sample.pdf";
25. 
26.            this.stream = File.OpenRead(pdfFile);
27. 
28.            this.pdf.LoadDocument(stream);
29. 
30.            Console.WriteLine("Done... so far...");
31.        }
32. 
33.        void pdf_DocumentLoaded(object sender, EventArgs e)
34.        {
35.            if (this.pdf != null)
36.            {
37.                this.nav.AssociatedViewer = this.pdf;
38.                 
39.                this.pdf.Print(false);
40. 
41.                Console.WriteLine("Printed... hopefully...");
42.            }
43.        }
44.    }
45.}

So far so good. The "bad" thing is, that if you use the PrintButton of radPdfViewerNavigator via a Form to initiate the print action, everything is fine ( see JPG of the normal PDF).

Setting the Margins doesn't work, because we don't have a RadPrintDocument.

What's telerik doing behind the PrintButton? ;)


Well... maybe you know an other way to print a pdf directly to a printer without using the acrobat reader as a detour.

Hopefully you can help us.

Greetings from germany,
Gøran
0
Gøran
Top achievements
Rank 2
answered on 16 May 2014, 11:31 AM
Well... after trying to get this to work for about 2 days now and posting help to the forum 1 hour ago... what happend? We found the solution!!!

01.public bool PrintDocumentToDefaultPrinter(string docPath)
02.       {
03.           bool result = false;
04. 
05.           try
06.           {
07.               Stream stream;
08.               RadPdfViewer pdfViewer;
09. 
10.               stream = File.OpenRead(docPath);
11. 
12.               pdfViewer = new RadPdfViewer();
13.               pdfViewer.DocumentLoaded += pdfViewer_DocumentLoaded;
14. 
15.               pdfViewer.LoadDocument(stream);
16. 
17.           }
18.           catch (Exception ex)
19.           {
20.               log.Fatal("PrintDocumentToDefaultPrinter::", ex);
21.           }
22. 
23.           return result;
24.       }
25. 
26.       void pdfViewer_DocumentLoaded(object sender, EventArgs e)
27.       {
28.           try
29.           {
30.               RadPdfViewerElement pdfViewerElement = sender as RadPdfViewerElement;
31. 
32.               if (pdfViewerElement != null)
33.               {
34.                   RadPrintDocument myDocumentToPrint = new RadPrintDocument();
35. 
36.                   myDocumentToPrint.AssociatedObject = pdfViewerElement;
37. 
38.                   myDocumentToPrint.DefaultPageSettings.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);
39. 
40.                   myDocumentToPrint.Print();
41. 
42.               }
43.           }
44.           catch (Exception ex)
45.           {
46.               log.Fatal("pdfViewer_DocumentLoaded::", ex);
47.               throw;
48.           }
49.       }

Well... that's all. 

I hope this will help others, too.

Greetz,
Gøran
0
George
Telerik team
answered on 21 May 2014, 07:35 AM
Hi Goran,

Thank you for your reply.

I can confirm that this is a correct way to access the settings of RadPrintDocument.

Do not hesitate to write back, should you have further questions.

Regards,
George
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
rosa
Top achievements
Rank 1
answered on 09 Dec 2016, 11:48 AM

Hi guys

I've used bellow code for setting paper size and margin for printing the content on radrichtexteditor, actually for this purpose i 've used Radprintdocument. But the margin dosent work

I will bee appreciated for hellping me about the set margin for printing

 

private void PrintA4_Click(object sender, EventArgs e)    

  {

            PaperSize ps = new PaperSize();            ps.RawKind = (int)PaperKind.A4;            radPrintDocument1.DefaultPageSettings.PaperSize = ps;            radPrintDocument1.DefaultPageSettings.Landscape = false;            //radPrintDocument1.DefaultPageSettings.Margins = new System.Drawing.Printing.Margins(10, 10, 10, 10);            radPrintDocument1.Margins.Left = 0;            radPrintDocument1.Margins.Top = 0;            radPrintDocument1.Print();                     }

0
Hristo
Telerik team
answered on 12 Dec 2016, 12:02 PM
Hello Rosa,

Thank you for writing.

In order to change the margins of a printed document from RadRichTextEditor, you need to set them on the loaded document. The behavior is similar to the one in Word. While investigating the described scenario I managed to isolate an issue. The incorrect behavior is related to the editor not applying the margins set to the RadPrintDocument instance.

I have logged the issue in our feedback portal. I have also added a vote for it on your behalf, here: FIX. RadRichTextEditor - the printing engine does not respect the margins set on the RadPrintDocument. You can additionally subscribe to the item and be updated with all of its status changes. I have also updated your Telerik points.

Until we permanently resolve the issue you would need to apply the margins on the document loaded in the editor. Please check my code snippet below: 
private void radButton1_Click(object sender, EventArgs e)
{
    RadPrintDocument doc = new RadPrintDocument();
    this.radRichTextEditor1.Document.SectionDefaultPageMargin = new Telerik.WinForms.Documents.Layout.Padding(0, 0, 10, 10);
  
    doc.AssociatedObject = this.radRichTextEditor1;
    RadPrintPreviewDialog dialog = new RadPrintPreviewDialog();
    dialog.Document = doc;
    dialog.ShowDialog();
}

I hope this helps. Should you have further questions please do not hesitate to write back.

Regards,
Hristo
Telerik by Progress
Telerik UI for WinForms is ready for Visual Studio 2017 RC! Learn more.
Tags
PdfViewer and PdfViewerNavigator
Asked by
Jeff
Top achievements
Rank 1
Answers by
Peter
Telerik team
Jeff
Top achievements
Rank 1
willi
Top achievements
Rank 1
George
Telerik team
Gøran
Top achievements
Rank 2
rosa
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or