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

Error in write_pdf after Document.copy with duplicate page #990

Closed
ewingrj opened this issue Nov 8, 2019 · 3 comments
Closed

Error in write_pdf after Document.copy with duplicate page #990

ewingrj opened this issue Nov 8, 2019 · 3 comments
Labels
bug Existing features not working as expected

Comments

@ewingrj
Copy link

ewingrj commented Nov 8, 2019

This is a follow up on #880

It appears that this is caused when duplicating a page within a document.

Here is a script to reproduce:

#!/usr/bin/env python
from weasyprint import HTML

if __name__ == "__main__":
    doc = HTML(string='''
    <style>
    h2 {
        margin-top: 8px;
        margin-bottom: 8px;
    }

    table.items {
        border-collapse: collapse;
        color: #333;
        width: 75%;
    }

    .items tr:nth-child(even) {
        background: #eee;
    }

    .items tr:first-child {
        background: white;
    }

    .items td, th {
        border: 1px solid #ccc;
        padding: 0.5em;
    }

    .items th {
        border: none;
        text-align: center;
    }

    .items tbody {
        border-bottom: 3px solid black;
    }
</style>



<table style="border: none; width: 100%; margin-bottom: 0">
    <tr>
        <td>Order ID: 3529</td>
        <td style="float:right;">Oct. 24, 2019, 12:01 a.m.</td>
    </tr>
</table>

<h2>Your Details</h2>
<table style="width: 100%;">
    
        <tr>
            
                <td style="padding: 5px; font-weight: 600">Name:&nbsp;&nbsp;&nbsp;</td>
                <td style="padding: 5px;">Name Here</td>
            
        </tr>
    
        <tr>
            
                <td style="padding: 5px; font-weight: 600">Phone:&nbsp;&nbsp;&nbsp;</td>
                <td style="padding: 5px;">999-999-9999</td>
            
                <td style="padding: 5px; font-weight: 600">Alt. Phone:&nbsp;&nbsp;&nbsp;</td>
                <td style="padding: 5px;"></td>
            
        </tr>
    
    <tr>
        <td style="padding: 5px; font-weight: 600">Drop Site</td>
        <td style="padding: 5px">xxxxxxxxx</td>
    </tr>
    
</table>

<h2>Items Ordered</h2>
<table class="items">
    <tr>
        <th>Item</th>
        <th>Qty</th>
        <th>Packed</th>
    </tr>

    
        <tbody>
            
                <tr>
                    <td>xxxxxx</td>
                    <td>1</td>
                    <td><input type="checkbox"/></td>
                </tr>
            
        </tbody>
    
</table>
    ''').render()

    doc = doc.copy(doc.pages + doc.pages)
    doc.write_pdf('example.pdf')
@liZe liZe added the bug Existing features not working as expected label Nov 8, 2019
@Tontyna
Copy link
Contributor

Tontyna commented Nov 9, 2019

Minimal snippet to reproduce:

<input type="checkbox">

This, like #991, is an effect of StackingContext.from_page() manipulating the original page box tree.

Original tree:

<PageBox PageType(side='right', blank=False, first=True, index=0, name='')>
  <BlockBox html>
    <BlockBox body>
      <LineBox body>
        <InlineBlockBox input>

Manipulated tree:

<PageBox PageType(side='right', blank=False, first=True, index=0, name='')>
  <BlockBox html>
    <BlockBox body>
      <LineBox body>
        <weasyprint.stacking.StackingContext object at 0x00000000051BF780>

No problem unless the tree is rendered twice.

@chickendude
Copy link

(I believe) i've been hit with this issue as well as i'm trying to create a version of the document with the title page and another without it:

doc.copy(pages=book).write_pdf(target=book_file)
doc.copy(pages=book[1:]).write_pdf(target=book_no_cover_file)

The first pdf is created, the second fails: "'StackingContext' object has no attribute 'style'"

@liZe liZe changed the title Error in write_pdf after Documet.copy with duplicate page Error in write_pdf after Document.copy with duplicate page Dec 27, 2019
@liZe
Copy link
Member

liZe commented Jun 18, 2024

This bug has been fixed in a previous version of WeasyPrint.

@liZe liZe closed this as completed Jun 18, 2024
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

4 participants