当前位置: 首页>>代码示例>>Python>>正文


Python Document.generate_pdf方法代码示例

本文整理汇总了Python中pylatex.Document.generate_pdf方法的典型用法代码示例。如果您正苦于以下问题:Python Document.generate_pdf方法的具体用法?Python Document.generate_pdf怎么用?Python Document.generate_pdf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pylatex.Document的用法示例。


在下文中一共展示了Document.generate_pdf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_document

# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import generate_pdf [as 别名]
def test_document():
    geometry_options = {
        "includeheadfoot": True,
        "headheight": "12pt",
        "headsep": "10pt",
        "landscape": True
    }

    doc = Document(
        default_filepath='default_filepath',
        documentclass='article',
        fontenc='T1',
        inputenc='utf8',
        lmodern=True,
        data=None,
        page_numbers=True,
        indent=False,
        document_options=["a4paper", "12pt"],
        geometry_options=geometry_options
    )

    repr(doc)

    doc.append('Some text.')
    doc.change_page_style(style="empty")
    doc.change_document_style(style="plain")
    doc.add_color(name="lightgray", model="gray", description="0.6")
    doc.add_color(name="abitless", model="gray", description="0.8")
    doc.set_variable(name="myVar", value="1234")
    doc.set_variable(name="myVar", value="1234")
    doc.change_length(parameter=r"\headheight", value="0.5in")

    doc.generate_tex(filepath='')
    doc.generate_pdf(filepath='', clean=True)
开发者ID:vovchikthebest,项目名称:PyLaTeX,代码行数:36,代码来源:args.py

示例2: arxiv_search

# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import generate_pdf [as 别名]
def arxiv_search(search_query):

    url = 'http://export.arxiv.org/api/query?search_query=all:' + \
        search_query + '&start=0&max_results=5'
    data = urllib.request.urlopen(url).read()

    soup = bs(data, features='xml')
    title_array = []
    summary_array = []

    for i in soup.findAll('title'):
        title_array.append(i)

    for i in soup.findAll('summary'):
        summary_array.append(i)

    doc = Document()
    doc.packages.append(
        Package(
            'geometry',
            options=[
                'tmargin=1cm',
                'lmargin=1cm',
                'rmargin=1cm']))

    with doc.create(Section('Search results for \"' + search_query + '\"')):

        for i in range(1, 5):
            doc.append(Subsection(italic(title_array[i].string)))
            doc.append(summary_array[i].string)

    doc.generate_pdf()
开发者ID:arecibokck,项目名称:Moonlight,代码行数:34,代码来源:arxiv.py

示例3: test

# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import generate_pdf [as 别名]
def test():
    doc = Document("multirow_cm")

    with doc.create(Section('Multirow Test')):
        with doc.create(Subsection('Multicol')):
            # we need to keep track of the object here
            with doc.create(Tabular('|c|c|')) as table1:
                table1.add_hline()
                table1.add_multicolumn(2, '|c|', 'Multicol')
                table1.add_hline()
                table1.add_row((1, 2))
                table1.add_hline()
                table1.add_row((3, 4))
                table1.add_hline()

        with doc.create(Subsection('Multirow')):
            with doc.create(Tabular('|c|c|c|')) as table2:
                table2.add_hline()
                table2.add_multirow(3, '*', 'Multirow', cells=((1, 2), (3, 4),
                                                               (5, 6)))
                table2.add_hline()
                table2.add_multirow(3, '*', 'Multirow2')
                table2.add_hline()

    doc.generate_pdf()
开发者ID:votti,项目名称:PyLaTeX,代码行数:27,代码来源:multirow_test_cm.py

示例4: generate_info_report

# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import generate_pdf [as 别名]
def generate_info_report():
			"""
			Generate a report with cover, status und last 2 lines in log for every test
			"""

			## Define the geometry for LaTeX files
			geometry_options = {
					"head": "40pt",
					"margin": "0.5in",
					"bottom": "0.6in",
					"includeheadfoot": True
				}


			## Create the LaTeX object, a instance of Document Class
			doc = Document(documentclass='article', geometry_options=geometry_options)

			## Add cover
			generate_cover2(doc)
			doc.append(NewPage())

			## Add status table
			generate_status_tabel(doc)
			doc.append(NewPage())

			## Add last 2 lines in log.txt
			for i in range(1, 4):
					generate_info_list(doc, i)


			doc.generate_pdf("RiMEA-Projekt Analyse", clean_tex=False)
开发者ID:JuPedSim,项目名称:jpscore,代码行数:33,代码来源:reportscript.py

示例5: circuit_to_pdf_using_qcircuit_via_tex

# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import generate_pdf [as 别名]
def circuit_to_pdf_using_qcircuit_via_tex(circuit: circuits.Circuit,
                                          filepath: str,
                                          pdf_kwargs=None,
                                          qcircuit_kwargs=None,
                                          clean_ext=('dvi', 'ps'),
                                          documentclass='article'):
    """Compiles the QCircuit-based latex diagram of the given circuit.

    Args:
        circuit: The circuit to produce a pdf of.
        filepath: Where to output the pdf.
        pdf_kwargs: The arguments to pass to generate_pdf.
        qcircuit_kwargs: The arguments to pass to
            circuit_to_latex_using_qcircuit.
        clean_ext: The file extensions to clean up after compilation. By
            default, latexmk is used with the '-pdfps' flag, which produces
            intermediary dvi and ps files.
        documentclass: The documentclass of the latex file.
    """
    pdf_kwargs = {'compiler': 'latexmk', 'compiler_args': ['-pdfps'],
                  **({} if pdf_kwargs is None else pdf_kwargs)}
    qcircuit_kwargs = {} if qcircuit_kwargs is None else qcircuit_kwargs
    tex = circuit_to_latex_using_qcircuit(circuit, **qcircuit_kwargs)
    doc = Document(documentclass=documentclass, document_options='dvips')
    doc.packages.append(Package('amsmath'))
    doc.packages.append(Package('qcircuit'))
    doc.append(NoEscape(tex))
    doc.generate_pdf(filepath, **pdf_kwargs)
    for ext in clean_ext:
        try:
            os.remove(filepath + '.' + ext)
        except (OSError, IOError) as e:
            if e.errno != errno.ENOENT:
                raise
开发者ID:google2013,项目名称:Cirq,代码行数:36,代码来源:qcircuit_pdf.py

示例6: test

# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import generate_pdf [as 别名]
def test():
    doc = Document("utils_escape_latex")
    section = Section('Escape LaTeX characters test')

    text = escape_latex('''\
    & (ampersand)
    % (percent)
    $ (dollar)
    # (number)
    _ (underscore)
    { (left curly brace)
    } (right curly brace)
    ~ (tilde)
    ^ (caret)
    \\ (backslash)
    --- (three minuses)
    a\xA0a (non breaking space)
    [ (left bracket)
    ] (right bracket)
    ''')

    section.append(text)
    doc.append(section)

    doc.generate_pdf()
开发者ID:JelteF,项目名称:PyLaTeX,代码行数:27,代码来源:test_utils_escape_latex.py

示例7: build_document

# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import generate_pdf [as 别名]
def build_document(transcript):
    """
    Processes a Transcript object to build a LaTeX document.
    """
    # Open temporary file
    doc = Document(documentclass='scrartcl', title=transcript.title,
                   subtitle=transcript.school,
                   author=transcript.student,
                   date=transcript.date.strftime('%d %B %Y'), temporary=True)

    doc.packages.append(Package('geometry', option='margin=1.0in'))
    doc.preamble.append(Command('renewcommand', argument=['\\familydefault', '\\sfdefault']))

    doc.append(Command('maketitle'))

    # Iterate through each transcript section
    for t_section in transcript.sections:
        # Create new section
        s = Section(escape_latex(t_section.title))
        # Add content to section
        for s_line in t_section.content:
            s_line = '\t'.join(s_line)
            s.append(escape_latex(s_line) + ' \\\n')

        # Add subsections to section
        for t_subsection in t_section.subsections:
            ss = Subsection(escape_latex(t_subsection.title))
            num_cols = max(len(l) for l in t_subsection.content)
            ss_table = Table(' l ' * num_cols)
            # Add content to subsection
            for ss_line in t_subsection.content:

                ss_line = '\t'.join(ss_line)
                if ss_line.startswith('Course Topic'):
                    ss_table.append('&')
                    ss_table.add_multicolumn(num_cols-1, 'l',
                                             escape_latex(ss_line))
                    ss_table.append(r'\\')
                elif not ss_line[:3].isupper() and not ss_line.startswith('Test'):
                    ss_table.add_multicolumn(num_cols, 'l', escape_latex(ss_line))
                    ss_table.append(r'\\')
                else:
                    if ss_line.startswith('TERM'):
                        ss_table.add_hline()
                    filled = escape_latex(ss_line).split('\t')
                    filled += (num_cols - len(filled)) * ['']
                    ss_table.add_row(filled)

            ss.append(ss_table)
            s.append(ss)

        doc.append(s)
    doc.generate_pdf(clean=True)

    return doc
开发者ID:Rsullivan00,项目名称:transcript-to-latex,代码行数:57,代码来源:buildDocument.py

示例8: _upload_problem

# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import generate_pdf [as 别名]
    def _upload_problem(self, problem):
        """Uploads a specified problem to imgur.

        Returns:
            A tuple (str, (int, int)), where str is the url, on imgur and
            the tuples are the dimensions of the image (width, height).
        Raises:
           LatexParsingException : there was an issue parsing the document
        """
        default_doc = []
        # populate doc with the appropriate problem
        for line in problem[0]:
            # these first two statements are for wrapping the title around in a minipage which allows
            # the problem to be generated on one page and doesn't invoke \newpage
            if line == '\\begin{document}':
                default_doc.append(NoEscape(line))
                default_doc.append(NoEscape('\\begin{minipage}{\\textwidth}'))
            elif line == '\\maketitle':
                default_doc.append(NoEscape(line))
                default_doc.append(NoEscape('\\end{minipage}'))
            elif line == '\\end{itemize}':
                for line2 in problem[1]:
                    default_doc.append(NoEscape(line2))
                default_doc.append(NoEscape(line))
            else:
                default_doc.append(NoEscape(line))

        doc_class_line = NoEscape(default_doc[0])
        use_pkg_line = NoEscape(default_doc[1])
        # skip twocolumn since it makes the problem look spread awfully
        opts = filter(lambda pkg: pkg != 'twocolumn', doc_class_line[doc_class_line.find('[') + 1: doc_class_line.find(']')].split(','))
        args = NoEscape(doc_class_line[doc_class_line.find('{') + 1: doc_class_line.find('}')])
        doc = Document(documentclass=Command('documentclass', options=opts, arguments=args))
        # load packages
        doc.packages = [Package(i) for i in use_pkg_line[use_pkg_line.find('{') + 1: use_pkg_line.find('}')].split(',')]
        # position right after \begin{document}
        it = 4
        while default_doc[it].strip() != '\end{document}':
            doc.append(NoEscape(default_doc[it]))
            it += 1
        # fail safe for future problems which may not parse correctly
        try:
            doc.generate_pdf('default', compiler="pdflatex")
        except:
            raise LatexParsingException

        # These are normal Linux commands that are used to convert the pdf
        # file created by pylatex into a snippet
        os.system("pdfcrop default.pdf")
        os.system("pdftoppm default-crop.pdf|pnmtopng > default.png")
        path = os.path.abspath('default.png')
        uploaded_image = self._client.upload_image(path, title="LaTeX")
        return uploaded_image.link, OnlineImage.get_local_image_info(path)
开发者ID:wgma00,项目名称:PokemonShowdownBot,代码行数:55,代码来源:Putnam.py

示例9: test

# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import generate_pdf [as 别名]
def test():
    doc = Document()
    section = Section('Multirow Test')
    figure = Figure()
    image_filename = os.path.join(os.path.dirname(__file__),
                                  '../examples/kitten.jpg')
    figure.add_image(image_filename)
    figure.add_caption('Whoooo an imagage of a pdf')
    section.append(figure)
    doc.append(section)

    doc.generate_pdf()
开发者ID:votti,项目名称:PyLaTeX,代码行数:14,代码来源:pictures.py

示例10: test

# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import generate_pdf [as 别名]
def test():
    doc = Document()
    Subsection('Only a single string', data='Some words')

    sec1 = Section('Only contains one subsection', data='Subsection')

    sec2 = Section('Only a single italic command', data=Command('textit',
                                                                'Hey'))
    sec2.append('something else that is not italic')
    doc.append(sec1)
    doc.append(sec2)

    doc.generate_pdf()
开发者ID:AnkurAgarwal1989,项目名称:PyLaTeX,代码行数:15,代码来源:test_no_list_as_data.py

示例11: test_document

# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import generate_pdf [as 别名]
def test_document():
    doc = Document(
        default_filepath="default_filepath",
        documentclass="article",
        fontenc="T1",
        inputenc="utf8",
        lmodern=True,
        data=None,
    )

    doc.append("Some text.")

    doc.generate_tex(filepath="")
    doc.generate_pdf(filepath="", clean=True)
开发者ID:markdoerr,项目名称:PyLaTeX,代码行数:16,代码来源:args.py

示例12: test_document

# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import generate_pdf [as 别名]
def test_document():
    doc = Document(
        default_filepath='default_filepath',
        documentclass='article',
        fontenc='T1',
        inputenc='utf8',
        lmodern=True,
        data=None,
    )

    repr(doc)

    doc.append('Some text.')

    doc.generate_tex(filepath='')
    doc.generate_pdf(filepath='', clean=True)
开发者ID:AnkurAgarwal1989,项目名称:PyLaTeX,代码行数:18,代码来源:args.py

示例13: generate_hr_tex

# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import generate_pdf [as 别名]
def generate_hr_tex(G, matchings, output_dir, stats_filename):
    """
    print statistics for the resident proposing stable,
    max-cardinality popular, and popular amongst max-cardinality
    matchings as a tex file
    :param G: graph
    :param matchings: information about the matchings
    """
    # create a tex file with the statistics
    doc = Document('table')
    # M_s = matching_algos.stable_matching_hospital_residents(graph.copy_graph(G))

    # add details about the graph, |A|, |B|, and # of edges
    n1, n2, m = len(G.A), len(G.B), sum(len(G.E[r]) for r in G.A)
    with doc.create(Subsection('graph details')):
        with doc.create(Tabular('|c|c|')) as table:
            table.add_hline()
            table.add_row('n1', n1)
            table.add_hline()
            table.add_row('n2', n1)
            table.add_hline()
            table.add_row('m', m)
        table.add_hline()

    with doc.create(Subsection('general statistics')):
        with doc.create(Tabular('|c|c|c|c|')) as table:
            table.add_hline()
            table.add_row(('description', 'size', 'bp', 'bp ratio'))
            for desc in matchings:
                M = matchings[desc]
                sig = signature(G, M)
                msize = matching_utils.matching_size(G, M)
                bp = matching_utils.unstable_pairs(G, M)
                table.add_hline()
                table.add_row((desc, msize, len(bp), len(bp)/(m - msize)))
            table.add_hline()

    # statistics w.r.t. set A
    stats_for_partition(G, matchings, doc)

    # statistics w.r.t. set B
    # stats_for_partition(G, matchings, doc, False)

    stats_abs_path = os.path.join(output_dir, stats_filename)
    doc.generate_pdf(filepath=stats_abs_path, clean_tex='False')
    doc.generate_tex(filepath=stats_abs_path)
开发者ID:rawatamit,项目名称:hospital-residents,代码行数:48,代码来源:sea.py

示例14: doit

# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import generate_pdf [as 别名]
def doit(outfile = 'summary', ndim=3, action=True):
    if action == False:
        print(outfile, ndim)
        return

    if ndim == 3:
        resfile = '05aperture_results_3d.txt'
        statfile = '3d_cluster_statistics.txt'
    elif ndim == 2:
        resfile = '05aperture_results_2d.txt'
        statfile = 'cluster_statistics.txt'
        
    # generate blank LaTeX doc
    geometry_options = {"tmargin": "1cm", "lmargin": "2cm"}
    doc = Document(geometry_options=geometry_options)

    # insert some introductory material
    dirname = os.getcwd()
    doc.append('Clustering output, found in')
    doc.append(dirname)

    # get the K-means section of results table and insert into the document
    with doc.create(Section('K-means results')):
        tmptex, ncl_list = get_stats(resfile, 'kmeans', oldcols_results, newcols_results, None, None)
        doc.append(tmptex)
        doc.append(NewPage())
    
        # add the individual K-means runs
        add_sections_to_doc(ncl_list, 'kmeans', doc, statfile, ndim)

    # now the intro material for meanshift
    # get the results table and insert into the document
    with doc.create(Section('Meanshift results')):
        tmptex, ncl_list = get_stats(resfile, 'meanshift', oldcols_res_ms, newcols_res_ms, None, None)
        doc.append(tmptex)
        doc.append(NewPage())

        # add the individual meanshift runs
        add_sections_to_doc(ncl_list, 'meanshift', doc, statfile, ndim)
            
    # turn the LaTex into a PDF
    doc.generate_tex(filepath=outfile)
    doc.generate_pdf(outfile, clean_tex=False)
    
    # all done!
    return
开发者ID:PBarmby,项目名称:m83_clustering,代码行数:48,代码来源:big_picture_summary.py

示例15: test_document

# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import generate_pdf [as 别名]
def test_document():
    doc = Document(
        default_filepath='default_filepath',
        documentclass='article',
        fontenc='T1',
        inputenc='utf8',
        author='',
        title='',
        date='',
        data=None,
        maketitle=False
    )

    doc.append('Some text.')

    doc.generate_tex(filepath='')
    doc.generate_pdf(filepath='', clean=True)
开发者ID:rfilmyer,项目名称:PyLaTeX,代码行数:19,代码来源:args.py


注:本文中的pylatex.Document.generate_pdf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。