Different Header Height for first page & other pages? (Dynamic Header Size)



  • Hi,

    We have created a PDF report using JSReport with ejs as engine & Phantom-PDF recipe.
    We wanted a different header for 1st page. So we have used the logic of hiding the Header using page number.
    But the issue we are facing is that we need different header height for 1st page & different header height for other pages.

    Is it possible to assign dynamic header height at the time of rendering the PDF?

    Thanks,
    Bipin



  • I'm afraid this is not possible with phantomjs native header.
    You may try pdf-utils extension and concatenate multiple pdfs.



  • Ok. Will Try.
    Thanks for the reply.



  • @jan_blaha How do you go about installing this PDF utils?


  • administrators

    @Carl-Blanchard hi! pdf-utils is an extension that it is pre-installed along with jsreport v2, so no need to install anything to get it. for usage check and some live examples the docs



  • oh so only with V2... can you run v2 alongside 1.8.2 ?
    of course on another port.


  • administrators

    oh so only with V2

    you can also install pdf-utils in jsreport v1 using npm install jsreport-pdf-utils@0.x.x, but of course the 0.x.x versions of pdf-utils are considered outdated and maybe you will find some bugs or maybe not, you will need to test it and see if it works normally for what you will try to do in your template.

    can you run v2 alongside 1.8.2 ?
    of course on another port.

    yes, you can do that, but if you want to share stored templates between the two versions the best will be to use an storage backed by a database.



  • @bjrmatos Is it possible with V2 to control the headers and footers from within the report page. My report is really complex. first three pages no headers and footers what so ever. Then depending on the boolean condition, I may need to show pages or not during my report.
    Ideally, if page headers can be controlled programmatically from within the page i.e. header.height, header.content etc. Is this possible with the new version and the pdf-utils? I've tried to use V2 but had problems to persevere with it, and I am unsure even if it gives me the flexibility I need.


  • administrators

    i think what you are describing is possible. check this example to get an idea how to render dynamic content in header depending on the page number, etc.

    https://playground.jsreport.net/w/anon/nXMgpqSu

    the example will serve you as starting point for the complex report you want.



  • Yeah, not what I meant.
    I think we need to have greater control over headers and footers. The support for these so far is very limited and in reporting a major feature is header/footers.
    If you define a header, footer, height etc. within the chrome pdf properties in the JSReport editor.
    Then on the page. If I decided to change the height for example, then If i could control the chrome pdf properties for that page, by accessing something like this.chromepdf.props.height = 0 or this.chromepdf.props.header = {#child template-header-warning......
    Having more and better control of the header & footers from each page will make your product great.
    Is this something that can be done?


  • administrators

    I think we need to have greater control over headers and footers. The support for these so far is very limited and in reporting a major feature is header/footers.

    agree with you, however what is possible today in most cases is enough. unfortunately we are limited to by what other technologies expose.

    If you define a header, footer, height etc. within the chrome pdf properties in the JSReport editor.
    Then on the page. If I decided to change the height for example, then If i could control the chrome pdf properties for that page, by accessing something like this.chromepdf.props.height = 0 or this.chromepdf.props.header = {#child template-header-warning......

    as i've shown you can decide what should be the content of the header/footer per page already, so you can put there a dynamic value. however what is not possible is to change the page's margin or height per page, there is just one option for all pages, so we can say that all html to pdf converters expect that the content in header/footer is something static in the sense that it won't consume different space per page, so far there is no way we can change that because it is a limitation of the pdf conversion.

    Is this something that can be done?

    so in short, what you are describing it is not possible to do it in the way that you want. however i think you can workaround that problem by using pdf-utils append operation, so in the end you will be composing your pdf with pages of multiples templates, each of these templates can have different margins or height, so maybe you can try that and see if it is enough for your case.



  • @bjrmatos I see where you're going with the PDF utils append. A couple of questions about this before I start.
    1, If I use multiple templates to make one report, will the page numbers span all templates or would they be restarting on each one?
    2, If I have one report that's made up of 10 individual templates. Can I conditionally decide to omit one of them?



  • @bjrmatos It doesn't work very well https://playground.jsreport.net/w/anon/3jYC4tCd

    Template 2 has a header which is not showing, Checkbox is checked everything looks like it should be working but not header on template 2



  • @bjrmatos any idea why the example above doesn't produce the header?


  • administrators

    hi! sorry, i wanted to find the time to later check the example, but i completely forgot about it.. the problem is that you were not specifying the space for the header in TemplatePage2, i changed that template with a margin top of 40px and now it shows. you can see it here https://playground.jsreport.net/w/bjrmatos/u9kIVdEz



  • Makes sense. I was expecting the margin to be set automatically for me. If the content of the header is 100px then I would expect the page to be offset by that value.
    Maybe a feature for the future.


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.