Skip to content

Commit d6d000d

Browse files
authored
Merge pull request #123 from greendreamer/reporting-examples
updated choosing mediabox
2 parents 3ba2ce6 + 638aa60 commit d6d000d

File tree

10 files changed

+64
-34
lines changed

10 files changed

+64
-34
lines changed

reporting/examples/filmfestival-2tables/Reports.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def make_story(self):
7373

7474

7575
class Options(object):
76-
def __init__(self, cols=1, format="A4", newpage=True):
76+
def __init__(self, cols=0, format=None, newpage=None):
7777
self.cols = cols
7878
self.format = format
7979
self.newpage = newpage
@@ -312,7 +312,7 @@ def __init__(
312312
self.archive = fitz.Archive(archive) if archive else fitz.Archive(".")
313313
self.HEADER_RECT = None
314314
self.FOOTER_RECT = None
315-
self.default_option = Options()
315+
self.default_option = Options(cols=1, format=mediabox, newpage=True)
316316

317317
self.css = css if css else ""
318318

@@ -359,7 +359,7 @@ def current_story(self): # get current story to draw
359359
def check_cols(self): # set current columns and determin if going new page or not
360360
_newpage = self.default_option.newpage
361361
if isinstance(self.get_current_section(), list):
362-
if len(self.get_current_section()) != 2:
362+
if len(self.get_current_section()) != 2 or self.sections[self.sindex][1].cols == 0:
363363
self.COLS = self.default_option.cols
364364
return _newpage
365365

@@ -370,8 +370,13 @@ def check_cols(self): # set current columns and determin if going new page or n
370370

371371
def get_pagerect(self): # get current page mediabox
372372
if isinstance(self.sections[self.sindex], list): # if section has info
373-
if len(self.sections[self.sindex]) != 2: # don't have property
374-
return fitz.paper_rect(self.default_option.format)
373+
if len(self.sections[self.sindex]) != 2 or self.sections[self.sindex][1].format == None: # don't have property
374+
return fitz.Rect(
375+
0.0,
376+
0.0,
377+
self.default_option.format.width,
378+
self.default_option.format.height,
379+
)
375380

376381
if isinstance(self.sections[self.sindex][1].format, str):
377382
return fitz.paper_rect(self.sections[self.sindex][1].format)

reporting/examples/filmfestival-2tables/filmfestival.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
</table>
5656
"""
5757

58-
mediabox = fitz.paper_rect("A4")
58+
mediabox = fitz.paper_rect("letter")
5959
report = Report(mediabox, font_families={"sans-serif": "ubuntu", "serif": "ubuntu"})
6060
header = Block(html=HEADER, report=report)
6161

@@ -143,6 +143,6 @@ def get_actor_items():
143143
report.header = [header]
144144
report.sections = [
145145
[film_items, Options(cols=1, format="A3", newpage=True)],
146-
[actor_items, Options(format=Size(300, 600))],
146+
[actor_items],
147147
]
148148
report.run("output.pdf")
Binary file not shown.

reporting/examples/invoice/Reports.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def make_story(self):
7373

7474

7575
class Options(object):
76-
def __init__(self, cols=1, format="A4", newpage=True):
76+
def __init__(self, cols=0, format=None, newpage=None):
7777
self.cols = cols
7878
self.format = format
7979
self.newpage = newpage
@@ -312,7 +312,7 @@ def __init__(
312312
self.archive = fitz.Archive(archive) if archive else fitz.Archive(".")
313313
self.HEADER_RECT = None
314314
self.FOOTER_RECT = None
315-
self.default_option = Options()
315+
self.default_option = Options(cols=1, format=mediabox, newpage=True)
316316

317317
self.css = css if css else ""
318318

@@ -359,7 +359,7 @@ def current_story(self): # get current story to draw
359359
def check_cols(self): # set current columns and determin if going new page or not
360360
_newpage = self.default_option.newpage
361361
if isinstance(self.get_current_section(), list):
362-
if len(self.get_current_section()) != 2:
362+
if len(self.get_current_section()) != 2 or self.sections[self.sindex][1].cols == 0:
363363
self.COLS = self.default_option.cols
364364
return _newpage
365365

@@ -370,8 +370,13 @@ def check_cols(self): # set current columns and determin if going new page or n
370370

371371
def get_pagerect(self): # get current page mediabox
372372
if isinstance(self.sections[self.sindex], list): # if section has info
373-
if len(self.sections[self.sindex]) != 2: # don't have property
374-
return fitz.paper_rect(self.default_option.format)
373+
if len(self.sections[self.sindex]) != 2 or self.sections[self.sindex][1].format == None: # don't have property
374+
return fitz.Rect(
375+
0.0,
376+
0.0,
377+
self.default_option.format.width,
378+
self.default_option.format.height,
379+
)
375380

376381
if isinstance(self.sections[self.sindex][1].format, str):
377382
return fitz.paper_rect(self.sections[self.sindex][1].format)

reporting/examples/invoice/invoicer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from Reports import *
77

88
# The following defines the overall report object
9-
mediabox = fitz.paper_rect("letter-l")
9+
mediabox = fitz.paper_rect("a4-l")
1010
report = Report(mediabox)
1111

1212
# Predefined HTML to define the header for all pages
@@ -142,7 +142,7 @@ def fetch_rows():
142142

143143
report.header = [logo, header]
144144
report.sections = [[prolog, Options(cols=1, format="letter-l")],
145-
[items, Options(newpage=False)]]
145+
[items, Options(format=Size(600, 600), newpage=False)]]
146146

147147
# This generates the report and saves it to the given path name.
148148
report.run("output.pdf")

reporting/examples/invoice/output.pdf

32.5 KB
Binary file not shown.

reporting/examples/multi-format/Reports.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def make_story(self):
7373

7474

7575
class Options(object):
76-
def __init__(self, cols=1, format="A4", newpage=True):
76+
def __init__(self, cols=0, format=None, newpage=None):
7777
self.cols = cols
7878
self.format = format
7979
self.newpage = newpage
@@ -312,7 +312,7 @@ def __init__(
312312
self.archive = fitz.Archive(archive) if archive else fitz.Archive(".")
313313
self.HEADER_RECT = None
314314
self.FOOTER_RECT = None
315-
self.default_option = Options()
315+
self.default_option = Options(cols=1, format=mediabox, newpage=True)
316316

317317
self.css = css if css else ""
318318

@@ -359,7 +359,7 @@ def current_story(self): # get current story to draw
359359
def check_cols(self): # set current columns and determin if going new page or not
360360
_newpage = self.default_option.newpage
361361
if isinstance(self.get_current_section(), list):
362-
if len(self.get_current_section()) != 2:
362+
if len(self.get_current_section()) != 2 or self.sections[self.sindex][1].cols == 0:
363363
self.COLS = self.default_option.cols
364364
return _newpage
365365

@@ -370,8 +370,13 @@ def check_cols(self): # set current columns and determin if going new page or n
370370

371371
def get_pagerect(self): # get current page mediabox
372372
if isinstance(self.sections[self.sindex], list): # if section has info
373-
if len(self.sections[self.sindex]) != 2: # don't have property
374-
return fitz.paper_rect(self.default_option.format)
373+
if len(self.sections[self.sindex]) != 2 or self.sections[self.sindex][1].format == None: # don't have property
374+
return fitz.Rect(
375+
0.0,
376+
0.0,
377+
self.default_option.format.width,
378+
self.default_option.format.height,
379+
)
375380

376381
if isinstance(self.sections[self.sindex][1].format, str):
377382
return fitz.paper_rect(self.sections[self.sindex][1].format)

reporting/examples/row-with-images/Reports.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def make_story(self):
7373

7474

7575
class Options(object):
76-
def __init__(self, cols=1, format="A4", newpage=True):
76+
def __init__(self, cols=0, format=None, newpage=None):
7777
self.cols = cols
7878
self.format = format
7979
self.newpage = newpage
@@ -312,7 +312,7 @@ def __init__(
312312
self.archive = fitz.Archive(archive) if archive else fitz.Archive(".")
313313
self.HEADER_RECT = None
314314
self.FOOTER_RECT = None
315-
self.default_option = Options()
315+
self.default_option = Options(cols=1, format=mediabox, newpage=True)
316316

317317
self.css = css if css else ""
318318

@@ -359,7 +359,7 @@ def current_story(self): # get current story to draw
359359
def check_cols(self): # set current columns and determin if going new page or not
360360
_newpage = self.default_option.newpage
361361
if isinstance(self.get_current_section(), list):
362-
if len(self.get_current_section()) != 2:
362+
if len(self.get_current_section()) != 2 or self.sections[self.sindex][1].cols == 0:
363363
self.COLS = self.default_option.cols
364364
return _newpage
365365

@@ -370,8 +370,13 @@ def check_cols(self): # set current columns and determin if going new page or n
370370

371371
def get_pagerect(self): # get current page mediabox
372372
if isinstance(self.sections[self.sindex], list): # if section has info
373-
if len(self.sections[self.sindex]) != 2: # don't have property
374-
return fitz.paper_rect(self.default_option.format)
373+
if len(self.sections[self.sindex]) != 2 or self.sections[self.sindex][1].format == None: # don't have property
374+
return fitz.Rect(
375+
0.0,
376+
0.0,
377+
self.default_option.format.width,
378+
self.default_option.format.height,
379+
)
375380

376381
if isinstance(self.sections[self.sindex][1].format, str):
377382
return fitz.paper_rect(self.sections[self.sindex][1].format)

reporting/examples/simple-article/Reports.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def make_story(self):
7373

7474

7575
class Options(object):
76-
def __init__(self, cols=1, format="A4", newpage=True):
76+
def __init__(self, cols=0, format=None, newpage=None):
7777
self.cols = cols
7878
self.format = format
7979
self.newpage = newpage
@@ -312,7 +312,7 @@ def __init__(
312312
self.archive = fitz.Archive(archive) if archive else fitz.Archive(".")
313313
self.HEADER_RECT = None
314314
self.FOOTER_RECT = None
315-
self.default_option = Options()
315+
self.default_option = Options(cols=1, format=mediabox, newpage=True)
316316

317317
self.css = css if css else ""
318318

@@ -359,7 +359,7 @@ def current_story(self): # get current story to draw
359359
def check_cols(self): # set current columns and determin if going new page or not
360360
_newpage = self.default_option.newpage
361361
if isinstance(self.get_current_section(), list):
362-
if len(self.get_current_section()) != 2:
362+
if len(self.get_current_section()) != 2 or self.sections[self.sindex][1].cols == 0:
363363
self.COLS = self.default_option.cols
364364
return _newpage
365365

@@ -370,8 +370,13 @@ def check_cols(self): # set current columns and determin if going new page or n
370370

371371
def get_pagerect(self): # get current page mediabox
372372
if isinstance(self.sections[self.sindex], list): # if section has info
373-
if len(self.sections[self.sindex]) != 2: # don't have property
374-
return fitz.paper_rect(self.default_option.format)
373+
if len(self.sections[self.sindex]) != 2 or self.sections[self.sindex][1].format == None: # don't have property
374+
return fitz.Rect(
375+
0.0,
376+
0.0,
377+
self.default_option.format.width,
378+
self.default_option.format.height,
379+
)
375380

376381
if isinstance(self.sections[self.sindex][1].format, str):
377382
return fitz.paper_rect(self.sections[self.sindex][1].format)

reporting/examples/user-fonts/Reports.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def make_story(self):
7373

7474

7575
class Options(object):
76-
def __init__(self, cols=1, format="A4", newpage=True):
76+
def __init__(self, cols=0, format=None, newpage=None):
7777
self.cols = cols
7878
self.format = format
7979
self.newpage = newpage
@@ -312,7 +312,7 @@ def __init__(
312312
self.archive = fitz.Archive(archive) if archive else fitz.Archive(".")
313313
self.HEADER_RECT = None
314314
self.FOOTER_RECT = None
315-
self.default_option = Options()
315+
self.default_option = Options(cols=1, format=mediabox, newpage=True)
316316

317317
self.css = css if css else ""
318318

@@ -359,7 +359,7 @@ def current_story(self): # get current story to draw
359359
def check_cols(self): # set current columns and determin if going new page or not
360360
_newpage = self.default_option.newpage
361361
if isinstance(self.get_current_section(), list):
362-
if len(self.get_current_section()) != 2:
362+
if len(self.get_current_section()) != 2 or self.sections[self.sindex][1].cols == 0:
363363
self.COLS = self.default_option.cols
364364
return _newpage
365365

@@ -370,8 +370,13 @@ def check_cols(self): # set current columns and determin if going new page or n
370370

371371
def get_pagerect(self): # get current page mediabox
372372
if isinstance(self.sections[self.sindex], list): # if section has info
373-
if len(self.sections[self.sindex]) != 2: # don't have property
374-
return fitz.paper_rect(self.default_option.format)
373+
if len(self.sections[self.sindex]) != 2 or self.sections[self.sindex][1].format == None: # don't have property
374+
return fitz.Rect(
375+
0.0,
376+
0.0,
377+
self.default_option.format.width,
378+
self.default_option.format.height,
379+
)
375380

376381
if isinstance(self.sections[self.sindex][1].format, str):
377382
return fitz.paper_rect(self.sections[self.sindex][1].format)

0 commit comments

Comments
 (0)