9832

Using Reportlab Canvas- How to create an Option to print the pdf generated from the browser itself?

Question:

Here is the code which generates pdf for me using Reportlab.

Now, it just shows the pdf in the browser, and after including 'attachment' in the resonse.header ['Content-Disposition'], it downloads the pdf.

But what i want is the rint option which comes you in the browser, which even allows you to choose your printer. is it possible ?

data = "raghav" p = canvas.Canvas(self.response.out) p.drawString(50, 700, data) p.showPage() self.response.headers['Content-Type'] = 'application/pdf' self.response.headers['Content-Disposition'] = 'attachment;filename=testpdf.pdf' p.save()

Answer1:

according to <a href="http://blog.adlibre.org/2012/04/05/automatically-print-pdf-generated-reportlab/" rel="nofollow">http://blog.adlibre.org/2012/04/05/automatically-print-pdf-generated-reportlab/</a> you can add these two lines to get the desired result:

from reportlab.pdfbase import pdfdoc pdfdoc.PDFCatalog.OpenAction = '<</S/JavaScript/JS(this.print\({bUI:true,bSilent:false,bShrinkToFit:true}\);)>>'

hope it helps :)

Recommend

  • Print Report directly on JasperReports Server
  • How to determine printer's postscript support using Win32 API?
  • Convert DOC to PDF [closed]
  • Why does this use of getImageData leak memory
  • Differences between drawing an Ellipse in Android and Java
  • How to separate filename from path? basename() versus preg_split() with array_pop()
  • Read a file in “chunks” using PHP
  • How to set download location via chrome api
  • Remove previous Directions Route Google Maps
  • write text on image and show it to a imageview
  • removing last 3 characters on a file (file extension)
  • How to open html table in xls on click of a button
  • C# Excel interop - how to test if interop object is still working and performing a task?
  • How to draw a line dynamically in android [duplicate]
  • Adding Object or changing its parameter programmatically in C# / ASP.Net
  • Write output of for loop to multiple files
  • Error processing multiple files
  • Tell Git to stop prompting me for conflicts when none really exist?
  • How do I display a dialog that asks the user multi-choice questıon using tkInter?
  • msbuild create itemgroup from property group
  • List images(01.png) and descriptions(01.txt) from directory
  • how to upload multiple files in c# windows application
  • Chart.js Multiple dataset
  • How to install a .deb file on a jailbroken iphone programmatically?
  • Handling un-mapped Rest path
  • Scrapy recursive link crawler
  • How to rebase a series of branches?
  • Why HTML5 Canvas with a larger size stretch a drawn line?
  • Sending data from AppleScript to FileMaker records
  • Is there a mandatory requirement to switch app.yaml?
  • File upload with ng-file-upload throwing error
  • ExecuteAsync RestSharp to allow backgroundWorker CancellationPending c#
  • How to include full .NET prerequisite for Wix Burn installer
  • AngularJs get employee from factory
  • Is it possible to post an object from jquery to bottle.py?
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • reshape alternating columns in less time and using less memory
  • How can I use `wmic` in a Windows PE script?
  • Unable to use reactive element in my shiny app
  • Android Heatmap on canvas or ImageView