Esempio n. 1
0
def save_pdf(component, path=None, default_directory=None, view=False, options=None):
    if default_directory is None:
        default_directory = os.path.join(os.path.expanduser("~"), "Documents")

    ok = True
    if options is None:
        ok = False
        options = FigurePDFOptions()
        options.load()
        dlg = SavePDFDialog(model=options)
        info = dlg.edit_traits(kind="livemodal")
        # path = '/Users/ross/Documents/pdftest.pdf'
        if info.result:
            options.dump()
            ok = True
    if ok:
        if path is None:
            dlg = FileDialog(action="save as", default_directory=default_directory)

            if dlg.open() == OK:
                path = dlg.path

        if path:

            path = add_extension(path, ".pdf")
            gc = PdfPlotGraphicsContext(filename=path, dest_box=options.dest_box, pagesize=options.page_size)
            # component.inset_border = False
            # component.padding = 0
            # component.border_visible = True
            # component.border_width = 2
            # component.fill_padding = True
            # component.bgcolor = 'green'
            obounds = component.bounds
            size = None
            if not obounds[0] and not obounds[1]:
                size = options.bounds

            if options.fit_to_page:
                size = options.bounds

            component.do_layout(size=size, force=True)
            gc.render_component(component, valign="center")
            gc.save()
            if view:
                view_file(path)
            component.do_layout(size=obounds, force=True)
Esempio n. 2
0
def save_pdf(component,
             path=None,
             default_directory=None,
             view=False,
             options=None):
    if default_directory is None:
        default_directory = os.path.join(os.path.expanduser('~'), 'Documents')

    ok = True
    if options is None:
        ok = False
        options = FigurePDFOptions()
        options.load()
        dlg = SavePDFDialog(model=options)
        info = dlg.edit_traits(kind='livemodal')
        # path = '/Users/ross/Documents/pdftest.pdf'
        if info.result:
            options.dump()
            ok = True
    if ok:
        if path is None:
            dlg = FileDialog(action='save as',
                             default_directory=default_directory)

            if dlg.open() == OK:
                path = dlg.path

        if path:

            path = add_extension(path, '.pdf')
            gc = PdfPlotGraphicsContext(filename=path,
                                        dest_box=options.dest_box,
                                        pagesize=options.page_size)
            # component.inset_border = False
            # component.padding = 0
            # component.border_visible = True
            # component.border_width = 2
            # component.fill_padding = True
            # component.bgcolor = 'green'
            obounds = component.bounds
            size = None
            if not obounds[0] and not obounds[1]:
                size = options.bounds

            if options.fit_to_page:
                size = options.bounds

            component.do_layout(size=size, force=True)
            gc.render_component(component, valign='center')
            gc.save()
            if view:
                view_file(path)
            component.do_layout(size=obounds, force=True)
Esempio n. 3
0
 def save_tray_pdf(self):
     p = os.path.join(paths.loading_dir, self.tray)
     gc = PdfPlotGraphicsContext(filename=p)
     gc.render_component(self.canvas)
     gc.save()
Esempio n. 4
0
 def save_tray_pdf(self):
     p = os.path.join(paths.loading_dir, self.tray)
     gc = PdfPlotGraphicsContext(filename=p)
     gc.render_component(self.canvas)
     gc.save()