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

No option to print PDF to scale? PDF is shrunk when printed.

3 Answers 711 Views
PdfViewer and PdfViewerNavigator
This is a migrated thread and some comments may be shown as answers.
Kerry
Top achievements
Rank 1
Kerry asked on 22 Mar 2019, 05:38 PM

It is VERY important to us that PDF documents print to scale.I have read through the posts here and am still having the problem.

I am printing to a printer that has 0.16 in margins all around. The page size is 8.5 x 11. The drawing border is 8 x 10.5 (which would allow margins up to 0.25")

There are 2 images attached. Each shows an architect scale against the print out. One for Adobe, one for RadPrintDocument.
The Adobe prints to scale (the 120" wall at 1/2" scale shows 10 (10 feet).  The RadPrintDocument is short as it is automatically scaling the PDF file down.
Also attached is the PDF file I am using for this example.  Correction: PDF not attached as not allowed to attach to forum posts.

How can I stop that scaling please and always print to 100% scale please?

The code we are using:

RadPdfViewer rViewer = new RadPdfViewer();
rViewer.DocumentLoaded += RViewer_DocumentLoaded;
rViewer.LoadDocument(@fileLocation + fileName);
rViewer.LoadElementTree();
Application.DoEvents();

 

 private static void RViewer_DocumentLoaded(object sender, EventArgs e)
      {
         RadPrintDocument document = new RadPrintDocument();

         document.Landscape = true;
         document.DefaultPageSettings.PrinterSettings.Copies = 1;
         document.DefaultPageSettings.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);
         document.AssociatedObject = (sender as RadPdfViewerElement);
        
         
         document.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);
         document.DefaultPageSettings.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);
         document.OriginAtMargins = true;
         document.HeaderHeight = 0;
         document.FooterHeight = 0;
         document.Print();
      }

Thank you!!!

 

 

 

3 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 25 Mar 2019, 11:15 AM
Hi Kerry,

It appears that this question duplicates your other ticket: 1401884 - How can I print PDF at 100% scale please? You can check my answer there. Please also have in mind that sometimes posting the same question again may slow down our response. Thank you for understanding.

Regards,
Hristo
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.
Scott
Top achievements
Rank 1
commented on 01 Nov 2022, 11:16 PM

Hristo,
I am facing a similar problem with the latest versions, 2022.3.906, and the sample solution provided here.  All the documents I print end up scaled down.  It also appears that the ticked mentioned above, 1401884, is no longer around and/or is not accessible anymore.

Please advise

Thanks,
- Scott

Dinko | Tech Support Engineer
Telerik team
commented on 02 Nov 2022, 01:16 PM

Hello Scott,

The other ticket is private and that is why is not available in the forum. The reply from a colleague is shared in Kerry's second post. In a few words, we have a Feature Request in our Feedback Portal to provide functionality in the RadPdfViewer to print the document in its actual size. 

What you could try is to zoom the control to 100% before printing the document. You can also use the PrintScalePageToPaperSize property to scale the page when printing to fit the paper size without keeping the aspect ratio. Alternatively, you can try exporting the page in the control to an image and later print the exported image: Export to Image.

Scott
Top achievements
Rank 1
commented on 02 Nov 2022, 03:58 PM | edited

Dinko,
That makes sense about the ticket, thank you for the clarification.

I am unable to export the page(s) as images to print later due to the requirements of the project.  I was also not able to figure out how to set the zoom control to 100%.  In my project there isn't a UI so maybe that option isn't available to me.  I did however try setting the PrintScalePageToPaperSize but it did not seem to have any effect.  I've pasted my code below as well as included a zip with two PDFs, both the expected result and the actual result.

public bool PrintMe(string filePath, string printerName)
{
    var radPdfViewer = new RadPdfViewer();
    radPdfViewer.DocumentLoaded += (sender, e) => Document_Loaded(sender, e, Path.GetFileName(filePath), printerName);
    radPdfViewer.PrintScalePageToPaperSize = true;

    radPdfViewer.LoadDocument(filePath);
    radPdfViewer.LoadElementTree();

    System.Windows.Forms.Application.DoEvents();

    return true;
}

private static void Document_Loaded(object sender, EventArgs e, string documentName, string printerName)
{
    using (var document = new RadPrintDocument { Landscape = false, DocumentName = documentName })
    {
        var radPdfViewerElement = (RadPdfViewerElement)sender;
        radPdfViewerElement.PrintScalePageToPaperSize = true;

        document.AssociatedObject = radPdfViewerElement;

        var settings = new PrinterSettings
        {
            PrinterName = printerName,
            Copies = 1,
            Duplex = Duplex.Simplex,
            PrintRange = PrintRange.AllPages
        };

        document.DefaultPageSettings = new PageSettings
        {
            PrinterSettings = settings
        };
        document.PrinterSettings = settings;

        document.Print();
    }
}

The project I am working in is .NET Framework 4.8, below are the Telerik packages that are also installed:

Please advise.

Thanks,
- Scott

Dinko | Tech Support Engineer
Telerik team
commented on 03 Nov 2022, 12:45 PM

The provided code snippet is greatly appreciated. 

I have tested your files by loading the Print_Test.pdf file and trying to print it. Indeed the document is scaled down. After checking the Document_Loaded event handler overring the default DefaultPageSettings and PrinterSettings properties lead to this scale. You can try the following code and let me know how it goes on your side.

public bool PrintMe(string filePath, string printerName)
{
    var radPdfViewer = new RadPdfViewer();
    radPdfViewer.DocumentLoaded += (sender, e) => Document_Loaded(sender, e, Path.GetFileName(filePath), printerName);
    radPdfViewer.PrintScalePageToPaperSize = true;
    radPdfViewer.LoadDocument(filePath);
    radPdfViewer.LoadElementTree();

    System.Windows.Forms.Application.DoEvents();

    return true;
}
private static void Document_Loaded(object sender, EventArgs e, string documentName, string printerName)
{
    using (var document = new RadPrintDocument { Landscape = false, DocumentName = documentName })
    {
        var radPdfViewerElement = (RadPdfViewerElement)sender;
        document.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);
        document.AssociatedObject = radPdfViewerElement;
        document.DefaultPageSettings.Landscape = false;
        // Uncomment this in your code
        //document.PrinterSettings.PrinterName = printerName;
        document.PrinterSettings.Copies = 1;
        document.PrinterSettings.Duplex  = Duplex.Simplex;
        document.PrinterSettings.PrintRange = PrintRange.AllPages;
        document.Print();
    }
}

Scott
Top achievements
Rank 1
commented on 03 Nov 2022, 04:57 PM

Dinko,
Thank you for this, unfortunately this didn't seem to resolve my issue.  However, I see in your sample that you've added the Margins property and set that to zero.  I ended up doing something very similar with also adding PrintScalePageToPaperSize and setting that to True.  These additions appear to have resolved my issue.

public bool Print(string filePath, string printerName)
{
    var radPdfViewer = new RadPdfViewer();
    radPdfViewer.DocumentLoaded += (sender, e) => Document_Loaded(sender, e, Path.GetFileName(filePath), printerName);
    radPdfViewer.PrintScalePageToPaperSize = true;

    radPdfViewer.LoadDocument(filePath);
    radPdfViewer.LoadElementTree();

    System.Windows.Forms.Application.DoEvents();

    return true;
}

private static void Document_Loaded(object sender, EventArgs e, string documentName, string printerName)
{
    using (var document = new RadPrintDocument { Landscape = false, DocumentName = documentName })
    {
        var radPdfViewerElement = (RadPdfViewerElement)sender;
        radPdfViewerElement.PrintScalePageToPaperSize = true;

        document.AssociatedObject = radPdfViewerElement;

        var settings = new PrinterSettings
        {
            PrinterName = printerName,
            Copies = 1,
            Duplex = Duplex.Simplex,
            PrintRange = PrintRange.AllPages
        };

        document.DefaultPageSettings = new PageSettings
        {
            PrinterSettings = settings,
            Margins = new Margins(0, 0, 0, 0)
        };
        document.PrinterSettings = settings;

        document.Print();
    }
}

Dinko | Tech Support Engineer
Telerik team
commented on 04 Nov 2022, 09:33 AM

I am happy to hear that the provided workaround work for you. If you have further questions arise, you can open a new ticket thread with your questions inside and we will be happy to help.
0
Kerry
Top achievements
Rank 1
answered on 26 Mar 2019, 02:43 PM
Sorry. I posted here first and then saw the sticky note that says support emails get a higher priority.

Thank you for the suggestions. I will try them out.I just wanted to make sure I was not missing a method or property that allowed me to print to scale. Hopefully that is added someday. Until then I will try your suggestions to print to image and then print the image. I will also see what I can do for the content creation to maybe "fudge" the data being printed to maybe compensate before the PDF is created. I am posting your response below hoping this may help others in the future.


We have a feature request to print the document in RadPdfViewer in its actual size: https://feedback.telerik.com/winforms/1372074-add-radpdfviewer-functionality-to-print-the-document-in-its-actual-size. I have already added a vote for the item on your behalf. 

Can you please try, zooming to control on 100% before printing the document. Setting the PrintScalePageToPaperSize property to true  could also help. Alternatively, you can try exporting the page in the control to an image and later print the exported image: https://docs.telerik.com/devtools/winforms/controls/pdfviewer/export-to-image.

I hope this will help. Let me know if you have other questions.
0
Hristo
Telerik team
answered on 27 Mar 2019, 08:45 AM
Hello Kerry,

Indeed the other question was posted in the ticketing system so thank you, for also updating the forum thread with my answer. I hope that you will manage to achieve the desired result.

Regards,
Hristo
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
Kerry
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Kerry
Top achievements
Rank 1
Share this question
or