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

Rotated headers missing from pdf when write_pdf is invoked twice from the same document #1081

Closed
bastbnl opened this issue Mar 21, 2020 · 3 comments
Labels
bug Existing features not working as expected
Milestone

Comments

@bastbnl
Copy link

bastbnl commented Mar 21, 2020

First of all I'd like to thank you all for maintaining such a wonderful module, including beautiful examples.

For some reason I called write_pdf more than once on the Document and noticed that the pdf created by the second call differs from the pdf that's created when it is first called. The most obvious difference is that rotated headers are missing from the document created by the second call.

  • WeasyPrint==51
  • Python 3.5.3
  • Debian 9.12

There is a warning when weasyprint is imported, which might be related.
document.py:36: UserWarning: There are known rendering problems and missing features with cairo < 1.15.4. WeasyPrint may work with older versions, but please read the note about the needed cairo version on the "Install" page of the documentation before reporting bugs. http://weasyprint.readthedocs.io/en/latest/install.html

This script reproduces the error:

from weasyprint import HTML, CSS

pdf_payload = HTML(
 filename='weasyprint-rotated-headers.html',
)

pdf_document = pdf_payload.render(
 stylesheets=[
  CSS(
   filename='weasyprint-rotated-headers.css',
  ),
 ]
)

pdf_document.write_pdf(target='x1.pdf')
pdf_document.write_pdf(target='x2.pdf')

weasyprint-rotated-headers.html:

<!DOCTYPE html>
<html>
 <head>
  <title>
   xxxx
  </title>
 </head>
 <body style="font-family: Rubik;">
  <article id="cover">
  </article>
  <article id="detail">
   <h3>
    XXX
   </h3>
   <table>
    <thead>
     <tr>
      <th class="rotate">
       <div>
        <span>
         1
        </span>
       </div>
      </th>
      <th class="rotate">
       <div>
        <span>
         2
        </span>
       </div>
      </th>
      <th class="rotate">
       <div>
        <span>
         3
        </span>
       </div>
      </th>
      <th class="rotate">
       <div>
        <span>
         4
        </span>
       </div>
      </th>
      <th class="rotate">
       <div>
        <span>
         5
        </span>
       </div>
      </th>
      <th class="rotate">
       <div>
        <span>
         6
        </span>
       </div>
      </th>
      <th class="rotate">
       <div>
        <span>
         7
        </span>
       </div>
      </th>
      <th class="rotate">
       <div>
        <span>
         8
        </span>
       </div>
      </th>
      <th class="rotate">
       <div>
        <span>
         9
        </span>
       </div>
      </th>
     </tr>
    </thead>
    <tbody>
     <tr>
      <td style="">
       xxx
      </td>
      <td style="">
       xxx
      </td>
      <td style="text-align: center; ">
       —
      </td>
      <td style="text-align: center; ">
       —
      </td>
      <td style="text-align: center; ">
       —
      </td>
      <td style="text-align: center; ">
       —
      </td>
      <td style="text-align: center; ">
       —
      </td>
      <td style="text-align: center; ">
       —
      </td>
      <td style="text-align:center; ">
       —
      </td>
     </tr>
    </tbody>
   </table>
  </article>
 </body>
</html>

weasyprint-rotated-headers.css:

  html body th.rotate{
    height:140px;white-space:nowrap}
  html body th.rotate > div{
    transform:translate(25px,51px) rotate(315deg);width:30px}
  html body th.rotate > div > span{
    border-bottom:1px solid #ccc;padding:5px 10px}

Running the script on the stack I'm using will create 2 pdf files: x1.pdf and x2.pdf. x1.pdf will have rotated headers, x2.pdf will not. I'm using Edge (and Firefox) on Windows to view the PDF files.

The workaround is pretty simple: write the pdf to a BytesIO and write the payload to multiple files - when you need it - but I thought you might like to know.

@liZe liZe added the bug Existing features not working as expected label Mar 27, 2020
@Tontyna
Copy link
Contributor

Tontyna commented May 28, 2020

Another case of StackingContext in action, see #990 and #991

Examples of things that will disappear when write_pdf is called twice:

<div style="transform: scaleX(2)">disappears</div>
<div style="float: right">disappears</div>
<div style="position:absolute">disappears</div>
<div style="z-index:3;position:relative">disappears</div>
<div style="overflow:hidden">disappears</div>
<div style="opacity:0.5">disappears</div>
<input type="checkbox">

@Tontyna
Copy link
Contributor

Tontyna commented May 28, 2020

To be honest: <input type="checkbox"> wont disappear but crash, see #880

@liZe
Copy link
Member

liZe commented Apr 25, 2022

This bug was fixed in version 54.x, related to #880 and #1396.

@liZe liZe closed this as completed Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Existing features not working as expected
Projects
None yet
Development

No branches or pull requests

3 participants