Programatic Printing Wrong Size

10 posts, 0 answers
  1. Jeff
    Jeff avatar
    48 posts
    Member since:
    Apr 2012

    Posted 23 Jun 2013 Link to this post

    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?
  2. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 27 Jun 2013 Link to this post

    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 >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Jeff
    Jeff avatar
    48 posts
    Member since:
    Apr 2012

    Posted 02 Jul 2013 Link to this post

    Thank you for the reply.Setting the margins on the RadPrintDocument works perfectly.
  5. willi
    willi avatar
    22 posts
    Member since:
    Oct 2006

    Posted 30 Apr 2014 in reply to Jeff Link to this post

    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

  6. George
    Admin
    George avatar
    500 posts

    Posted 01 May 2014 Link to this post

    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.
     
  7. willi
    willi avatar
    22 posts
    Member since:
    Oct 2006

    Posted 06 May 2014 in reply to George Link to this post

    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
     

    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
  • George
    Admin
    George avatar
    500 posts

    Posted 09 May 2014 Link to this post

    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.
     
  • Gøran
    Gøran avatar
    3 posts
    Member since:
    Jun 2011

    Posted 16 May 2014 Link to this post

    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
  • Gøran
    Gøran avatar
    3 posts
    Member since:
    Jun 2011

    Posted 16 May 2014 Link to this post

    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
  • George
    Admin
    George avatar
    500 posts

    Posted 21 May 2014 Link to this post

    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.
     
  • Back to Top
    UI for WinForms is Visual Studio 2017 Ready