Please enable JavaScript to view this site.

Navigation: Advanced topics > Programming topics > JavaScript API > AJAX helper object > Methods

ajax.addPDF

Scroll Prev Next More

Description

The ajax.addPDF method creates a PDF file and sends it to the Server event. The file can be emailed, saved to the disk or into the database.

Syntax

ajax.addPDF( name, settings, callback )

Arguments

name {string}

the name of the variable in which the PDF file contents are stored in the params server array, so that it is available to use in the Server event.

settings {object}

the PDF settings. See PDF Parameters for details. Use an empty object {} for default settings.

callback

defines callback function to call  after PDF file is created. You should call either the submit() or dialog() function in the callback to start the Server part of the event.

Note: the submit() function is applied to start the Server part of the event when the basic routine cannot be used. It is necessary, when the Client Before event runs an asynchronous task, e.g., creating a PDF.

See submit() to learn more.

Return value

No return value.

Examples

Example 1

This example shows the use of the name argument. In this example we save PDF file as file.pdf.

 

Client before:

 

ajax.addPDF( 'pdf', {} );
return false;

 

Note: when using the addPDF fucntion in the Client Before event, you should always return false. Just add the following line to the end of your event code:

return false;

 

Server:

 

MVCFunctions.runner_save_file((XVar)(filename), (XVar)(parameters["pdf"]));

 

Note: see Tri-part events to learn more about Client before and Server events.

Example 2

This example shows the use of the callback argument in the ClientBefore event.

 

ajax.addPDF( "pdf", {}, function() {
  alert('PDF file was created');
  ajax.submit();
});
return false;

See also:

Example: How to create a PDF and save it to the disk

Example: How to save the View page as PDF from the List page

Example: How to email the current page as PDF

Example: How to email selected records as separate PDF files

Tri-part events

About Dialog API

About AJAX helper object

About PDF API