Esempio n. 1
0
def testURL(
    url="http://www.htmltopdf.org",
    dest="test-website.pdf"):

    """
    Loading from an URL. We open a file like object for the URL by
    using 'urllib'. If there have to be loaded more data from the web,
    the pisaLinkLoader helper is passed as 'link_callback'. The
    pisaLinkLoader creates temporary files for everything it loads, because
    the Reportlab Toolkit needs real filenames for images and stuff. Then
    we also pass the url as 'path' for relative path calculations.
    """
    import urllib

    pdf = pisa.CreatePDF(
        urllib.urlopen(url),
        file(dest, "wb"),
        log_warn = 1,
        log_err = 1,
        path = url,
        link_callback = pisa.PisaLinkLoader(url).get_file_name
        )

    dumpErrors(pdf)
    if not pdf.err:
        pisa.startViewer(dest)
Esempio n. 2
0
def testURL(
    url="http://www.htmltopdf.org",
    dest="test-website.pdf"):

    """
    Loading from an URL. We open a file like object for the URL by
    using 'urllib'. If there have to be loaded more data from the web,
    the pisaLinkLoader helper is passed as 'link_callback'. The
    pisaLinkLoader creates temporary files for everything it loads, because
    the Reportlab Toolkit needs real filenames for images and stuff. Then
    we also pass the url as 'path' for relative path calculations.
    """
    import urllib.request, urllib.parse, urllib.error

    pdf = pisa.CreatePDF(
        urllib.request.urlopen(url),
        file(dest, "wb"),
        log_warn = 1,
        log_err = 1,
        path = url,
        link_callback = pisa.pisaLinkLoader(url).getFileName
        )

    dumpErrors(pdf)
    if not pdf.err:
        pisa.startViewer(dest)
Esempio n. 3
0
def helloWorld():
	filename = __file__ + ".pdf"                
	p = "hello"

	pdf = pisa.CreatePDF(p,file(filename, "wb"))
	if not pdf.err:                             
		pisa.startViewer(filename)               
Esempio n. 4
0
def testSimple(dest="test.pdf"):
    data = """

<style type="text/css">
.tftable {font-size:12px;color:#333333;width:100%;border-width: 1px;border-color: #729ea5;border-collapse: collapse;}
.tftable th {font-size:12px;background-color:#acc8cc;border-width: 1px;padding: 8px;border-style: solid;border-color: #729ea5;text-align:left;}
.tftable tr {background-color:#d4e3e5;}
.tftable td {font-size:12px;border-width: 1px;padding: 8px;border-style: solid;border-color: #729ea5;}
.tftable tr:hover {background-color:#ffffff;}
</style>

<table class="tftable" border="1">
<tr><th>Header 1</th><th>Header 2</th><th>Header 3</th><th>Header 4</th><th>Header 5</th></tr>
<tr><td>Row:1 Cell:1</td><td>Row:1 Cell:2aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</td><td>Row:1 Cell:3</td><td>Row:1 Cell:4</td><td>Row:1 Cell:5</td></tr>
<tr><td>Row:2 Cell:1</td><td>Row:2 Cell:2</td><td>Row:2 Cell:3</td><td>Row:2 Cell:4</td><td>Row:2 Cell:5</td></tr>
<tr><td>Row:3 Cell:1</td><td>Row:3 Cell:2</td><td>Row:3 Cell:3</td><td>Row:3 Cell:4</td><td>Row:3 Cell:5</td></tr>
<tr><td>Row:4 Cell:1</td><td>Row:4 Cell:2</td><td>Row:4 Cell:3</td><td>Row:4 Cell:4</td><td>Row:4 Cell:5</td></tr>
<tr><td>Row:5 Cell:1</td><td>Row:5 Cell:2</td><td>Row:5 Cell:3</td><td>Row:5 Cell:4</td><td>Row:5 Cell:5</td></tr>
<tr><td>Row:6 Cell:1</td><td>Row:6 Cell:2</td><td>Row:6 Cell:3</td><td>Row:6 Cell:4</td><td>Row:6 Cell:5</td></tr>
</table>

<p><small>365 Monitoreo C.A<a href="http://365monitoreo.com" target="_blank">http://365monitoreo.com</a></small></p>"""
    """
    Simple test showing how to create a PDF file from
    PML Source String. Also shows errors and tries to start
    the resulting PDF
    """

    pdf = pisa.CreatePDF(cStringIO.StringIO(data), file(dest, "wb"))

    if pdf.err:
        dumpErrors(pdf)
    else:
        pisa.startViewer(dest)
Esempio n. 5
0
def minutesHtmlToPdf(html_string, name_pdf, css_string):
    pdf_address = "/pdf/%s_Actarium%s.pdf" % (
        name_pdf, int(random.random() * 100000))
    file_dir = "%s%s" % (MEDIA_ROOT, pdf_address)
    file_dir = open(file_dir, "w+b")
    try:
        showLogging() 
        pdf = CreatePDF(html_string, file_dir, default_css=css_string)
        if not pdf.err:
            startViewer(name_pdf)
    except Exception, e:
        print e
        return False
Esempio n. 6
0
def html2pdf(data, filename, open_file=False):
    """
    Simple test showing how to create a PDF file from
    PML Source String. Also shows errors and tries to start
    the resulting PDF
    """

    pdf = pisa.CreatePDF(StringIO.StringIO(data), file(filename, "wb"))

    if open_file and (not pdf.err):
        pisa.startViewer(filename)

    return not pdf.err
Esempio n. 7
0
def testBackgroundAndImage(src="test-background.html", dest="test-background.pdf"):

    """
    Simple test showing how to create a PDF file from
    PML Source String. Also shows errors and tries to start
    the resulting PDF
    """

    pdf = pisa.CreatePDF(file(src, "r"), file(dest, "wb"), log_warn=1, log_err=1, path=os.path.join(os.getcwd(), src))

    dumpErrors(pdf)
    if not pdf.err:
        pisa.startViewer(dest)
Esempio n. 8
0
def testSimple(data="""Hello <b>World</b><br/><img src="img/test.jpg"/>""",
               dest="test.pdf"):
    """
    Simple test showing how to create a PDF file from
    PML Source String. Also shows errors and tries to start
    the resulting PDF
    """

    pdf = pisa.CreatePDF(cStringIO.StringIO(data), file(dest, "wb"))

    if pdf.err:
        dumpErrors(pdf)
    else:
        pisa.startViewer(dest)
Esempio n. 9
0
def HTML2PDF(data, filename, open_file=False):

    """
    Simple test showing how to create a PDF file from
    PML Source String. Also shows errors and tries to start
    the resulting PDF
    """

    pdf = pisa.CreatePDF(StringIO(data), open(filename, "wb"))

    if open_file and (not pdf.err):
        pisa.startViewer(filename)

    return not pdf.err
Esempio n. 10
0
def testSimple(data="""Hello <b>World</b><br/><img src="img/test.jpg"/>""", dest="test.pdf"):

    """
    Simple test showing how to create a PDF file from
    PML Source String. Also shows errors and tries to start
    the resulting PDF
    """

    pdf = pisa.CreatePDF(cStringIO.StringIO(data), file(dest, "wb"))

    if pdf.err:
        dumpErrors(pdf)
    else:
        pisa.startViewer(dest)
Esempio n. 11
0
	def generate_reportPDF(self, template_name, dest_file, context, timestamp=false):
		# add in case for district vs immunization unit
		html = template.render( context )
		
		# add in boolean for timestamp!
		if(timestamp) {
			filename = os.path.dirname(os.path.realpath(__file__)) + "/pdf-reports/testPDF" + datetime.now() + ".pdf"
		} else {
			filename = os.path.dirname(os.path.realpath(__file__)) + "/pdf-reports/testPDF.pdf"
		}
		filename.replace(" ", "_")
		pdf = pisa.CreatePDF(
			src=html,
			dest=file(filename, "wb"))
		if not pdf.err:
			pisa.startViewer(filename)
Esempio n. 12
0
def htmlToPdf(html_string, pdf_name):
    from django.template.defaultfilters import slugify
    import datetime
    pdf_address = "pdf/%s_%s_%s.pdf" % (
                    slugify(pdf_name),
                    slugify(settings.PROJECT_NAME),
                    datetime.datetime.now().strftime("%Y-%m-%d_%H-%M")
                    )
    file_dir = "%s/%s" % (settings.MEDIA_ROOT, pdf_address)
    file_dir = file(file_dir, "wb")
    pdf = CreatePDF(html_string, file_dir)
                    #, default_css="#minute{margin:200px}")
    if not pdf.err:
        startViewer(pdf_name)
    file_dir.close()
    return '%s%s' % (settings.MEDIA_URL, pdf_address)
Esempio n. 13
0
	def openPDF(self):
		data = 2
		district_name="Pune"
		curdate = datetime.now()
		template = get_template('pdf_report_base.html')
		context = Context({ 'data' : data,
							'district_name' : district_name,
							'date' : curdate })
		html  = template.render( context )
		
		# add in boolean for timestamp!
		filename = os.path.dirname(os.path.realpath(__file__)) + "/pdf-reports/testPDF.pdf"
		pdf = pisa.CreatePDF(
			src=html,
			dest=file(filename, "wb"))
		if not pdf.err:
			pisa.startViewer(filename)
Esempio n. 14
0
def testBackgroundAndImage(src="test-background.html",
                           dest="test-background.pdf"):
    """
    Simple test showing how to create a PDF file from
    PML Source String. Also shows errors and tries to start
    the resulting PDF
    """

    pdf = pisa.CreatePDF(file(src, "r"),
                         file(dest, "wb"),
                         log_warn=1,
                         log_err=1,
                         path=os.path.join(os.getcwd(), src))

    dumpErrors(pdf)
    if not pdf.err:
        pisa.startViewer(dest)
Esempio n. 15
0
def pasarPDF(datos, outputFilename, nombrePrueba, descripcion, inumeroPregunta,
             idescripcion):
    htmlcode = txtToHtml(datos, nombrePrueba, descripcion, inumeroPregunta,
                         idescripcion)
    convertHtmlToPdf(htmlcode, outputFilename)
    pisa.startViewer(outputFilename)