Esempio n. 1
0
 def pdf(self):
     return PDFStreamer(
         HTMLParser(self.generate, CSS("".join(self.css))),
         os.path.join(settings.MEDIA_ROOT,
                      self.letterhead.letterhead_pdf.name)
         if self.format == "email" else None,
     )
Esempio n. 2
0
 def test_html_to_pdf(self):
     output = BytesIO()
     for chunk in PDFStreamer(HTMLParser(self.html, CSS(''))):
         output.write(chunk)
     pdf = PdfReader(fdata=output.getvalue())
     self.assertEqual(pdf['/Info']['/Producer'], '(bericht)')
     self.assertEqual(pdf['/Root']['/Pages']['/Count'], '3')
Esempio n. 3
0
 def pdf(self):
     return PDFStreamer(
         HTMLParser(self.generate, CSS(self.css)),
         os.path.join(settings.MEDIA_ROOT,
                      self.letterhead.letterhead_pdf.name),
         "landscape",
     )
Esempio n. 4
0
from bericht.html import HTMLParser, CSS
from bericht.pdf import PDFStreamer

css = CSS("""

""")


def html():
    yield """
<p>Some descriptive text for the table.</p>
<br>
<table>
  <tr>
    <td><i>Some <b>people</b> don't like change, but you need to
        embrace change if the alternative is <b>disaster</b>.</i>
    <td>People <b>work</b> better when they know what the goal is
        and why. It is important that people look forward
        to coming to <b>work</b> in the morning and enjoy <b>work</b>ing.
  <tr>
    <td colspan="2">
    Alright, thank you. <br/>
    So, I’ve got about apparently I’ve got about five to six minutes to say the most useful things I can think of. <br/>
    I’m gonna do my best. <br/>
    It was suggested that I distill things down to 3 items. <br/>
    I think I’ll go with four. <br/>
    And I’ll try, I think, I think these are pretty important ones. <br/>
    Some of it may kinda sound like, well you’ve heard them before. <br/>
    But, you know, worth reemphasizing. <br/>
    <br/>
    I think the first is, you need to <b>work</b>, if you, depending on how well you want to do, <br/>
Esempio n. 5
0
css = CSS("""
.collapse {
  border-collapse: collapse;
}

.separate {
  border-collapse: separate;
}

table {
  margin: 5px;
  border-style: dashed;
  border-width: 5px;
}

table th,
table td {
  border-style: solid;
  border-width: 3px;
}

.fx { border-color: orange blue; }
.gk { border-color: black red; }
.ed { border-color: blue gold; }
.tr { border-color: aqua; }
.sa { border-color: silver blue; }
.wk { border-color: gold blue; }
.ch { border-color: red yellow green blue; }
.bk { border-color: navy blue teal aqua; }
.op { border-color: red; }
""")
Esempio n. 6
0
def parse_html(html, css=None):
    return HTMLParser(lambda: iter(html if isinstance(html, list) else [html]),
                      css if isinstance(css, CSS) else CSS(css or ''))