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

Unable to create more than one page #15

Open
rose-ramasamy opened this issue Mar 18, 2021 · 8 comments
Open

Unable to create more than one page #15

rose-ramasamy opened this issue Mar 18, 2021 · 8 comments

Comments

@rose-ramasamy
Copy link

rose-ramasamy commented Mar 18, 2021

Hi there,

I am trying to create PDF reports using python. I have the content for more than one page but if I generate a report it is failing to create.

Note: If I reduce the content the pdf is created with a single page.

Please help me.. Thanks in advance.

My python file look like this:

import pandas
from pdf_reports import pug_to_html, write_report
from pdf_reports import ReportWriter

litems = ["apple", "banana", "cherry","apple", "banana", "cherry","apple", "banana", "cherry","apple", "banana", "cherry","apple", "banana", "cherry","apple", "banana", "cherry"]

dataframe = pandas.DataFrame.from_records({
    "Name": ["US", "Netherlands", "Germany"],
    "Status": ['Pass','Pass','Fail']
}, columns=["Name", "Status"])

print(dataframe)

df = pandas.DataFrame({'Date':['10/2/2011', '11/2/2011', '12/2/2011', '13/2/11'],
                    'Event':['Music', 'Poetry', 'Theatre', 'Comedy'],
                    'Cost':[10000, 5000, 15000, 2000]})

# Create an empty list
Row_list = []

# Iterate over each row
for index, rows in df.iterrows():
    # Create list for the current row
    my_list = [rows.Date, rows.Event, rows.Cost]

    # append the list to the final list
    Row_list.append(my_list)

# Print the list
print(Row_list)

report_writer = ReportWriter(
    default_stylesheets=["style.css"],
    default_template="example_template.pug"
)

html = report_writer.pug_to_html(title="My report",items= litems,data= Row_list)
report_writer.write_report(html, "example.pdf")

my template file look like this:

#sidebar: p Hey, I am a sidebar text ! I make your document look much more serious.

h1 {{ title }}
:markdown
  You can install `pdf_reports` with Python's PIP:

.ui.container
  .ui.icon.message.yellow.block-center
    i.exclamation.circle.icon
    .content .header This is an important message, as per the exclamation mark.

:markdown
  ##  I am a section title
{% for c in items %}
p {{c}}
{% endfor %}

{% for value in data %}
p {{ value }}
{% endfor %}

table.ui.celled.table
thead
    tr
      th File
      th description
tbody
    tr
      td No Name Specified
      td Unknown
      td.negative None
@Zulko
Copy link
Member

Zulko commented Mar 18, 2021

but if I generate a report it is failing to create.

Can you share the full error you get?

@rose-ramasamy
Copy link
Author

Dear Zulko,

I did not get an error. The PDF is created but when i open the pdf i am getting an error.

error_msg_pdf

If you want I can attach my source code.

@veghp
Copy link
Member

veghp commented Mar 18, 2021

This error is the same as was posted in Edinburgh-Genome-Foundry/blabel#10 .
A solution was posted in this comment: Edinburgh-Genome-Foundry/blabel#10 (comment)
The issue exists in Windows only (which we don't test for), in a dependency of pdf_reports, not the package itself.
Please let us know if this solves the problem.

@rose-ramasamy
Copy link
Author

It worked @veghp.
Thanks for support.

@rose-ramasamy
Copy link
Author

Hi there..
This solved the issue in windows. But in Linux experiencing different issues. When I run the same program in Linux getting the following error:
image

Can someone help on this?

@doppioandante
Copy link

It looks like this error also affects Linux, in my case Debian 12 (bookworm). I'm not sure whether cairo is the culprit again, system cairo is at version 1.16.0-7 and cairocffi python dep is 1.6.1. weasyprint version 61.0

@doppioandante
Copy link

Downgrading weasyprint to version 52 solved this for me

@veghp
Copy link
Member

veghp commented Mar 29, 2024

Thanks @doppioandante for posting this, yes indeed there is an issue we're currently having and there might be a couple things going on. Your solution was also proposed at https://doc.courtbouillon.org/weasyprint/stable/first_steps.html#installation

If the version of Pango provided by your distribution is too old, you can use version 52.5 of WeasyPrint which does not need recent Pango features.

But for the original issue, installation of dependencies are explained in the link above.

It may be worth checking if you have multiple different versions of pango installed (run which pango-view in different conda environments for example), as that's an additional complication I came across.

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

4 participants