Reputation: 353
I am using ReportLab
for generating PDF Reports and below is the code for the same. The problem is, for X number of pages, it takes T time, but for 2X pages, it takes a lot more than 2T time. Since I have a need to generate PDFs that may go up to 35000 pages, it is a big hassle. What can I do to circumvent around this issue.
from reportlab.platypus import TableStyle, SimpleDocTemplate, LongTable, Table
from reportlab.lib.pagesizes import letter
class JournalPDFGenerator(object):
"""
Generates Journal PDF with ReportLab
"""
def __init__(self, pdf_name, profile_report_id):
self.pdf_name = pdf_name
self.profile_report_id = profile_report_id
self.profile_report = ProfileWatchReport.objects.get(id=self.profile_report_id)
self.document = SimpleDocTemplate(self.pdf_name, pagesize=letter)
self.story = []
def get_prepared_rows(self):
row = [your_mark_details, threat_mark_details]
yield row
def generate_pdf(self):
report_table = LongTable([row for row in self.get_prepared_rows()])
self.story.append(report_table)
self.document.build(self.story)
Upvotes: 3
Views: 1619
Reputation: 483
I spent a lot of time to find the cause of the problem above. Instead of LongTable you can try to use my BigDataTable class, optimized for processing big data.
GIST BigDataTable faster LongTable on the big data
Tested with 6500 rows and 7 columns:
Upvotes: 2
Reputation: 5740
35k pages is not exactly mainstream PDF use, so any glitches are not entirely unexpected. A few ideas to explore:
LongTable
that runs over the same length to check if the problem is related to that particular structure; if it is; you might be able to find an alternative.Upvotes: 0