"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "xhtml2pdf/xhtml2pdf_reportlab.py" between
xhtml2pdf-0.2.6.tar.gz and xhtml2pdf-0.2.7.tar.gz

About: xhtml2pdf is a HTML/CSS to PDF converter written in Python.

xhtml2pdf_reportlab.py  (xhtml2pdf-0.2.6):xhtml2pdf_reportlab.py  (xhtml2pdf-0.2.7)
skipping to change at line 38 skipping to change at line 38
from reportlab.lib.utils import (LazyImageReader, flatten, from reportlab.lib.utils import (LazyImageReader, flatten,
haveImages, open_for_read) haveImages, open_for_read)
from reportlab.platypus.doctemplate import (BaseDocTemplate, IndexingFlowable, from reportlab.platypus.doctemplate import (BaseDocTemplate, IndexingFlowable,
PageTemplate) PageTemplate)
from reportlab.platypus.flowables import (CondPageBreak, Flowable, KeepInFrame, from reportlab.platypus.flowables import (CondPageBreak, Flowable, KeepInFrame,
ParagraphAndImage) ParagraphAndImage)
from reportlab.platypus.tableofcontents import TableOfContents from reportlab.platypus.tableofcontents import TableOfContents
from reportlab.platypus.tables import Table, TableStyle from reportlab.platypus.tables import Table, TableStyle
from reportlab.rl_config import register_reset from reportlab.rl_config import register_reset
from xhtml2pdf.builders.watermarks import WaterMarks
from xhtml2pdf.reportlab_paragraph import Paragraph from xhtml2pdf.reportlab_paragraph import Paragraph
from xhtml2pdf.util import getBorderStyle, getUID from xhtml2pdf.util import getBorderStyle, getUID
from xhtml2pdf.files import pisaTempFile from xhtml2pdf.files import pisaTempFile
try: try:
from reportlab.graphics import renderPDF, renderPM from reportlab.graphics import renderPDF, renderPM
from svglib.svglib import svg2rlg from svglib.svglib import svg2rlg
except ImportError: except ImportError:
svg2rlg = None svg2rlg = None
renderPM = None renderPM = None
skipping to change at line 197 skipping to change at line 198
PageTemplate.__init__(self, **kw) PageTemplate.__init__(self, **kw)
self._page_count = 0 self._page_count = 0
self._first_flow = True self._first_flow = True
### Background Image ### ### Background Image ###
self.img = None self.img = None
self.ph = 0 self.ph = 0
self.h = 0 self.h = 0
self.w = 0 self.w = 0
self.backgroundids = []
def isFirstFlow(self, canvas): def isFirstFlow(self, canvas):
if self._first_flow: if self._first_flow:
if canvas.getPageNumber() <= self._page_count: if canvas.getPageNumber() <= self._page_count:
self._first_flow = False self._first_flow = False
else: else:
self._page_count = canvas.getPageNumber() self._page_count = canvas.getPageNumber()
canvas._doctemplate._page_count = canvas.getPageNumber() canvas._doctemplate._page_count = canvas.getPageNumber()
return self._first_flow return self._first_flow
def isPortrait(self): def isPortrait(self):
return self.pageorientation == self.PORTRAIT return self.pageorientation == self.PORTRAIT
def isLandscape(self): def isLandscape(self):
return self.pageorientation == self.LANDSCAPE return self.pageorientation == self.LANDSCAPE
def beforeDrawPage(self, canvas, doc): def beforeDrawPage(self, canvas, doc):
canvas.saveState() canvas.saveState()
try: try:
# Background if doc.pageTemplate.id not in self.backgroundids:
pisaBackground = None pisaBackground = None
if (self.isFirstFlow(canvas) if hasattr(self, "pisaBackground") and self.pisaBackground and (
and hasattr(self, "pisaBackground") not self.pisaBackground.notFound()):
and self.pisaBackground if self.pisaBackground.getMimeType().startswith("image/"):
and (not self.pisaBackground.notFound())): pisaBackground = WaterMarks.generate_pdf_background(self
.pisaBackground,
# Is image not PDF self
if self.pisaBackground.getMimeType().startswith("image/"): .pagesize, self.isPortrait(),
cont
try: ext=self.backgroundContext)
self.img = PmlImageReader(BytesIO(self.pisaBackground.ge else:
tData())) pisaBackground = self.pisaBackground
iw, ih = self.img.getSize() self.backgroundids.append(doc.pageTemplate.id)
pw, self.ph = canvas._pagesize if pisaBackground:
self.pisaBackgroundList.append((canvas.getPageNumber(), pisa
width = pw # min(iw, pw) # max Background, self.backgroundContext))
wfactor = float(width) / iw
height = self.ph # min(ih, ph) # max
hfactor = float(height) / ih
factor_min = min(wfactor, hfactor)
if self.isPortrait():
self.w = iw * factor_min
self.h = ih * factor_min
canvas.drawImage(self.img, 0, self.ph - self.h, self
.w, self.h)
elif self.isLandscape():
factor_max = max(wfactor, hfactor)
self.h = ih * factor_max
self.w = iw * factor_min
canvas.drawImage(self.img, 0, 0, self.w, self.h)
except:
log.exception("Draw background")
# PDF!
else:
pisaBackground = self.pisaBackground
self.pisaBackgroundList.append(pisaBackground)
def pageNumbering(objList): def pageNumbering(objList):
for obj in flatten(objList): for obj in flatten(objList):
if isinstance(obj, PmlParagraph): if isinstance(obj, PmlParagraph):
for frag in obj.frags: for frag in obj.frags:
if frag.pageNumber: if frag.pageNumber:
frag.text = str(pagenumber) frag.text = str(pagenumber)
elif frag.pageCount: elif frag.pageCount:
frag.text = str(canvas._doctemplate._page_count) frag.text = str(canvas._doctemplate._page_count)
 End of changes. 3 change blocks. 
40 lines changed or deleted 20 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)