Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
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)
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).getFileName
)
dumpErrors(pdf)
if not pdf.err:
pisa.startViewer(dest)
def HTML2PDF(data, filename, open=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(
io.StringIO(data),
file(filename, "wb"))
if open and (not pdf.err):
pisa.startViewer(filename)
return not pdf.err
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)
path = config.TUTORIAL_PATH
if IS_WIN:
try:
from sas.sasgui.guiframe.pdfview import PDFFrame
dialog = PDFFrame(None, -1, "Tutorial", path)
# put icon
self.put_icon(dialog)
dialog.Show(True)
except:
logger.error("Error in _onTutorial: %s" % sys.exc_value)
try:
# Try an alternate method
logger.error(
"Could not open the tutorial pdf, trying xhtml2pdf")
from xhtml2pdf import pisa
pisa.startViewer(path)
except:
logger.error(
"Could not open the tutorial pdf with xhtml2pdf")
msg = "This feature requires 'PDF Viewer'\n"
wx.MessageBox(msg, 'Error')
else:
try:
command = "open '%s'" % path
os.system(command)
except:
try:
# Try an alternate method
logger.error(
"Could not open the tutorial pdf, trying xhtml2pdf")
from xhtml2pdf import pisa
pisa.startViewer(path)