Printing generated PDF

4 posts, 0 answers
  1. James
    James avatar
    6 posts
    Member since:
    Feb 2014

    Posted 28 Jan Link to this post

    Hi

    We  are creating  a pdf using the drawing api which creates a open / save / cancel dialog in the browser allowing the user to open the pdf in Acrobat and then print it. Some users (senior managers) are complaining that this multi stage process is too long (they are used to our windows client app that outputs directly to their local printer). Is there any way we can bypass the first dialog and automatically open the pdf in Acrobat are display the print dialog?

    I have see this: http://www.telerik.com/support/kb/reporting/details/print-a-report-directly-at-client-side-without-displaying-it-in-a-viewer

    but I don't really understand whether we can use any of it?

     

    Any help or suggestions would be gratefully received.

    Thanks

    James

  2. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3892 posts

    Posted 31 Jan Link to this post

    Hello James,

    If you want parts of your page printed directly, I strongly suggest you consider using @print media queries to hide the irrelevant bits and then simply call window.print() in the current page. With this you will let the browser print the best version of the page it can without passing it through an additional tool (PDF export).

    The KB article you have found pertains to Telerik Reporting, which is a server-side tool. The actual code is in the code-behind:

    this.print({bUI: true, bSilent: false, bShrinkToFit: true});

    which is added to the PDF generated by Telerik Reporting.

    Such a feature is not present in the Kendo Drawing API, the major reason being that its generates a base64 string that is passed through the browser FileAPI or a blob to generate a file. You can try adding a <script> block with this content at the end of the PDF, but I cannot guarantee it will work. The way the PDF is provided in both cases is extremely different:

    • with the KB and Telerik Reporting a file is streamed to a hidden iframe where the script may be executed, because the browser has already downloaded the file
    • with the Kendo Drawing API the PDF is generated with JavaScript and JavaScript cannot access the OS (including printers) because it is sandboxed by the browser


    Regards,

    Marin Bratanov
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. James
    James avatar
    6 posts
    Member since:
    Feb 2014

    Posted 01 Feb in reply to Marin Bratanov Link to this post

    Hi Marin

    Thanks for the reply  I thought that approach was not possible ..... just hoped that I could inject the pdf 'fileContents ' in the controller into the Telerik reporting structure and use that to print from !!!  

            public ActionResult ExportPdf(string contentType, string base64, string fileName)
            {
                var fileContents = Convert.FromBase64String(base64);
                return File(fileContents, contentType, fileName);
                
            }

     

    Now I think I will go down the route of having an option when creating the pdf to change in the MVC controller the 'content-disposition' header to inline and also set the proxy target to "_blank", hopefully that should enable the pdf to be opened so the user can just choose Print from there.... such an effort to save a couple of clicks!

    Cheers

    James

  4. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3892 posts

    Posted 01 Feb Link to this post

    Hello James,

    You can probably look into the Adobe API to add the script to the generated PDF before streaming it to the browser: http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/js_api_reference.pdf.

    The other option of using content-disposition may also work and I hope it will suffice your your use case.

    Regards,

    Marin Bratanov
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top