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

How To Embed Javascript in PDF

9 Answers 301 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
briankb
Top achievements
Rank 2
briankb asked on 02 May 2008, 07:39 AM
I just started playing with Telerik Reporting. I'm hoping to migrate a simple single page report I currently do in .net using PDFGenerator.

With PDFGenerator you can embed javascript. In my case I add the following line:
MyDocument.JavaScripts.Add(New DocumentJavaScript("print", "this.print({bUI: false, bSilent: true, bShrinkToFit: true});"))

Which results in the PDF file going straight to the printer.

I created the following code in a new .aspx file using sample code I found in the docs.

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 
        Dim report As New Telerik.Reporting.Report() 
        Dim detail As New Telerik.Reporting.DetailSection() 
        Dim textBox2 As New Telerik.Reporting.TextBox() 
        textBox2.Location = New Telerik.Reporting.Drawing.PointU(New Telerik.Reporting.Drawing.Unit(0, Telerik.Reporting.Drawing.UnitType.Inch), New Telerik.Reporting.Drawing.Unit(0, Telerik.Reporting.Drawing.UnitType.Inch)) 
        textBox2.Value = "Hello World!" 
        textBox2.Location = New Telerik.Reporting.Drawing.PointU(New Telerik.Reporting.Drawing.Unit(1.25, Telerik.Reporting.Drawing.UnitType.Inch), New Telerik.Reporting.Drawing.Unit(0, Telerik.Reporting.Drawing.UnitType.Inch)) 
        textBox2.Size = New Telerik.Reporting.Drawing.SizeU(New Telerik.Reporting.Drawing.Unit(4.75, Telerik.Reporting.Drawing.UnitType.Inch), New Telerik.Reporting.Drawing.Unit(0.25, Telerik.Reporting.Drawing.UnitType.Inch)) 
        detail.Items.AddRange(New Telerik.Reporting.ReportItemBase() {textBox2}) 
        detail.Height = New Telerik.Reporting.Drawing.Unit(0.3, Telerik.Reporting.Drawing.UnitType.Inch) 
        report.Items.Add(DirectCast(detail, Telerik.Reporting.ReportItemBase)) 
        ExportToPDF("Test", report) 
    End Sub 
 
    Sub ExportToPDF(ByVal reportName As String, ByVal reportToExport As Telerik.Reporting.Report) 
        Dim mimeType As StringString = String.Empty 
        Dim ext As StringString = String.Empty 
        Dim encoding As EncodingEncoding = Encoding.[Default] 
        Dim reportBytes As Byte() = ReportProcessor.Render("PDF", reportToExport, Nothing, mimeType, ext, encoding) 
        Dim fileName As String = reportName + ".pdf" 
        Response.Clear() 
        Response.ContentType = mimeType 
        Response.Cache.SetCacheability(HttpCacheability.[Private]) 
        Response.Expires = -1 
        Response.Buffer = False 
        Response.AddHeader("Content-Disposition", String.Format("{0};FileName=""{1}""", "attachment", fileName)) 
        Response.OutputStream.Write(reportBytes, 0, reportBytes.Length) 
        Response.[End]() 
    End Sub 

This code generates a PDF directly just like my PDFGenerator code.

How do I embed javascript directly in the PDF generated by the Telerik Reporting control?



9 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 02 May 2008, 08:16 AM
Hello Briankb,

Thank you for contacting Telerik Support.

Currently there is no way to inject JavaScript in the generated PDF file. We will log that as a feature request and if there is enough interest we will implement it for a future release. Thanks for the great idea.

All the best,
Ross
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
briankb
Top achievements
Rank 2
answered on 02 May 2008, 08:25 AM
Thanks for the quick reply.

I hope you will add it soon. Or if you don't want to open it up to javascript maybe make a property you can set true/false in the PDF generation where the javascript I mentioned earlier is added which pushes the PDF directly to the default printer or at least the printer dialog box.
0
Chavdar
Telerik team
answered on 02 May 2008, 11:32 AM
Hi Briankb,

You can start the immediate print after sending the pdf document by adding the following device information:

    Dim deviceInfo As New Hashtable()
    deviceInfo.Add("ImmediatePrint", True)

    ReportProcessor.Render("PDF", reportToExport, deviceInfo, mimeType, ext, encoding) 

However, it will first show the Print dialog before printing. Hope this helps.

Regards,
Chavdar
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Jun
Top achievements
Rank 1
answered on 11 May 2008, 02:41 AM
How can you hide or disable the print button in the PDF reader? Is this can be done by injecting javascript? Or one of you suggestions like device setting?

Bembol
0
Chavdar
Telerik team
answered on 12 May 2008, 01:45 PM
Hi bembol,

At this time you cannot hide or disable the Print button in the reader. We are currently researching whether this is possible or not. If possible we will include the requested functionality for the service pack release in a couple of weeks.

All the best,
Chavdar
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Rakesh
Top achievements
Rank 1
answered on 15 Jul 2008, 02:37 PM
Hi,
I don't know how Chavdar has written that you can't disable the printing options. You can disable both printing as wel as copying options too, so that the document can neither be copied or printed. This can be achieved while creating the document itself. I use openOffice for creating pdf documents. Here open any word document and then
File>Export as PDF> give file name abc.pdf >save
pdfOptions page pops up : Here  under the security options check the  Restrict the Permissions then click set permission Password and after setting the password choose the permissions.

0
Steve
Telerik team
answered on 15 Jul 2008, 03:40 PM
Hello Rakesh,

We believe that you are talking about something else - generating the pdfs yourself with other 3rd party software. While the conversation here is about the auto generated pdf files by our Reporting tool. Our developers have already implemented a way to inject javascript in the generated pdf - through the javascript attribute. More info is available in this help topic.

Kind regards,
Steve
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
sundarabalaji
Top achievements
Rank 1
answered on 01 Apr 2015, 05:56 AM
hi bembol,

Can u send example code for Render Concept
0
KS
Top achievements
Rank 1
answered on 02 Apr 2015, 06:18 AM
Tags
General Discussions
Asked by
briankb
Top achievements
Rank 2
Answers by
Rossen Hristov
Telerik team
briankb
Top achievements
Rank 2
Chavdar
Telerik team
Jun
Top achievements
Rank 1
Rakesh
Top achievements
Rank 1
Steve
Telerik team
sundarabalaji
Top achievements
Rank 1
KS
Top achievements
Rank 1
Share this question
or