report.pdf

Revision

  $Revision:  $

Description

A component for generating MasonSQL reports in PDF or ODT format.

Arguments

  B<Argument Name>  | B<Default Value>              | B<Description>
  -------------------------------------------------------------------------------------------------
  $base             | $r->dir_config('DataBaseUrl') | The data directory.
  $report           | undef                         | The name of a new report file.
  $report_method    | undef                         | A report method (rep, pdf or odt).
  $report_file      | undef                         | A Reportman config filepath.
  $GROUP_ID         | undef                         | Identifier of a group of records to be printed
                    |                               | (see the report_id table).
  $report_ids       | undef                         | An array of records to be printed.
  $landscape        | undef                         | Deprecated.
  $orientation      | PORTRAIT                      | Deprecated.
  $path_pdf         | undef                         | If defined, determines ODT and PDF filepaths.
  $send_pdf         | 1                             | The report is transmitted with the Mason request object.
  $cups_printer     | undef                         | If defined, instead of sending the file with $m->out(),
                    |                               | send the file to the indicated Cups printer.

Component Body

The component is called from the dbms_library.comp from the PDF method.

The procedure to print the report document:

  1. If send_pdf is set, clear the Mason request buffer and set content_type to text/html.
  2. Compose the temporary filepaths of the PDF and ODT report files.
  3. Create a new report file using the utility determined by the report_method.
    a.
    When the report_method is rep, print the complete .pdf report with Report Manager using GROUP_ID.
    b.
    When the report_method is odt, print single .odt report with ODT Reportman.
    c.
    When the report_method is pdf, print the complete .pdf report with ODT Reportman using group_ids.
  4. Process newly created report file.
    a.
    If the PDF report file is present print it with PrintPdf().
    b.
    Otherwise if ODT report file is present print it with SendFile().

Once Block

SendFile()

Prints the new report file:

  1. Opens the new report file for reading.
  2. Depending on the Apache version sets the Cache-Control, Content-transfer-encodig and the Content-disposition Apache::Request attributes.
  3. Outputs the content of the report file to the HTML::Mason::Request buffer. Raises an error in case any undefined character was detected.
  4. Then flushes the HTML::Mason::Request buffer and deletes the report file after the file was read.

PrintPdf()

Prints the created report file and handles a printing errors:

  • If the PROTECT argument is defined, encrypts the content of the report file using the qpdf utility.
  • If the cups_printer is defined, prints the report file using the lp utility.
  • If the cups_printer is not defined prints the report file with default subroutine SendFile.

UpdateReportmanConfigFile()

The procedure to update Reportman's report configuration file:

  1. If the report configuration file is older than the database_directory/report_name.rep file it updates it with the content of the later file.
  2. During update it additionally updates the ADOConnectionString with the current Apache config settings.
  3. At the end updates the report_file's modification time.

Reportman()

Composes a command to be passed to the printreptopdf:

  1. Verifies the base directory.
  2. As a commandline options, appends all argument name=value pairs with an exception of the reserved arguments:

  report,
  base,
  path_pdf,
  send_pdf,
  cups_printer,
  PROTECT and
  GROUP_ID

Synopsis for printreptopdf:

  printreptopdf 2.9a
  Prints a report manager (.rep) file to a Adobe PDF file
  Usage: printreptopdf [Options] -stdin|reportfilename [outputfilename]
           -q        Quiet mode, don't show progress
           -from   n Prints report from page pnum
           -to     n Prints report to page pnum
           -copies n Prints pnum copies
           -u        Generate not compressed pdf
           -m        Generate Report Metafile Stream format
           -collate  Collate the copies
           -csv      Output to comma separated values
           -svg      Output to scalable vector graphics format
           -ctxt     Output to custom text
           -csvseparator     CSV output separator
           -paramPARAMNAME=paramvalue  Assign a value to a parameter
           -stdin    Read from standard input instead from a file
           -text     Generate text output with escape codes to print
           -textdriver driver Use the text driver for text output
           -oemconvert        Force recode to oem for text output
           -html     Generate Html output

OdtReport()

Composes a command for the script that creates the ODT report. The command is invoked with IPC::Run::run. The required arguments are appended to the command line in the arg_name:arg_value format. The required arguments are: report_name and odt_filepath. The rest of the arguments are appended at the end of the command line in the arg_name=arg_value format. The command output is logged and checked for errors.

PdfReport()

Composes a command for the script that creates the PDF report. The command is invoked with IPC::Run::run. The required arguments are appended to the command line in the arg_name:arg_value format. The required arguments are: report_name, odt_filepath and pdf_filepath. The rest of the arguments are appended at the end of the command line in the arg_name=arg_value format. The command output is logged and checked for errors.

CatPdfs()

Concatenate multiple PDFs into one PDF. The concatenation is made with pdftk executable, with the command:

  pdftk <filepath1> <filepath2> ... <filepathN> cat output <output_filepath>

UnlinkTmpReports()

Unlink temporary .pdf and .odt files.

RunCmd()

Run command. Print the command output to the debug log. In case an error is detected, pass on the error message and die.

AddArgs()

Appends all arguments to the command line with exception of the reserved arguments. The reserved arguments are:

  report,
  base,
  path_pdf,
  send_pdf,
  cups_printer and
  PROTECT
  GROUP_ID

PrintPaths()

Returns a newly created temporary ODT and PDF filepaths. In case the path_pdf is defined it uses it for filepath instead of composing it with TmpDir directory root path.

TmpFile()

Uses File::Temp::tempfile to create a new temporary file. Closes the file, to make sure it is unlocked, then returns its filepath.

  (C) 2003 Leader.IT di Guido Brugnara <http://www.leader.it>
           Strada della Pozzata, 41 - Villazzano
           38123 T R E N T O   (ITALY)

Authors

  Guido Brugnara <gdo@leader.it>
 
Topic revision: r4 - 03 Nov 2016, JanezStangelj
This site is powered by FoswikiCopyright (©) Leader.IT - Italy P.I. IT01434390223 Privacy policy & use of cookies