• Publicity: Public Only All

pdf-procs.tcl

Functions for handling Template-documents

Location:
packages/acs-tcl/tcl/pdf-procs.tcl
Created:
2005-07-07
Author:
Christian Langmann <C_Langmann@gmx.de>

Procedures in this file

Detailed information

text_templates::create_pdf_content (public)

 text_templates::create_pdf_content -template_id template_id \
    -set_var_call set_var_call

Create the pdf content from a template

Switches:
-template_id
(required)
The template to use for the preview. It is assumed that the template_id is the same as the revision_id to be used for the template.
-set_var_call
(required)
procedure-name which sets the variables used
Returns:
the pdf-file-name
Author:
Christian Langmann <C_Langmann@gmx.de>
Created:
2005-07-07

Partial Call Graph (max 5 caller/called nodes):
%3 ad_file ad_file (public) ad_tmpdir ad_tmpdir (public) parameter::get parameter::get (public) text_templates::create_html_content text_templates::create_html_content (private) text_templates::create_pdf_content text_templates::create_pdf_content text_templates::create_pdf_content->ad_file text_templates::create_pdf_content->ad_tmpdir text_templates::create_pdf_content->parameter::get text_templates::create_pdf_content->text_templates::create_html_content

Testcases:
No testcase defined.

text_templates::create_pdf_from_html (public)

 text_templates::create_pdf_from_html -html_content html_content

The HTML Content is transformed into a PDF file

Switches:
-html_content
(required)
HTML Content that is transformed into PDF
Returns:
filename of the pdf file

Partial Call Graph (max 5 caller/called nodes):
%3 ad_file ad_file (public) ad_tmpdir ad_tmpdir (public) parameter::get parameter::get (public) text_templates::create_pdf_from_html text_templates::create_pdf_from_html text_templates::create_pdf_from_html->ad_file text_templates::create_pdf_from_html->ad_tmpdir text_templates::create_pdf_from_html->parameter::get

Testcases:
No testcase defined.

text_templates::store_final_document (public)

 text_templates::store_final_document -pdf_file pdf_file \
    -folder_id folder_id -title title -description description

The document is stored in the given folder.

Switches:
-pdf_file
(required)
the pdf-file to save
-folder_id
(required)
the folder the document is stored in
-title
(required)
Title or name of the document
-description
(required)
Description of the document
Returns:
item_id
Author:
Christian Langmann <C_Langmann@gmx.de>
Created:
2005-07-07

Partial Call Graph (max 5 caller/called nodes):
%3 ad_file ad_file (public) cr_import_content cr_import_content (public) text_templates::store_final_document text_templates::store_final_document text_templates::store_final_document->ad_file text_templates::store_final_document->cr_import_content

Testcases:
No testcase defined.
[ hide source ] | [ make this the default ]

Content File Source

# packages/acs-tcl/tcl/pdf-procs.tcl

ad_library {

    Functions for handling Template-documents

    @author Christian Langmann (C_Langmann@gmx.de)
    @creation-date 2005-07-07
}

namespace eval text_templates {}

d_proc -public text_templates::create_pdf_content {
    {-template_id:required}
    {-set_var_call:required}
} {

    Create the pdf content from a template

    @author Christian Langmann (C_Langmann@gmx.de)
    @creation-date 2005-07-07

    @param template_id The template to use for the preview. It is \
    assumed that the template_id is the same as the revision_id to \
    be used for the template.

    @param set_var_call procedure-name which sets the variables used

    @return the pdf-file-name
} {
    
    # create html.file
    set html_content [create_html_content -template_id $template_id -set_var_call $set_var_call]
    set fp [file tempfile tmp_html_filename [ad_tmpdir]/pdf-XXXXXX.html]
    puts $fp $html_content
    close $fp

    # create pdf-file
    set tmp_pdf_filename "${tmp_html_filename}.pdf"
    set htmldoc_bin [parameter::get -parameter "HtmlDocBin" -default "/usr/bin/htmldoc"]
    if {[catch {exec $htmldoc_bin --webpage --quiet -t pdf -f $tmp_pdf_filename $tmp_html_filename} err]} {
        ns_log Error "Error during conversion from html to pdf: $err"
    }
    file delete -- $tmp_html_filename

    if {[ad_file exists $tmp_pdf_filename]} {
        return $tmp_pdf_filename
    } else {
        return ""
    }
}


d_proc -public text_templates::create_pdf_from_html {
    {-html_content:required}
} {
    The HTML Content is transformed into a PDF file

    @param html_content HTML Content that is transformed into PDF
    @return filename of the pdf file
} {
    set fp [file tempfile tmp_html_filename [ad_tmpdir]/pdf-XXXXXX.html]
    puts $fp $html_content
    close $fp

    # create pdf-file
    set tmp_pdf_filename "${tmp_html_filename}.pdf"
    set htmldoc_bin [parameter::get -parameter "HtmlDocBin" -default "/usr/bin/htmldoc"]
    if {[catch {exec $htmldoc_bin --webpage --quiet -t pdf -f $tmp_pdf_filename $tmp_html_filename} err]} {
        ns_log Error "Error during conversion from html to pdf: $err"
    }
    if {[ad_file exists $tmp_pdf_filename]} {
        return $tmp_pdf_filename
    } else {
        return ""
    }
}

d_proc -public text_templates::store_final_document {
    {-pdf_file:required}
    {-folder_id:required}
    {-title:required}
    {-description:required}
} {
    The document is stored in the given folder.

    @author Christian Langmann (C_Langmann@gmx.de)
    @creation-date 2005-07-07
    @param pdf_file the pdf-file to save
    @param folder_id the folder the document is stored in
    @param title Title or name of the document
    @param description Description of the document
    @return item_id

} {
    set file_size [ad_file size $pdf_file]
    set item_id [cr_import_content -title $title -description $description $folder_id $pdf_file $file_size application/pdf $title]
    return $item_id
}

d_proc -private text_templates::create_html_content {
    {-template_id ""}
    {-set_var_call:required}
    {-filename:required}
} {

    Create the filled out template as html

    @author Christian Langmann (C_Langmann@gmx.de)
    @creation-date 2005-07-07

    @param template_id The template to use for the preview. It is assumed that the template_id is the same as the revision_id to be used for the template.
    @param set_var_call procedure-name which sets the variables used
} {

    {*}$set_var_call

    # retrieve template and write to tmpfile
    # set content [content::get_content_value $template_id]
    set file [open $filename]
    fconfigure $file -translation binary
    set content [read $file]

    # parse template and replace placeholders
    eval [template::adp_compile -string $content]
    set final_content $__adp_output

    return $final_content
}

# Local variables:
#    mode: tcl
#    tcl-indent-level: 4
#    indent-tabs-mode: nil
# End: