【问题标题】:Can I view and print the file with using JS without uploading file to the server?不上传文件到服务器,可以用JS查看和打印文件吗?
【发布时间】:2019-05-20 04:22:12
【问题描述】:

我想上传单独的文件,然后在不上传服务器的情况下查看和打印这些文件。如果用户单击发送按钮,将这些文件发送到服务器。

经验:

<p>
    <input type="file" id="file1">
    <img src="">Show thumbnail here
    <button class="print">Print</button>
</p>

<p>
    <input type="file" id="file2">
    <img src="">Show thumbnail here
    <button class="print">Print</button>
</p>

<p>
    <input type="file" id="file3">
    <img src="">Show thumbnail here
    <button class="print">Print</button>
</p>

<p>
    <input type="file" id="file4">
    <img src="">Show thumbnail here
    <button class="print">Print</button>
</p>

<button>Send All Files to Server</button>

Fiddle Example

我可以只使用 vanilla JS 而不使用第三方应用程序吗?

【问题讨论】:

标签: javascript html ajax file-upload printing


【解决方案1】:

您可以使用File Reader API 读取文件,然后将它们绘制成canvas,使用print-only CSS 隐藏(display: none)画布以外的所有元素。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-15
    • 2011-01-25
    • 2018-04-22
    • 1970-01-01
    • 2011-01-27
    • 2012-12-05
    相关资源
    最近更新 更多