Using new gtk printing system - any way to use reportlab generated PDFs? Alternatively, a tutorial?

View: New views
2 Messages — Rating Filter:   Alert me  

Using new gtk printing system - any way to use reportlab generated PDFs? Alternatively, a tutorial?

by Thomas Mills Hinkle :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm interested in switching to the new gtk printing system (I still use gnomeprint for GNOME applications, LPR for gnome-lib-less linux users, and launching Adobe Acrobat to print PDF for Windows users). I can already get very nice PDF output using ReportLab -- is there any way I can just hand gnomeprint a PDF and have it handle the rest?

Alternatively, can anyone point me to a tutorial on the new printing system (even one in another language would be helpful). I've looked at the docs and the powerpoint from Guadec 2006, but I'd feel more comfortable if I had a hello-world style tutorial to help me see how I'd do basic text layout (e.g. I have some basic text I want to paginate and print).

Sorry if I missed an obvious link somewhere -- I did search through e-mail and the FAQ, but I'm sure I could have missed something simple.

Tom

_______________________________________________
pygtk mailing list   pygtk@...
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Re: Using new gtk printing system - any way to use reportlab generated PDFs? Alternatively, a tutorial?

by Thomas Mills Hinkle :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sat, Nov 8, 2008 at 9:54 AM, Thomas Mills Hinkle <tmhinkle@...> wrote:
I'm interested in switching to the new gtk printing system (I still use gnomeprint for GNOME applications, LPR for gnome-lib-less linux users, and launching Adobe Acrobat to print PDF for Windows users). I can already get very nice PDF output using ReportLab -- is there any way I can just hand gnomeprint a PDF and have it handle the rest?


In just under a year, I got back around to this problem and solved it for myself. The answer is libpoppler for python, which makes it easy to render a PDF to a cairo surface. That plus the testprint example (which appears a bit dated -- it has a number of calls that don't work), and I have a working solution in just about 25 lines.

In case anyone has my same question (just now googling for a solution my initial question was the top hit I found), here's the code:

import gtk
import poppler
import os.path

class PDFPrinter:

    def __init__ (self, fn):
        self.d = poppler.document_new_from_file(fn,None)
    
    def draw_page (self,operation, context, page_num):
        page = self.d.get_page(page_num)
        page.render_for_printing(context.get_cairo_context())
        
def setup_printer (pp):
    po = gtk.PrintOperation()
    po.set_n_pages(pp.d.get_n_pages())
    po.connect('draw_page',pp.draw_page)
    po.set_export_filename('/tmp/foo.pdf')
    po.run(gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG)

def print_pdf (pdf_filename):
    if not pdf_filename.startswith('file'):
        pdf_filename = 'file://' + os.path.realpath(pdf_filename)
    setup_printer(PDFPrinter(pdf_filename))

print_pdf(PATH_TO_FILE)

_______________________________________________
pygtk mailing list   pygtk@...
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/