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

Printing generated PDF

3 Answers 492 Views
Drawing API
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 28 Jan 2017, 06:57 AM

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

3 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 31 Jan 2017, 04:56 PM

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.
0
James
Top achievements
Rank 1
answered on 01 Feb 2017, 10:26 AM

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

0
Marin Bratanov
Telerik team
answered on 01 Feb 2017, 02:26 PM

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.
Tags
Drawing API
Asked by
James
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
James
Top achievements
Rank 1
Share this question
or