Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I setup a customized footer by using this library? #118

Open
DamengRandom opened this issue Sep 14, 2018 · 3 comments
Open

How can I setup a customized footer by using this library? #118

DamengRandom opened this issue Sep 14, 2018 · 3 comments

Comments

@DamengRandom
Copy link

How can I setup customized footer by using this library?

I am trying to do something either this:
let options = {
'footer-html': '../../templates/banner-footer.html'
};
wkhtmltopdf(html, { pageSize: 'A4', disableSmartShrinking: true, options: options }, function (err, stream) { ... }

or this:

wkhtmltopdf(html, { pageSize: 'A4', disableSmartShrinking: true, footerHtml: '../../templates/banner-footer.html' }, function (err, stream) { ... }

All trials don't work? Any suggestions?

@DamengRandom
Copy link
Author

this is my code:

return new Promise((resolve, reject) => {
console.info('Converting HTML to PDF');

    let html = createHtml(statement);
    let options = {
        'footer-html': '../../templates/banner-footer.html'
    };
    wkhtmltopdf(html, { pageSize: 'A4', disableSmartShrinking: true, footerHtml: '../../templates/banner-footer.html' }, function (err, stream) {
        if (err){
            console.error(err);
            reject(err);
            return;
        }
        
        storage.writeStream(stream, statement.getFilename(), (err, cb) => {
            if (err) {
                console.error(err);
                reject(err);
            }else{
                resolve(statement);
            }
        });
    });
});

@nwhitmont
Copy link

@DamengRandom this module is a wrapper around the wkhtmltopdf program.

The footer options you are looking for are described in the core program documentation, not this module...

Check here: https://wkhtmltopdf.org/usage/wkhtmltopdf.txt

Then convert what option you need to camelCase in your options object. Eg. --footer-center becomes options = { footerCenter: 'foo'}.

Example footer options (from original documentation)

Headers And Footer Options:
      --footer-center <text>          Centered footer text
      --footer-font-name <name>       Set footer font name (default Arial)
      --footer-font-size <size>       Set footer font size (default 12)
      --footer-html <url>             Adds a html footer
      --footer-left <text>            Left aligned footer text
      --footer-line                   Display line above the footer
      --no-footer-line                Do not display line above the footer
                                      (default)
      --footer-right <text>           Right aligned footer text
      --footer-spacing <real>         Spacing between footer and content in mm
                                      (default 0)
      --header-center <text>          Centered header text
      --header-font-name <name>       Set header font name (default Arial)
      --header-font-size <size>       Set header font size (default 12)
      --header-html <url>             Adds a html header
      --header-left <text>            Left aligned header text
      --header-line                   Display line below the header
      --no-header-line                Do not display line below the header
                                      (default)
      --header-right <text>           Right aligned header text
      --header-spacing <real>         Spacing between header and content in mm
                                      (default 0)
      --replace <name> <value>        Replace [name] with value in header and
                                      footer (repeatable)

@Samerkassem
Copy link

@DamengRandom this module is a wrapper around the wkhtmltopdf program.

The footer options you are looking for are described in the core program documentation, not this module...

Check here: https://wkhtmltopdf.org/usage/wkhtmltopdf.txt

Then convert what option you need to camelCase in your options object. Eg. --footer-center becomes options = { footerCenter: 'foo'}.

Example footer options (from original documentation)

Headers And Footer Options:
      --footer-center <text>          Centered footer text
      --footer-font-name <name>       Set footer font name (default Arial)
      --footer-font-size <size>       Set footer font size (default 12)
      --footer-html <url>             Adds a html footer
      --footer-left <text>            Left aligned footer text
      --footer-line                   Display line above the footer
      --no-footer-line                Do not display line above the footer
                                      (default)
      --footer-right <text>           Right aligned footer text
      --footer-spacing <real>         Spacing between footer and content in mm
                                      (default 0)
      --header-center <text>          Centered header text
      --header-font-name <name>       Set header font name (default Arial)
      --header-font-size <size>       Set header font size (default 12)
      --header-html <url>             Adds a html header
      --header-left <text>            Left aligned header text
      --header-line                   Display line below the header
      --no-header-line                Do not display line below the header
                                      (default)
      --header-right <text>           Right aligned header text
      --header-spacing <real>         Spacing between header and content in mm
                                      (default 0)
      --replace <name> <value>        Replace [name] with value in header and
                                      footer (repeatable)

Can you please show exactly how to use footerHtml? It requires a path to the file but it's always failing.

   let footerHtml  ="imgs/footer.html"
   
   
    var html = `
   
    <h1>Test</h1><p>Hello world</p>
    `;

    let mypdf =  await wkhtmltopdf(html, 
        { pageSize: 'A4' ,   

        footerHtml : footerHtml 
    
    })

the imgs folder exists in the same folder of the script. I have tried ./imgs/footer.html as well, any idea?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants