Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

Need support: 2 sections in 1 page. #1654

Open
rutcreate opened this issue Apr 19, 2014 · 12 comments · May be fixed by #5001
Open

Need support: 2 sections in 1 page. #1654

rutcreate opened this issue Apr 19, 2014 · 12 comments · May be fixed by #5001
Labels
Verified The issue is verified.
Milestone

Comments

@rutcreate
Copy link

I put 2 h1s in first page. There are 2 pages.

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style>
    .break {page-break-before:always;}
    </style>
</head>

<body>
    <h1>First section</h1>
    <p>Quam temere in vitiis, legem sancimus haerentia. Petierunt uti sibi concilium totius Galliae in diem certam indicere. Plura mihi bona sunt, inclinet, amari petere vellent. Ullamco laboris nisi ut aliquid ex ea commodi consequat. Magna pars studiorum, prodita quaerimus. Curabitur blandit tempus ardua ridiculus sed magna.</p><p>Gallia est omnis divisa in partes tres, quarum. Inmensae subtilitatis, obscuris et malesuada fames. Quo usque tandem abutere, Catilina, patientia nostra? Pellentesque habitant morbi tristique senectus et netus. Quam diu etiam furor iste tuus nos eludet? Cum sociis natoque penatibus et magnis dis parturient.</p>
    <h1>Second section</h1>
    <p>Contra legem facit qui id facit quod lex prohibet. Quisque ut dolor gravida, placerat libero vel, euismod. Contra legem facit qui id facit quod lex prohibet. A communi observantia non est recedendum.</p><p>Nihil hic munitissimus habendi senatus locus, nihil horum? Non equidem invideo, miror magis posuere velit aliquet. Hi omnes lingua, institutis, legibus inter se differunt. Idque Caesaris facere voluntate liceret: sese habere. Excepteur sint obcaecat cupiditat non proident culpa. Non equidem invideo, miror magis posuere velit aliquet.</p></p>Salutantibus vitae elit libero, a pharetra augue. Morbi fringilla convallis sapien, id pulvinar odio volutpat. Cum sociis natoque penatibus et magnis dis parturient. Mercedem aut nummos unde unde extricat, amaras. Cum ceteris in veneratione tui montes, nascetur mus. Nec dubitamus multa iter quae et nos invenerat.</p>
    <div class="break"></div>
    <p>Qui ipsorum lingua Celtae, nostra Galli appellantur. Tu quoque, Brute, fili mi, nihil timor populi, nihil! Qui ipsorum lingua Celtae, nostra Galli appellantur. A communi observantia non est recedendum. A communi observantia non est recedendum. Quis aute iure reprehenderit in voluptate velit esse.</p>
</body>
</html>

Then I put script into the header html file.

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
        <script type="text/javascript">
            function subst() {
                var vars ={};
                var x =document.location.search.substring(1).split('&');
                for (var i in x) {var z=x[i].split('=',2);vars[z[0]] = unescape(z[1]);}
                var x=['frompage','topage','page','webpage','section','subsection','subsubsection'];
                for (var i in x) {
                    var y = document.getElementsByClassName(x[i]);
                    for (var j=0; j<y.length; ++j) y[j].textContent = vars[x[i]];
                }
                $('body').append('<div>' + vars['section'] + '</div>');
            }
        </script>
    </head>
    <body onload="subst()">
    </body>
</html>

Here is footer html:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <link href="{{ STATIC_URL }}css/project_pdf.css" type="text/css" rel="stylesheet" />
        <script type="text/javascript" src="{{ STATIC_URL }}js/jquery-1.10.2.min.js"></script>
        <script type="text/javascript">
            function subst() {
                var vars ={};
                var x =document.location.search.substring(1).split('&');
                for (var i in x) {var z=x[i].split('=',2);vars[z[0]] = unescape(z[1]);}
                var x=['frompage','topage','page','webpage','section','subsection','subsubsection'];
                for (var i in x) {
                    var y = document.getElementsByClassName(x[i]);
                    for (var j=0; j<y.length; ++j) y[j].textContent = vars[x[i]];
                }
            }
        </script>
    </head>
    <body onload="subst()">
        <div class="text-center">- <span class="page"></span> -</div>
    </body>
</html>

At the header, it says 'First section' on both page.

Please see result: http://rutcreate.com/s1.pdf

@ashkulz
Copy link
Member

ashkulz commented Apr 21, 2014

Can you post the exact command line you used to generate the above PDF?

@rutcreate
Copy link
Author

I use https://github.com/incuna/django-wkhtmltopdf in Django project. I debug from code and I got this command.

wkhtmltopdf --encoding utf8 --footer-html /var/.../wkhtmltopdfJRCQtu.html --header-spacing 10 --header-html /var/.../wkhtmltopdf8TFvNx.html --margin-bottom 30 -margin-left 17 --margin-top 30 --quiet /var/.../wkhtmltopdfvMqNnH.html

@ashkulz
Copy link
Member

ashkulz commented Apr 21, 2014

Can you update your initial post to include the contents of --footer-html?

@rutcreate
Copy link
Author

Please see below:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <link href="{{ STATIC_URL }}css/project_pdf.css" type="text/css" rel="stylesheet" />
        <script type="text/javascript" src="{{ STATIC_URL }}js/jquery-1.10.2.min.js"></script>
        <script type="text/javascript">
            function subst() {
                var vars ={};
                var x =document.location.search.substring(1).split('&');
                for (var i in x) {var z=x[i].split('=',2);vars[z[0]] = unescape(z[1]);}
                var x=['frompage','topage','page','webpage','section','subsection','subsubsection'];
                for (var i in x) {
                    var y = document.getElementsByClassName(x[i]);
                    for (var j=0; j<y.length; ++j) y[j].textContent = vars[x[i]];
                }
            }
        </script>
    </head>
    <body onload="subst()">
        <div class="text-center">- <span class="page"></span> -</div>
    </body>
</html>

@rutcreate
Copy link
Author

Any clue?

@ashkulz
Copy link
Member

ashkulz commented Apr 23, 2014

Not really, haven't gotten time to look into it this week.

@rutcreate
Copy link
Author

Ok. I understand you have a lot of work to do. I'm going to find another way to do this. Thanks anyway.

@mn4367
Copy link
Contributor

mn4367 commented Apr 23, 2014

Very interesting. I've tested this with 0.11.0rc2 on OSX and the problem is the same, so at least it wasn't introduced by changes in the 0.12x branch.

I've investigated this a little bit further and it seems that if there is more than one heading on a page, only the first one is used, all others are ignored for the following pages which don't have headings. This isn't only true for the first page but for all pages. And it is also true for other headings (h2, h3 respectively subsection and subsubsection).

If this should be fixed in the future the question arises which section name should be passed to the header/footer html, if there is more than one section on the page, the first or the last section name? I'd vote for the first one, IMO this is more appropriate.

@jobe451
Copy link

jobe451 commented Aug 14, 2015

I have the same issue. mn4367 asks earlier "If this should be fixed in the future the question arises which section name should be passed to the header/footer html, if there is more than one section on the page, the first or the last section name?".

mn4367 writes "I'd vote for the first one".

Me too, except for that it is not that simple. There might be 0, 1 or n sections on any page. wkhtmltopdf currently missbehaves in the 0-scenario.

I would vote for:

  • the first one present on the page
  • if there is no first one, than the last one seen on the previous pages
  • if there was never one on any previous page, than empty

Example.

Header:
..........................................................
content
content
content
----------page break-----------------
Header:
..........................................................
content
content
content
----------page break-----------------
Header: title a
..........................................................
content
H1: title a
content
----------page break-----------------
Header: title b
..........................................................
content
H1: title b
content
H1: title c
content
----------page break-----------------
Header: title c
..........................................................
content
content
content
----------page break-----------------
Header: title c
..........................................................
content
content
content

@richmahn
Copy link

3 years and still open?

@Anto1106
Copy link

Anto1106 commented Dec 3, 2019

is this issue fixed? any solution?

@RiazAhamed
Copy link

RiazAhamed commented Nov 29, 2020

Hi
This Could be the solution to this problem...

<?php
  require './vendor/autoload.php';

  $optionsForAllPage = array(
    'header-html' => './common/header/header-template-1.html',
  );
  $optionsForSpecificPage = array(
    'header-html' => './common/header/header-template-2.html',
  );

  $pdf = new Pdf();
  $pdf->addCover('http://localhost:8888/pdf/cover-page.html');
for ($x = 0; $x <= 10; $x++) {
  $pdf->addPage('http://localhost:8888/pdf/page/home-page-' . $x . '.html', $optionsForAllPage);
  $pdf->addPage('http://localhost:8888/pdf/page/index-page-' . $x . '.html', $optionsForAllPage);
  $pdf->addPage('http://localhost:8888/pdf/page/user-page-' . $x . '.html', $optionsForAllPage);
  $pdf->addPage('http://localhost:8888/pdf/page/reference-page-' . $x . '.html', $optionsForSpecificPage);
}
  $pdf->setOptions($options);

  if (!$pdf->saveAs('out.pdf')) {
    $error = $pdf->getError();
    echo $error;die;
  }
?>

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Verified The issue is verified.
7 participants