示例#1
0
 def doit():
     with EbookIterator(sys.argv[-1]) as it:
         p = Printing(it, None)
         printer = QPrinter()
         of = sys.argv[-1]+'.pdf'
         printer.setOutputFileName(of)
         p.do_print(printer)
         print ('Printed to:', of)
         app.exit()
示例#2
0
 def doit():
     with EbookIterator(sys.argv[-1]) as it:
         p = Printing(it, None)
         printer = QPrinter()
         of = sys.argv[-1] + '.pdf'
         printer.setOutputFileName(of)
         p.do_print(printer)
         print('Printed to:', of)
         app.exit()
示例#3
0
def get_pdf_printer(opts, for_comic=False, output_file_name=None):
    from calibre.gui2 import is_ok_to_use_qt
    if not is_ok_to_use_qt():
        raise Exception('Not OK to use Qt')

    printer = QPrinter(QPrinter.HighResolution)
    custom_size = get_custom_size(opts)
    if isosx and not for_comic:
        # On OSX, the native engine can only produce a single page size
        # (usually A4). The Qt engine on the other hand produces image based
        # PDFs. If we set a custom page size using QSizeF the native engine
        # produces unreadable output, so we just ignore the custom size
        # settings.
        printer.setPaperSize(paper_size(opts.paper_size))
    else:
        if opts.output_profile.short_name == 'default' or \
                opts.output_profile.width > 9999:
            if custom_size is None:
                printer.setPaperSize(paper_size(opts.paper_size))
            else:
                printer.setPaperSize(QSizeF(custom_size[0], custom_size[1]),
                                     unit(opts.unit))
        else:
            w = opts.output_profile.comic_screen_size[0] if for_comic else \
                    opts.output_profile.width
            h = opts.output_profile.comic_screen_size[1] if for_comic else \
                    opts.output_profile.height
            dpi = opts.output_profile.dpi
            printer.setPaperSize(QSizeF(float(w) / dpi,
                                        float(h) / dpi), QPrinter.Inch)

    if for_comic:
        # Comic pages typically have their own margins, or their background
        # color is not white, in which case the margin looks bad
        printer.setPageMargins(0, 0, 0, 0, QPrinter.Point)
    else:
        printer.setPageMargins(opts.margin_left, opts.margin_top,
                               opts.margin_right, opts.margin_bottom,
                               QPrinter.Point)
    printer.setOrientation(orientation(opts.orientation))
    printer.setOutputFormat(QPrinter.PdfFormat)
    printer.setFullPage(for_comic)
    if output_file_name:
        printer.setOutputFileName(output_file_name)
    if isosx and not for_comic:
        # Ensure we are not generating enormous image based PDFs
        printer.setOutputFormat(QPrinter.NativeFormat)

    return printer
示例#4
0
文件: writer.py 项目: hashken/calibre
def get_pdf_printer(opts, for_comic=False, output_file_name=None):  # {{{
    from calibre.gui2 import is_ok_to_use_qt

    if not is_ok_to_use_qt():
        raise Exception("Not OK to use Qt")

    printer = QPrinter(QPrinter.HighResolution)
    custom_size = get_custom_size(opts)
    if isosx and not for_comic:
        # On OSX, the native engine can only produce a single page size
        # (usually A4). The Qt engine on the other hand produces image based
        # PDFs. If we set a custom page size using QSizeF the native engine
        # produces unreadable output, so we just ignore the custom size
        # settings.
        printer.setPaperSize(paper_size(opts.paper_size))
    else:
        if (
            opts.output_profile.short_name == "default"
            or opts.output_profile.width > 9999
            or opts.override_profile_size
        ):
            if custom_size is None:
                printer.setPaperSize(paper_size(opts.paper_size))
            else:
                printer.setPaperSize(QSizeF(custom_size[0], custom_size[1]), unit(opts.unit))
        else:
            w = opts.output_profile.comic_screen_size[0] if for_comic else opts.output_profile.width
            h = opts.output_profile.comic_screen_size[1] if for_comic else opts.output_profile.height
            dpi = opts.output_profile.dpi
            printer.setPaperSize(QSizeF(float(w) / dpi, float(h) / dpi), QPrinter.Inch)

    if for_comic:
        # Comic pages typically have their own margins, or their background
        # color is not white, in which case the margin looks bad
        printer.setPageMargins(0, 0, 0, 0, QPrinter.Point)
    else:
        printer.setPageMargins(opts.margin_left, opts.margin_top, opts.margin_right, opts.margin_bottom, QPrinter.Point)
    printer.setOutputFormat(QPrinter.PdfFormat)
    printer.setFullPage(for_comic)
    if output_file_name:
        printer.setOutputFileName(output_file_name)
    if isosx and not for_comic:
        # Ensure we are not generating enormous image based PDFs
        printer.setOutputFormat(QPrinter.NativeFormat)

    return printer
示例#5
0
data = json.loads(response.read())

app = QApplication([])

printer = QPrinter(QPrinter.HighResolution)
printer.setOutputFormat(QPrinter.PdfFormat)
printer.setPageSize(QPrinter.A6)
printer.setOrientation(QPrinter.Landscape)
printer.setPageMargins(0, 0, 0, 0, QPrinter.Millimeter)
printer.setFullPage(False)

bkgimg = QImage()
if not bkgimg.load("KosyMost.png", format="png"):
    print "Not loaded"

printer.setOutputFileName("contigo.pdf")

painter = QPainter(printer)

maxx = painter.device().width()
maxy = painter.device().height()

print "Wymiary: %d,%d" % (maxx, maxy)

q = QRectF(0, 2 * maxy / 10, maxx, 2 * maxy / 10)
a = QRectF(0, 4 * maxy / 10, maxx, 2 * maxy / 10)

penHText = QPen(QColor("#c60b1e"))

for qa in data['flashcards']:
    print "%s -> %s" % (qa['q'], qa['a'][0])