如何在 GtkPrintOperation 中设置自定义页面大小?
How can I set a custom page size in a GtkPrintOperation?
我正在使用 GtkPrintOperation 并且需要为 draw-page
信号自定义页面大小。
这是使用 python 的打印操作:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
print_op = Gtk.PrintOperation ()
print_op.run(Gtk.PrintOperationAction.PRINT_DIALOG, window)
设置自定义页面大小的方法如下:
def print_clicked (self, button):
paper_size = Gtk.PaperSize.new_custom("1.5x", "918 x 1188", 918, 1188, Gtk.Unit.POINTS)
page_setup = Gtk.PageSetup()
page_setup.set_paper_size(paper_size)
print_op = Gtk.PrintOperation ()
print_op.set_embed_page_setup(True)
print_op.set_default_page_setup(page_setup)
print_op.set_n_pages( 1) # single page
print_op.connect("draw-page", self.draw_page)
print_op.run(Gtk.PrintOperationAction.PRINT_DIALOG, window)
def draw_page (self, print_op, print_context, page_num):
cr = print_context.get_cairo_context()
#draw with cairo here
我正在使用 GtkPrintOperation 并且需要为 draw-page
信号自定义页面大小。
这是使用 python 的打印操作:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
print_op = Gtk.PrintOperation ()
print_op.run(Gtk.PrintOperationAction.PRINT_DIALOG, window)
设置自定义页面大小的方法如下:
def print_clicked (self, button):
paper_size = Gtk.PaperSize.new_custom("1.5x", "918 x 1188", 918, 1188, Gtk.Unit.POINTS)
page_setup = Gtk.PageSetup()
page_setup.set_paper_size(paper_size)
print_op = Gtk.PrintOperation ()
print_op.set_embed_page_setup(True)
print_op.set_default_page_setup(page_setup)
print_op.set_n_pages( 1) # single page
print_op.connect("draw-page", self.draw_page)
print_op.run(Gtk.PrintOperationAction.PRINT_DIALOG, window)
def draw_page (self, print_op, print_context, page_num):
cr = print_context.get_cairo_context()
#draw with cairo here