def main(): """Generate a PDF using the async method.""" docraptor = DocRaptor() print("Create PDF") resp = docraptor.create({ "document_content": "<h1>python-docraptor</h1><p>Async Test</p>", "test": True, "async": True, }) print("Status ID: {status_id}".format(status_id=resp["status_id"])) status_id = resp["status_id"] resp = docraptor.status(status_id) print(" {status}".format(status=resp["status"])) while resp["status"] != "completed": time.sleep(3) resp = docraptor.status(status_id) print(" {status}".format(status=resp["status"])) print("Download to test_async.pdf") with open("test_async.pdf", "wb") as pdf_file: pdf_file.write(docraptor.download(resp["download_key"]).content) print("[DONE]")
def main(): """Generate a PDF using the async method.""" docraptor = DocRaptor() print("Create PDF") resp = docraptor.create( { "document_content": "<h1>python-docraptor</h1><p>Async Test</p>", "test": True, "async": True, } ) print("Status ID: {status_id}".format(status_id=resp["status_id"])) status_id = resp["status_id"] resp = docraptor.status(status_id) print(" {status}".format(status=resp["status"])) while resp["status"] != "completed": time.sleep(3) resp = docraptor.status(status_id) print(" {status}".format(status=resp["status"])) print("Download to test_async.pdf") with open("test_async.pdf", "wb") as pdf_file: pdf_file.write(docraptor.download(resp["download_key"]).content) print("[DONE]")
def generate_pdf(request): #return HttpResponse(os.getcwd()) response = HttpResponse(mimetype='application/pdf') response['Content-Disposition'] = 'attachment; filename=somefilename.pdf' docraptor = DocRaptor('yBXuHoCGqUDOjJ2MrWmv') userprof = UserProfile.objects.get(user=request.user) if request.POST .get('side') == "L": sg = StudyGuide.objects.get(title_id=userprof.current_guide) else: sg = StudyGuide.objects.get(title_id=userprof.current_guide2) images = PersonalImageNote.objects.filter(guide=sg) text = TextNote.objects.filter(guide=sg) html = "<html><body>" for t in text: if t.text is not None: html += str(t.text) for note in images: html += "<img src='http://ujungo.com/media/%s' STYLE='position:absolute; TOP:%spx; LEFT:%spx; WIDTH:%spx; HEIGHT:%spx' />" % (note.image.image,note.ycoord, note.xcoord, note.width, note.height) # STYLE='position:absolute; TOP:{{note.ycoord}}px; LEFT:{{note.xcoord}}px; WIDTH:{{note.width}}px; HEIGHT:{{note.height}}px' #html = html.replace(" ","") html += "</body></html>" print html with open("/usr/local/src/testsheets/media/%s.pdf" % sg.title_id, "wb") as f: f.write(docraptor.create({ 'document_content': html, 'test': True, 'api_key': 'yBXuHoCGqUDOjJ2MrWmv' }).content) return HttpResponse(sg.title_id)
def main(): """Generate a PDF with specified url.""" docraptor = DocRaptor() print("Create test_basic_url.pdf") with open("test_basic_url.pdf", "wb") as pdf_file: pdf_file.write( docraptor.create({ "document_url": "http://docraptor.com", "test": True }).content)
def main(): """Generate a PDF with specified url.""" docraptor = DocRaptor() print("Create test_basic_url.pdf") with open("test_basic_url.pdf", "wb") as pdf_file: pdf_file.write( docraptor.create( {"document_url": "http://docraptor.com", "test": True} ).content )
def main(): """Generate a PDF with specified content.""" docraptor = DocRaptor() print("Create test_basic_content.pdf") with open("test_basic_content.pdf", "wb") as pdf_file: pdf_file.write( docraptor.create({ "document_content": "<h1>python-docraptor</h1><p>Basic Test</p>", "test": True, }).content)
def main(): """Generate a PDF with specified content.""" docraptor = DocRaptor() print("Create test_basic_content.pdf") with open("test_basic_content.pdf", "wb") as pdf_file: pdf_file.write( docraptor.create( { "document_content": "<h1>python-docraptor</h1><p>Basic Test</p>", "test": True, } ).content )
def main(): """Generate an XLS with specified content.""" table = """<table> <thead> <tr><th>First Name</th><th>Last Name</th></tr> </thead> <tbody> <tr><td>Paul</td><td>McGrath</td></tr> <tr><td>Liam</td><td>Brady</td></tr> <tr><td>John</td><td>Giles</td></tr> </tbody> </table>""" docraptor = DocRaptor() print("Create test_basic.xls") with open("test_basic.xls", "wb") as pdf_file: pdf_file.write( docraptor.create( {"document_content": table, "document_type": "xls", "test": True} ).content )
import time from docraptor import DocRaptor docraptor = DocRaptor() print "Create PDF" resp = docraptor.create({ 'document_content': '<h1>python-docraptor</h1><p>Async Test</p>', 'test': True, 'async': True }) print "Status ID: %s" % (resp['status_id']) status_id = resp['status_id'] resp = docraptor.status(status_id) print " %s" % (resp['status']) while resp['status'] != 'completed': time.sleep(3) resp = docraptor.status(status_id) print " %s" % (resp['status']) print "Download to test_async.pdf", with open("test_async.pdf", "wb") as f: f.write(docraptor.download(resp['download_key']).content) print "[DONE]"
import time from docraptor import DocRaptor docraptor = DocRaptor() print "Create test_basic_content.pdf" with open("test_basic_content.pdf", "wb") as f: f.write(docraptor.create({ 'document_content': '<h1>python-docraptor</h1><p>Basic Test</p>', 'test': True }).content)
import time from docraptor import DocRaptor table = """<table> <thead> <tr><th>First Name</th><th>Last Name</th></tr> </thead> <tbody> <tr><td>Paul</td><td>McGrath</td></tr> <tr><td>Liam</td><td>Brady</td></tr> <tr><td>John</td><td>Giles</td></tr> </tbody> </table>""" docraptor = DocRaptor() print "Create test_basic.xls" with open("test_basic.xls", "wb") as f: f.write(docraptor.create({ 'document_content': table, 'document_type': 'xls', 'test': True }).content)
import time from docraptor import DocRaptor docraptor = DocRaptor() print "Create test_basic_url.pdf" with open("test_basic_url.pdf", "wb") as f: f.write(docraptor.create({ 'document_url': 'http://docraptor.com', 'test': True }).content)
</style> </head> <body> <div class="page"> <h1>Hello, world!</h1> </div> <div class="page"> <h1>Hello, from page 2!</h1> </div> </body> </html> """ docraptor = DocRaptor(os.environ['DOCRAPTOR_KEY']) results = docraptor.create({ 'document_content': content, 'test': True, 'javascript': True, }) with open("docraptor_sample.pdf", "wb") as f: f.write(results.content)