【问题标题】:Import/Embed PDF Into HTML (For PDF)将 PDF 导入/嵌入到 HTML(对于 PDF)
【发布时间】:2017-03-02 14:21:03
【问题描述】:

我们的一个应用程序创建了一个 HTML 报告,该报告通过他们的浏览器显示给用户。随后将其转换为可通过电子邮件发送或稍后查看的 PDF 文件。该报告可以分类为医疗/生活方式。我被要求允许选择和嵌入各种 PDF,例如各种饮食和/或练习到 HTML 中。该软件是用 Python 2.7 和 wxPython 2.8 编写的。我正在尝试找到一种将 PDF 嵌入 HTML 以供查看然后将所有内容转换为最终 PDF 的方法。

【问题讨论】:

    标签: html python-2.7 pdf wxpython


    【解决方案1】:

    几个月前,我在这方面做了一些广泛的研究。如果您想使用 HTML 显示 PDF,我会先查看 https://github.com/mozilla/pdf.js

    如果您的目标是从 HTML 页面生成 PDF,那么我会推荐 https://github.com/fraserxu/electron-pdf,它是一种用于生成 PDF 并将其发送回客户端的服务器端解决方案。

    使用 electron-pdf,您可以选择在 Node.JS API 服务器后面运行它,这将使 Electron 实例保持运行以获得最佳延迟。或者,您可以使用 CLI 从您的 Python 代码中调用导出。

    自述文件涵盖了基本的使用场景。

    【讨论】:

      【解决方案2】:

      如果在 Linux 上运行,请查看wkhtmltopdf
      手册页如下:

      Name:
        wkhtmltopdf 0.12.2.4
      
      Synopsis:
        wkhtmltopdf [GLOBAL OPTION]... [OBJECT]... <output file>
      
      Document objects:
        wkhtmltopdf is able to put several objects into the output file, an object is
        either a single webpage, a cover webpage or a table of content.  The objects
        are put into the output document in the order they are specified on the
        command line, options can be specified on a per object basis or in the global
        options area. Options from the Global Options section can only be placed in
        the global options area
      
        A page objects puts the content of a singe webpage into the output document.
      
        (page)? <input url/file name> [PAGE OPTION]...
        Options for the page object can be placed in the global options and the page
        options areas. The applicable options can be found in the Page Options and 
        Headers And Footer Options sections.
      
        A cover objects puts the content of a singe webpage into the output document,
        the page does not appear in the table of content, and does not have headers
        and footers.
      
        cover <input url/file name> [PAGE OPTION]...
        All options that can be specified for a page object can also be specified for
        a cover.
      
        A table of content object inserts a table of content into the output document.
      
        toc [TOC OPTION]...
        All options that can be specified for a page object can also be specified for
        a toc, further more the options from the TOC Options section can also be
        applied. The table of content is generated via XSLT which means that it can be
        styled to look however you want it to look. To get an aide of how to do this
        you can dump the default xslt document by supplying the
        --dump-default-toc-xsl, and the outline it works on by supplying
        --dump-outline, see the Outline Options section.
      
      Description:
        Converts one or more HTML pages into a PDF document, *not* using wkhtmltopdf
        patched qt.
      
      Global Options:
            --collate                       Collate when printing multiple copies
                                            (default)
            --no-collate                    Do not collate when printing multiple
                                            copies
            --copies <number>               Number of copies to print into the pdf
                                            file (default 1)
        -H, --extended-help                 Display more extensive help, detailing
                                            less common command switches
        -g, --grayscale                     PDF will be generated in grayscale
        -h, --help                          Display help
            --license                       Output license information and exit
        -l, --lowquality                    Generates lower quality pdf/ps. Useful to
                                            shrink the result document space
        -O, --orientation <orientation>     Set orientation to Landscape or Portrait
                                            (default Portrait)
        -s, --page-size <Size>              Set paper size to: A4, Letter, etc.
                                            (default A4)
        -q, --quiet                         Be less verbose
            --read-args-from-stdin          Read command line arguments from stdin
            --title <text>                  The title of the generated pdf file (The
                                            title of the first document is used if not
                                            specified)
        -V, --version                       Output version information and exit
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-11-08
        • 2012-04-30
        • 2015-12-12
        • 2014-03-31
        • 2016-01-22
        • 1970-01-01
        • 2021-07-23
        • 1970-01-01
        相关资源
        最近更新 更多