46.7 UPLOAD_TEMPLATE Function

This function uploads a template to OCI Object Storage and returns its corresponding ID.

Can only be used when Oracle Document Generator Pre-built Function is configured as print server in the instance.

To be used in combination with the APEX_PRINT.GENERATE_DOCUMENT and REMOVE_TEMPLATE Procedure APIs to generate documents using the same custom template, which is not stored as a report layout.

Syntax

APEX_PRINT.UPLOAD_TEMPLATE (
    p_template      IN BLOB,
    p_template_type IN t_template_type  DEFAULT c_template_docx )
    RETURN NUMBER;

Parameters

Parameter Description
p_template Content of the template.
p_template_type Type of the template.

Returns

A number containing the unique ID to reference the template in future calls.

Example

The following example uploads the template to Object Storage that was uploaded in Oracle APEX by an end user, generates a PDF document, and removes the template afterwards.

DECLARE
    l_template       blob;
    l_template_id    number;
    l_data           sys.json_object_t := sys.json_object_t();
    l_document       blob;
BEGIN

    SELECT blob_content
      INTO l_template
      FROM apex_application_temp_files
     WHERE name = :P1_TEMPLATE;

    l_template_id := apex_print.upload_template( p_template => l_template );

    l_data.put( 'name', 'Scott' );

    l_document := apex_print.generate_document(
                      p_data         => l_data.to_clob,
                      p_template_id  => l_template_id );

    apex_print.remove_template( p_template_id => l_template_id );

EXCEPTION
    WHEN others THEN
        apex_print.remove_template( p_template_id => l_template_id );
END;