Can I display a different PDF header for each instance of generation?

(8 posts) (2 voices)

Tags:

  1. shem, Member

    I am new to PDF Header implementation.

    We are generating reports from within our PHP application.

    Let's say that the PHP application produces some data or better yet a block of HTML code before generating the report.
    This block of html might be different each time the PHP code is run and gets to the point of generating the myDBR report.

    Can I pass this block of HTML code to the myDBR URL which I have assembled in order that this header appears on the PDF output as the header of the PDF report?

    Please remember I am new to this (and somewhat new to myDBR in general) so explicit instructions would be appreciated.
    Thanks.

  2. myDBR Team, Key Master

    You can use the wkhtmltopdf's --header-html option to pass HTML into the header. See the myDBR documentation how to use the option.

    You can also create your own version of the default header located at mydbr/user/export_header_pdf.php.
    --
    myDBR Team

  3. shem, Member

    ok, I see this in the documentation:
    select 'dbr.wkhtmltopdf', "--header-html ''"; /* Do not use header in export using wkhtmltopdf */

    So assuming I want PDF possibility via &export=pdf, and I want PDF headers for all my reports
    then please tell me if the following is correct:
    I would have to do the following for every single report"
    1) Add a parameter to every myDBR stored procedure, maybe called _my_html_for_header
    2) Add the automatic parameter inExportFormat to every report
    3) Add the following code to my reports
    if (inExportFormat !='pdf') then
    SELECT 'dbr.wkhtmltopdf', "--header-html _my_html_for_header "
    end if;

    And then I need clarification on what can be in the parameter _my_html_for_header
    a) Is it just the html tags themselves right away e.g. <h1>stuff</></br><h2>more stuff</h2>
    or do I need to include these tags
    <!DOCTYPE html>
    <html lang="en-US">
    <head>
    </head>
    <body>
    </body>
    </html>

    b) Do I need special handling for single or double quotes that are in this block of html

    Here are questions about the alternative solution you wrote:
    You can also create your own version of the default header located at mydbr/user/export_header.php.

    1) Is mydbr/user/export_header.php doing anything if I haven't touched it? Do I need to enable it in environment settings?
    2) Where in that file would I put something to do a simple test?
    3) From that file would it work if it contained $_SESSION variables from my PHP application? My thought is maybe I can have my application store a block of HTML code in a PHP $_SESSION variable and have it be rendered there?

    Any detailed comments will be appreciated.
    Thanks

  4. myDBR Team, Key Master

    I would have to do the following for every single report

    You can either do custom header for reports in your report code or use generic custom header by modifying the mydbr/user/export_header_pdf.php

    if (inExportFormat !='pdf') then

    No need to check the PDF, the option will do nothing on other exports/normal report. It only affects PDF exports.

    a) Is it just the html tags themselves right away
    b) Do I need special handling for single or double quotes that are in this block of html

    See sample headers in the wkhtmltopdf documentation or check the myDBR default one.

    1) Is mydbr/user/export_header.php doing anything if I haven't touched it? Do I need to enable it in environment settings?

    it is only used in PDF exports when the default header is being used.

    2) Where in that file would I put something to do a simple test?

    You are free to modify the PHP file or replace it with your own.

    3) From that file would it work if it contained $_SESSION variables from my PHP application? My thought is maybe I can have my application store a block of HTML code in a PHP $_SESSION variable and have it be rendered there?

    Each PHP applications have their own $_SESSION variable. myDBR does not see your apps $_SESSION variable.

    --
    myDBR Team

  5. shem, Member

    Thank you.
    So in https://wkhtmltopdf.org/usage/wkhtmltopdf.txt
    I see one example.
    The paragraph beginning with:
    Headers and footers can also be supplied with HTML documents. As an example one could specify --header-html header.html, and use the following content in header.html

    Is that the example you were referring to?
    I didn't see any others.
    That one has a lot of JavaScript, and I don't really know JavaScript.
    Do you have an example with pure HTML?

    And when you write "or check the myDBR default one."
    Do you mean your reference to a file mydbr/user/export_header.php ?
    p.s. in the mydbr/user directory I see a file called export_header_pdf.php but not a file called export_header.php
    Did the name change in a recent version?

    Finally, in the one wkhtmltopdf example, they wrote ne could specify --header-html header.html
    Is header.html the name of a file?
    Is it a myDBR file or is it a new file that I create? and if I create it, would I place it in the mydbr/user directory?

  6. myDBR Team, Key Master

    That one has a lot of JavaScript, and I don't really know JavaScript.
    Do you have an example with pure HTML?

    You can leave out the JavaScript and use plain HTML. Use of JavaScript is optional.

    Do you mean your reference to a file mydbr/user/export_header.php ?
    p.s. in the mydbr/user directory I see a file called export_header_pdf.php but not a file called export_header.php

    The correct file is export_header_pdf.php.

    Finally, in the one wkhtmltopdf example, they wrote ne could specify --header-html header.html
    Is header.html the name of a file?
    Is it a myDBR file or is it a new file that I create? and if I create it, would I place it in the mydbr/user directory?

    If you want to use your own HTML file, you create one and place it into user directory. You can then refer to it with --header-html user/header.html

    --
    myDBR Team

  7. shem, Member

    Please see the email I sent to support@mydbr.com in effort to summarize and clarify the answers you have given me so far.
    The email also asks to please send me an example with pure html that I can use as a parameter to
    select 'dbr.wkhtmltopdf', " --header-html THE_PARAMETER_OF_HTML_CODE ";
    thanks

  8. shem, Member

    Please see the email I sent to support@mydbr.com today
    I have not been able to get export_header_pdf.php to show anything at all even with a skeleton of a file.


Reply

You must log in to post.