Exemplo n.º 1
0
def compile_src(marktex_src, template='presentation'):
    """
    Compiles the Marktex source to a temporary PDF and returns its path.
    """
    tex_src = templates[template](marktex_src)
    temp_id, pdf_path = tempfile.mkstemp(suffix='.pdf')
    generate_pdf(tex_src, pdf_path)
    return pdf_path
Exemplo n.º 2
0
def compile_src(marktex_src, template='presentation'):
    """
    Compiles the Marktex source to a temporary PDF and returns its path.
    """
    tex_src = templates[template](marktex_src)
    temp_id, pdf_path = tempfile.mkstemp(suffix='.pdf')
    generate_pdf(tex_src, pdf_path)
    return pdf_path
Exemplo n.º 3
0
def compile_file(marktex_file, template='presentation'):
    """
    Compiles the Marktex file at the given location to a similarly named PDF.
    """
    with open(marktex_file) as file:
        marktex_src = file.read()
        tex_src = templates[template](marktex_src)
        pdf_path = re.sub(r'\.\w+$', '.pdf', marktex_file)
        generate_pdf(tex_src, pdf_path)
    return pdf_path
Exemplo n.º 4
0
def compile_file(marktex_file, template='presentation'):
    """
    Compiles the Marktex file at the given location to a similarly named PDF.
    """
    with open(marktex_file) as file:
        marktex_src = file.read()
        tex_src = templates[template](marktex_src)
        pdf_path = re.sub(r'\.\w+$', '.pdf', marktex_file)
        generate_pdf(tex_src, pdf_path)
    return pdf_path
Exemplo n.º 5
0
    def get_pdf(self):

        out_folder = QFileDialog.getExistingDirectory(self, "Choose directory")
        path_out = out_folder + "/" + self.name
        self.path_out = path_out

        if (self.path != ""):
            img = cv2.imread(self.path)
            height, width, channels = img.shape
            generate_pdf(height, width,
                         text_out(self.path)[0],
                         shape_recreator(detct_shapes(text_out(self.path)[1])),
                         self.path_out)
            self.le.setText("Processd successfully!")
        else:
            self.le.setText("You should select a photo first!")
                                'cost':
                                float(tm['hoursDecimal']) *
                                float(rates_for_users_per_project[
                                    tm['person-id']][tm['project-id']]),
                            } for tm in time['time-entries']
                                        if tm['id'] in time_ids]
                            summ = round(
                                sum(map(lambda x: x['cost'], invoices)), 2)
                            generate_pdf(
                                generate_html({
                                    'name':
                                    name,
                                    'date':
                                    datetime.datetime.utcnow(),
                                    'invoices':
                                    invoices,
                                }), PDF_DIR,
                                '({summ} usd) Invoice {project} {name}.pdf'.
                                format(
                                    summ=str(summ).replace('.', ','),
                                    project=PROJECT,
                                    name=name,
                                ))
                        except Exception as exp:
                            log_error(
                                'Ошибка сохранения PDF (project {}, person {}): {}'
                                .format(PROJECT, name, exp))

                else:
                    log_error(
                        'Ошибка ответа от API (create invoice for time entries, project {}, person )! Аварийное завершение.'
Exemplo n.º 7
0
else:
    text_files = [f for f in glob.glob(os.path.join(book_path, '*.txt')) if not f.endswith('words.txt')]
    if text_files:
        VARS['CONTENT'] = latex_single(text_files[0], split_paragraphs, VARS['sections'], VARS['new_page_before_sections'])

sep_path = os.path.join(book_path, 'words.txt')
if os.path.isfile(sep_path):
    with open(sep_path, 'r') as f:
        hyphenation = ''
        for word in f.readlines():
            hyphenation += latex_hyphenation(word.strip())
        VARS['HYPHENATION'] = hyphenation

TEMPLATE = 'template.tex'

template = latex_env.get_template(TEMPLATE)

base_filename = VARS['BASE_FILENAME']
tex_file = filepath(book_path, base_filename, 'tex')

with open(tex_file, 'w') as f:
    f.write(template.render(**VARS))

if not args.only_tex:
    if args.pdf or not args.epub:
        pdf_file = generate_pdf(book_path, base_filename, tex_file)
        if args.booklet:
            generate_booklet(pdf_file, filepath(book_path, base_filename, 'booklet.pdf'))
    if args.epub:
        generate_epub(book_path, base_filename, tex_file)
Exemplo n.º 8
0
def generating_pdf():
    pdf.generate_pdf()
Exemplo n.º 9
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--BASE_FILENAME', default='default')
    parser.add_argument('book_path',
                        help='Carpeta con archivos para un libro.',
                        metavar='carpeta')
    parser.add_argument('--no-split',
                        help='No separar párrafos.',
                        action='store_true')
    parser.add_argument('--pdf',
                        help='Genera la versión pdf del libro.',
                        action='store_true')
    parser.add_argument('--booklet',
                        help='Genera la versión booklet del pdf.',
                        action='store_true')
    parser.add_argument('--epub',
                        help='Genera la versión epub del libro.',
                        action='store_true')
    parser.add_argument('--only-tex',
                        help='Solo genera el archivo latex.',
                        action='store_true')
    parser.add_argument(
        '--sections',
        help='Usar secciones en lugar de capítulos como elemento principal.',
        action='store_true')
    parser.add_argument(
        '--new-page-before-sections',
        help='Forzar página nueva en las secciones principales.',
        action='store_true')
    parser.add_argument('--TITLE', default='TITLE')
    parser.add_argument('--SUBTITLE', default='')
    parser.add_argument('--AUTHOR', default='AUTHOR')
    parser.add_argument('--FONT_SIZE', default=11)
    parser.add_argument('--PAGE_SIZE', default='a5paper')
    parser.add_argument('--YEAR', default=datetime.now().year)
    parser.add_argument('--URL', default='')
    parser.add_argument('--exclude-index', action='store_true')
    args = parser.parse_args()
    book_path = args.book_path

    class EmptyConfig(object):
        pass

    if not os.path.isdir(book_path):
        print('El argumento debe ser un directorio')
        exit()
    config_file = os.path.join(book_path, 'config.py')
    if os.path.isfile(config_file):
        config = imp.load_source('config', config_file)
    else:
        config = EmptyConfig()
        config.CONFIGS = {}

    VARS = DEFAULTS.copy()
    VARS.update(config.CONFIGS)
    for k, v in args._get_kwargs():
        if not VARS.get(k):
            VARS[k] = v

    index_path = os.path.join(book_path, 'index.txt')

    split_paragraphs = not VARS['no_split']
    if os.path.isfile(index_path):
        with open(index_path, 'r') as f:
            content = ''
            for filename in f.readlines():
                if VARS['no_split']:
                    content += latex_chapter(
                        os.path.join(book_path, filename).strip(),
                        split_paragraphs)
                else:
                    content += latex_single(
                        os.path.join(book_path,
                                     filename).strip(), split_paragraphs,
                        VARS['sections'], VARS['new_page_before_sections'])
            VARS['CONTENT'] = content
    else:
        text_files = [
            f for f in glob.glob(os.path.join(book_path, '*.txt'))
            if not f.endswith('words.txt')
        ]
        if text_files:
            VARS['CONTENT'] = latex_single(text_files[0], split_paragraphs,
                                           VARS['sections'],
                                           VARS['new_page_before_sections'])

    sep_path = os.path.join(book_path, 'words.txt')
    if os.path.isfile(sep_path):
        with open(sep_path, 'r') as f:
            hyphenation = ''
            for word in f.readlines():
                hyphenation += latex_hyphenation(word.strip())
            VARS['HYPHENATION'] = hyphenation

    TEMPLATE = 'template.tex'
    local_template_path = os.path.join(book_path, 'template.tex')
    if os.path.isfile(local_template_path):
        template = latex_env.from_string(open(local_template_path).read())
    else:
        template = latex_env.get_template(TEMPLATE)

    base_filename = VARS['BASE_FILENAME']
    tex_file = filepath(book_path, base_filename, 'tex')

    with open(tex_file, 'w') as f:
        f.write(template.render(**VARS))

    if not args.only_tex:
        if args.pdf or not args.epub:
            pdf_file = generate_pdf(book_path, base_filename, tex_file)
            if args.booklet:
                generate_booklet(
                    pdf_file, filepath(book_path, base_filename,
                                       'booklet.pdf'))
        if args.epub:
            generate_epub(book_path, base_filename, tex_file)