Printing a Dialog as PDF


This example shows how to accept user input into a dialog component and then print a PDF version of the resulting document.

The Printing a Dialog as PDF topic describes a technique available to Alpha Anywhere database users.

Creating the Dialog 

  1. Create a new dialog web component based on the AlphaSports database.

  2. Display the Form > Controls page.

  3. Add the "Firstname", "Lastname", "Company", and "Bill_City" fields to the dialog as textboxes.

  4. Add the "Bill_State_Region" field to the dialog as a drop down listbox.

  5. Select the "Bill_State_Region" control and click the in the DropDownBox Properties > Choices field to display the Define Choices dialog.

    • 1. Select "Dynamic" in the Define Choices > List Type list.

    • 2. Select "Variable" in the Data Source > Data source type list.

    • 3. Enter "session.states" in the Data Source > Variable name field.

    • 4. Click OK.

  6. Set the Row Properties > Hide row selection to "True" for the "Firstname", "Lastname", "Bill_City", and "Bill_State_Region" controls.

  7. Set the Textbox Properties > Size selection to 10 for the "Firstname" control, 10 for the "Lastname" control, and 15 for the "Bill_City" control.

  8. Select the "Company" control.

    • 1. Set the Row Properties > Freeform layout selection to "True" for the "Company".

    • 2. Click the in the Row Properties > Freeform template field to display the Freeform Column Layout dialog.

    • 3. Enter the following HTML code and click OK.

      This is to certify that {Firstname} {Lastname} (First Name, Last Name) of {Company} (Company) located in {City} (City), {State} (State) is a customer in good standing with AlphaSports on {Today}.
    • 4. Change the Row Properties > Row label field to AlphaSports Customer Certificate.

    • 5. Change the Row Properties > Cell in line style field to vertical-align: top;.

    • 6. Change the Row Properties > Row label in line style field to font-family: Verdana; font-size: 12pt;.

  9. Display the Form > Properties page.

  10. Click the in the Server Events > Declarations field to display the Form Events dialog.

  11. Enter the following Xbasic code to create the session.states variable that populates the "bill_state_region" drop down list:

    dim session.states as C
  12. Select the "Initialize" event from the Event list.

  13. Enter the following Xbasic code to assign data to the session.states variable and set a default value for the "Today" control.

    session.states = crlf()+ cstates("a" + crlf())
    CurrentForm.Controls.Today = date()
  14. Select the "AfterValidate" event from the Event list.

  15. Enter the following Xbasic script. This script saves the values in the dialog controls to the customer table. It then reads the customer_id value of this new record and uses that value to filter the LAYOUT.SAVEAS() function. This function uses the Certificate report of the customer table to create a PDF version of the dialog. This script runs when you click the Submit button.

    dim tbl as P
    dim id as C
    tbl ="PathAlias.ADB_Path\customer")
    tbl.enter_begin(.t.) = company
    tbl.firstname = firstname
    tbl.lastname = lastname
    tbl.bill_city = city
    tbl.bill_state_region = state
    id = tbl.customer_id
    Report.saveas("[email protected]_Path\customer.ddd", "pdf", "Customer_ID = " + s_quote(id), "", session.session_folder + "\certificate.pdf", .f.)
    response.redirect(session.session_url + "certificate.pdf?" + time("hms03"))
  16. Save the dialog as "AlphaSports_Customer". The dialog component should look something like the following.

  17. Close the Dialog Builder.

  18. Place the dialog component on a A5W page named "AlphaSports_Customer".

Creating the Certificate Report 

  1. Display the Reports tab of the Control Panel.

  2. Click New, select "customer" in the Data Source list, select Start from a blank report, and click OK.

  3. Draw a RTF object on the Detail section of the new report. Create content that looks like the following. For more information about working with RTF objects on reports, see Working with Rich Text Fields and Working with Conditional Rich Text Fields.

  4. Save the new report as "Certificate".

After publishing the page, entering data, and clicking submit. You should see something like the following in Adobe Acrobat.

If you have a problem viewing the PDF file, make sure that you have installed Adobe Acrobat and have associated it with the PDF file type.