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
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
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 >>


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
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

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
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
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

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

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
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

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(); }
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