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

Remove all margins when printing

11 Answers 765 Views
PdfViewer and PdfViewerNavigator
This is a migrated thread and some comments may be shown as answers.
Stefan
Top achievements
Rank 1
Iron
Iron
Iron
Stefan asked on 02 Sep 2019, 06:58 AM

Hi,

we are printing out a PDF through PdfViewer.Print() utilizing a RadPrintDocument for removing the margins (new Margins(0,0,0,0)).

Unfortunately there still seem to be (very small) margins applied during print-out, because when printing the document with an external tool (e.g. Adobe Acrobat Reader) these document borders are much smaller.

Is there anything else we have to consider when printing?

11 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 02 Sep 2019, 10:34 AM

Hi Stefan,

You need to set the header/footer size as well: 

private void RadButton1_Click(object sender, EventArgs e)
{
    RadPrintDocument document = new RadPrintDocument();
    document.Landscape = false;
    
     
    document.DefaultPageSettings.PrinterSettings.Copies = 1;
    document.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);

    document.HeaderHeight = 0;
    document.FooterHeight = 0;
    document.AssociatedObject = radPdfViewer1.PdfViewerElement;

    document.Print();

}

In addition, I am testing this by manually painting in a test document. Here is how I am creating it:

RadFixedDocument document = new RadFixedDocument();
RadFixedPage page = document.Pages.AddPage();
page.Size = new System.Windows.Size(850, 1100);

FixedContentEditor editor = new FixedContentEditor(page);
editor.DrawText("Hello RadPdfProcessing!");
editor.DrawEllipse(new System.Windows.Point(425, 550), 425, 550);

PdfFormatProvider provider = new PdfFormatProvider();

using (Stream output = File.OpenWrite(@"D:\Hello.pdf"))
{
    provider.Export(document, output);
}
radPdfViewer1.LoadDocument(@"D:\Hello.pdf");

I hope this helps. Should you have any other questions, do not hesitate to ask.

Regards,
Dimitar
Progress Telerik

Get quickly onboard and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Stefan
Top achievements
Rank 1
Iron
Iron
Iron
answered on 02 Sep 2019, 12:01 PM

Hi Dimitar,

thank you for the quick answer. Unfortunately this did not help. Could it be some kind of zooming issue/feature?

I found that if I compare the print-out result with what other PDF-Viewers produce, for example Chrome and Microsoft Edge, that Edge shows a margin akin to the RadPdfViewer, while Chrome's has a smaller margin.

Is there any parameter I might be able to adjust, to come closer to the Chrome result?

0
Dimitar
Telerik team
answered on 02 Sep 2019, 02:26 PM

Hi Stefan,

Can you send me the document so I can test this locally and see if there is a solution for this? What I am thinking is that the page aspect ration can be different from the paper one which can cause such an effect. 

I am looking forward to your reply.

Regards,
Dimitar
Progress Telerik

Get quickly onboard and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Stefan
Top achievements
Rank 1
Iron
Iron
Iron
answered on 03 Sep 2019, 06:28 AM

Hi Dimitar,

sure, I attached the document.

0
Stefan
Top achievements
Rank 1
Iron
Iron
Iron
answered on 03 Sep 2019, 06:31 AM
It looks like pdf files are not allowed as attachments... How can I send you the document?
0
Stefan
Top achievements
Rank 1
Iron
Iron
Iron
answered on 03 Sep 2019, 07:54 AM
0
Dimitar
Telerik team
answered on 03 Sep 2019, 11:18 AM

Hello Stefan,

It seems that there is an issue with our implementation and this is why there is no how to remove the Margin in this case. I have logged this issue on our Feedback Portal. You can track its progress, subscribe to status changes and add your comment to it here. I have updated your Telerik Points as well.

Unfortunately, I cannot suggest a workaround for the issue.

Should you have any other questions, do not hesitate to ask.

Regards,
Dimitar
Progress Telerik

Get quickly onboard and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Stefan
Top achievements
Rank 1
Iron
Iron
Iron
answered on 03 Sep 2019, 01:14 PM

Hi Dimitar,

thank you for the quick help and information. We'll wait and see what happens. :)

0
Dimitar
Telerik team
answered on 18 Oct 2019, 12:39 PM

Hi Stefan,

This feature is not supported in PDFViewer. To achieve this the user should use PDF Processing in order to load this document and edit it. For example to set CropBox.

Regards,
Dimitar
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Stefan
Top achievements
Rank 1
Iron
Iron
Iron
answered on 21 Oct 2019, 06:40 AM

Hello Dimitar,

thank you for the Information. Is there an example on the Telerik website for this, setting the margins and printing, using the PDF Processing? For us the advantage for using the PdfViewer has been that it is so easy to use.

Kind regards.

0
Georgi
Telerik team
answered on 24 Oct 2019, 08:26 AM

Hello Stefan,

In order to print the document with paper size applied with the imported page size, you may set the PaperSize property of the RadPrintDocument instance. For example:

RadPrintDocument document = new RadPrintDocument();

RadFixedPage page = this.pdfViewer.PdfViewerElement.CurrentPage;
int width = (int)page.Size.Width;
int height = (int)page.Size.Height;
bool isLendscape = width < height;
document.Landscape = isLendscape;

document.DefaultPageSettings.PrinterSettings.Copies = 1;
document.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);

document.HeaderHeight = 0;
document.FooterHeight = 0;
document.AssociatedObject = this.pdfViewer.PdfViewerElement;

if (isLendscape)
{
    document.PaperSize = new PaperSize("Custom", width, height);
}
else
{
    document.PaperSize = new PaperSize("Custom", height, width);
}

this.pdfViewer.Print(true, document);

However, if this doesn't provide you with a solution you may use the PdfProcessing library as Dimitar has mentioned, in order to scale the page content to fit with a different scale factor in the document page. I will briefly describe the steps:

 - import the document using the PdfFormatProvider class
 - iterate the RadFixedPage content and add it to a Form object
 - create a new RadFixedDocument instance and add the Form object as page content
 - apply translate and scale transformations of the Form position
 - export the document using the PdfFormatProvider class

PdfFormatProvider provider = new PdfFormatProvider();
RadFixedDocument document = provider.Import(memory);

RadFixedDocument modifiedDocument = new RadFixedDocument();

foreach (var page in document.Pages)
{
    RadFixedPage modifiedPage = modifiedDocument.Pages.AddPage();
    modifiedPage.Size = page.Size;

    List<ContentElementBase> contentElements = new List<ContentElementBase>();
    foreach (var contentElement in page.Content)
    {
        contentElements.Add(contentElement);
    }

    // Clear the content from the original page so the content elements will have only one parent.
    page.Content.Clear();

    FormSource formSource = new FormSource
    {
        Size = page.Size
    };

    foreach (var contentElement in contentElements)
    {
        formSource.Content.Add(contentElement);
    }

    Form form = modifiedPage.Content.AddForm(formSource);
    form.Width = page.Size.Width;
    form.Height = page.Size.Height;

    form.Position.Translate(-25, -25);
    form.Position.Scale(1.05, 1.05);
}

byte[] data = provider.Export(modifiedDocument);

After the modified document is exported, you can load it in RadPdfViewer for printing:

this.pdfViewer.LoadDocument(new MemoryStream(data));

I hope this helps.

Regards,
Georgi
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
PdfViewer and PdfViewerNavigator
Asked by
Stefan
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Dimitar
Telerik team
Stefan
Top achievements
Rank 1
Iron
Iron
Iron
Dimitar
Telerik team
Georgi
Telerik team
Share this question
or