javascript文档

A teeny-tiny javascript library that made printing from the web incredibly simple.

一个很小的javascript库,使从网络打印变得异常简单。

Photo by Florian Klauer on Unsplash
Florian Klauer在Unsplash上拍摄的照片

Print.js was primarily written to help us print PDF files directly within our apps, without leaving the interface, and no use of embeds. For unique situations where there is no need for users to open or download the PDF files, and instead, they just need to print them. One scenario where this is useful, for example, is when users request to print reports that are generated on the server-side. These reports are sent back as PDF files. There is no need to open these files before printing them. Print.js offers a quick way to print these files within our apps.

Print.js的主要目的是帮助我们直接在我们的应用程序中打印PDF文件,而无需离开界面,也不使用嵌入。 对于不需要用户打开或下载PDF文件的独特情况,他们只需要打印即可。 例如,当用户请求打印服务器端生成的报告时,这种方法很有用。 这些报告以PDF文件的形式发送回。 无需在打印之前打开这些文件。 Print.js提供了一种在我们的应用程序中打印这些文件的快速方法。

1)下载并安装 (1) Download and Install)

You can either download the latest version(v1.2.0) of Print.js from the GitHub releases or use one of the two steps given below depending on your package manager.

您可以从GitHub版本下载Print.js的最新版本( v1.2.0 ),也可以根据软件包管理器使用以下两个步骤之一。

  • To install using npm:
    要使用npm安装:
npm install print-js --save
  • To install using yarn:
    要使用纱线安装:
yarn add print-js

After installing via npm or yarn, you should import the library into your project, as shown below, prior to starting using it.

通过npm或yarn安装后,应在开始使用之前将库导入到项目中,如下所示。

import print from 'print-js'

2)入门 (2) Getting Started)

  • First, we need to include the Print.js library on the page:
    首先,我们需要在页面上包含Print.js库:
<script src="print.js"></script>
  • If you will use the modal feature, also include Print.css on the page:
    如果要使用模式功能,请在页面上也包括Print.css:
<link rel="stylesheet" type="text/css" href="print.css">

That’s it. You can now use Print.js in your pages.

而已。 现在,您可以在页面中使用Print.js。

When writing your javascript code, remember that the library occupies a global variable of printJS.

在编写JavaScript代码时,请记住该库占用了一个printJS全局变量

3)使用Print.js (3) Using Print.js)

Now, that we have correctly installed and imported the library let’s start using it.

现在,我们已经正确安装并导入了库,让我们开始使用它。

The 4 types of documents you can print using Print.js:

您可以使用Print.js打印的4种类型的文档:

i) PDF (Default)

i)PDF (默认)

Its basic usage is to call printJS() and just pass in a PDF document URL:

它的基本用法是调用printJS()并仅传递PDF文档URL:

printJS('docs/PrintJS.pdf')

ii) HTML

ii)HTML

To print HTML elements, in a similar way, pass in the element id and type:

要以类似方式打印HTML元素,请传入元素ID并输入:

printJS('myElementId', 'html')

iii) IMAGE

iii)影像

For image files, the idea is the same, but you need to pass a second argument:

对于图像文件,想法是相同的,但是您需要传递第二个参数:

printJS('images/PrintJS.jpg', 'image')

iv) JSON

iv)JSON

When printing JSON data, pass in the data, type, and the data properties that you want to print:

在打印JSON数据时,传入数据,类型和要打印的数据属性:

printJS(         {           printable: myData,            type: 'json',            properties: ['prop1', 'prop2', 'prop3']         });

4)例子 (4) Examples)

Enough of the theory, let’s now look at some useful illustrations on how we can use this library to get some good printing work done on our webpage:

有了足够的理论,现在让我们看一些有用的插图,说明如何使用该库在网页上完成一些好的打印工作:

1. Print an HTML Form

1.打印HTML表单

Print.js accepts an object with arguments. Let’s print an HTML form with a customized heading now :

Print.js接受带有参数的对象。 让我们现在打印带有自定义标题HTML表单:

演示地址

Print HTML Form with Heading Using Print.js
使用Print.js以标题打印HTML表单

2. Print Images

2.打印图像

To print multiple images together, we can pass an array of images. We can also pass the style to be applied to each image :

要一起打印多个图像,我们可以传递一个图像数组。 我们还可以传递要应用于每个图像的样式:

演示地址

Print Multiple Styled Images together Using Print.js
使用Print.js一起打印多个样式的图像

3. Print JSON Data

3.打印JSON数据

演示地址

Print JSON data as a table Using Print.js
使用Print.js将JSON数据打印为表格

4. Print Styled JSON Data

4.打印样式化的JSON数据

We can now add custom styles to our data table as well as customize the table header text by sending an object array :

现在,我们可以向数据表添加自定义样式,并通过发送对象数组来自定义表头文本:

演示地址

Print Styled JSON data as a table
将样式化的JSON数据打印为表格

5. Handle Error while Printing PDF

5.打印PDF时处理错误

You could also handle errors using the onError() method provided by print.js and display them to the users using alerts as shown in the example below:

您还可以使用print.js提供的onError()方法处理错误,并使用警报将其显示给用户,如下例所示:

演示地址

Print.js Error handling
Print.js错误处理

5)浏览器兼容性(5) Browser Compatibility)

Since print.js is a fairly new library, therefore, currently, not all library features are working between browsers. However, most of the leading browsers support all of the document types that this amazing library allows us to print. Below are the results of tests done with these major browsers, using their latest versions:

由于print.js是一个相当新的库,因此,当前,并非所有库功能都在浏览器之间运行。 但是,大多数领先的浏览器都支持该惊人的库允许我们打印的所有文档类型。 以下是使用这些主要浏览器的最新版本进行的测试结果:

Credits: https://printjs.crabbly.com/
学分: https : //printjs.crabbly.com/

The tests were done using a cross-browser testing tool provided by BrowserStack.

测试是使用BrowserStack提供的跨浏览器测试工具完成的。

So, that’s it about this useful Javascript library. I hope the information provided in this article provides value to you and helps you simplify and optimize the future printing tasks on your web app.

所以,就是关于这个有用的Javascript库。 希望本文中提供的信息能为您带来价值,并帮助您简化和优化Web应用程序中将来的打印任务。

翻译自: https://levelup.gitconnected.com/the-easiest-way-to-print-documents-with-javascript-print-js-cd512594a98c

javascript文档

http://www.taodudu.cc/news/show-2366944.html

相关文章:

  • Threejs中文文档
  • js文档加载事件---
  • JavaScript文档注释JSDoc注释
  • JavaScript——DOM文档
  • Fabric.js 文档
  • jsDoc的使用文档
  • JS文档整理
  • Word中公式输入的快捷键
  • word插入公式及编号右对齐
  • word输入公式快捷键
  • word里面给公式自动编号
  • wps公式如何加序号_Microsoft Word 插入公式、公式编号及交叉引用完美指南
  • 解决word中公式插入后行间距变大,和文字不统一的问题
  • word插入公式不自动斜体的解决办法
  • word文档中添加公式、插入数学公式及其编号
  • word之中快速插入已有公式的几种方法
  • Python之GUI编程 实现界面化的词云图生成器.exe
  • 三国演义词云图
  • Python用户画像词云图生成并集成到django网站
  • 在线词云图生成(以WordArt为例)
  • mysql数据生成词云图,7个好用的在线词云生成工具
  • python词云图片在哪儿打开_如何用python创建词云图片
  • python制作中文词云图_Python3制作中文词云图
  • python词云图片生成不出来_python实现使用词云展示图片
  • python生成词云图、特殊图形_Python模块---Wordcloud生成词云图
  • 爬取B站弹幕并生成HTML格式的词云图
  • stylecloud:一款可以制作个性化词云图的 Python 神器
  • python词云图_Python快速生成词云图,这是最详细的教程,没有之一!
  • 微信聊天记录生成词云图
  • Python 实现的、带GUI界面的词云生成器

javascript文档_用javascript print js打印文档的最简单方法相关推荐

  1. java打印文档_从Java应用程序打印文档?

    我正在尝试创建一个能够直接从UI打印文档的Java UI . 我能够创建和使用Javax ServiceUI,但是当从ServiceUI中选择"Print"并调用DocJob上的p ...

  2. javascript中对象_了解JavaScript中的承诺

    javascript中对象 我向您承诺,到本文结束时,您将更好地了解JavaScript. 我与JavaScript有一种"爱与恨"的关系. 但是尽管如此,JavaScript一直 ...

  3. javascript 高级程序设计_所以 JavaScript 到底是什么?我居然懵了????

    前言 引用<JavaScript 高级程序设计第四版>中说的话 --"从简单的输入验证脚本到强大的编程语言,JavaScript 的崛起没有任何人预测到.它很简单,学会用只要几分 ...

  4. javascript map 排序_数据结构-JavaScript字典结构的编程实现

    字典是一类特殊的数据元素的集合,字典的基本单元为数对,所谓数对是指类似(key,value)形式的数据.每一个数对结构包括了关键字key与该元素对应的value值,在一个普通字典所组成的数对集合中,关 ...

  5. javascript单引号_避免JavaScript单文化

    javascript单引号 本文由Tom Greco , Dan Prince和Mallory van Achterberg进行了同行评审. 感谢所有SitePoint的同行评审员使SitePoint ...

  6. python命令打印word文档_使用DOS命令如何打印Word文档

    打印Word文档,使用窗口菜单即可打印,为什么还来个多余的招数?首先澄清一下,这不是没事找事做,而是一招防患于未然的绝招! 什么情况下我们使用到这招呢? 当你倒霉到极点.走路都会被石头扳倒的时候就用得 ...

  7. 使用jQuery.print.js打印

    在网页开发的过程中不可避免会使用到浏览器的打印功能,通常情况下开发者需要在打印完成后提示用户进行确认,然后发送更新请求.作者在写这篇博文之前遇到过类似的应用场景:在开发某景区的兑票系统的时候,项目方要 ...

  8. vue使用print.js打印插件

    任务:解决vue页面局部打印功能 print.js插件,可以打印 html.pdf.json数据 官网:https://printjs.crabbly.com/ 一个整理的很好的讲解:https:// ...

  9. jquery.print.js打印去掉页眉页脚和设置横纵向打印

    <style media='print'> @page{ size:portrait;// 或landscape   设置横纵向打印 margin:0mm auto } </styl ...

  10. java 最长回文串_通俗易懂的最长回文串图解、说明及Java代码(中心扩散法和Manacher算法)...

    1. 回文串 作为程序员,回文串这个词已经见怪不怪了,就是一个字符串正着读和反着读是一样的,形式如abcdcba.bbaabb.这里涉及到奇回文和偶回文,奇回文指回文串的字符数是奇数,偶回文指回文串的 ...

最新文章

  1. 计算机组成原理中12H是什么,计算机组成原理课程实习报告.doc
  2. 2020人工神经网络第一次作业-参考答案第四部分
  3. hibernate的native sql查询
  4. Android BLE开发(一):串口调试
  5. Java Optional 的 orElse() 和 orElseGet() 的区别
  6. 面试笔记——C++11新特性
  7. 永磁直驱风力发电机结构图_国内首台10MW海上永磁直驱风力发电机研制成功
  8. python无法安装第三方库read time out_解决pip install的时候报错timed out的问题
  9. 基于深度学习的文本分类1
  10. 一个上帝视角的java游戏_从上帝视角看Java如何运行
  11. oracle查询优化不走缓存,Oracle数据库存储优化问题
  12. mysql最早出现的数据模型_在数据库发展史中出现的数据模型有哪些
  13. android怎么用经纬度定位,android 依据经纬度定位所在城市
  14. mysql5.7下载中文版_mysql 5.7版本的下载安装
  15. 《Kotlin从零到精通Android开发》面世啦
  16. android 图片虚化代码,Android图片虚化源码
  17. SQLServer笔试题
  18. 软件开发环境SDK安装及注意事项
  19. 站点能源低碳目标网,助力网络碳中和 | 华为发布站点能源十大趋势
  20. 【数学 裴蜀定理】luogu_4549 裴蜀定理

热门文章

  1. 解决Office桌面图标异常
  2. usbwriter使用后还原
  3. AI和数学领域的咖啡甜心(一):DeepFace基础
  4. python中的pip是什么_python中的pip是什么意思
  5. vue3.0开发环境搭建及vue2.x和vue3.x的区别
  6. 机械硬盘换固态硬盘重装系统
  7. 如何成为一名合格的算法工程师?我们做了一次技能拆分…
  8. 如何给论文添加参考文献
  9. GAN生成图像质量的两个评价指标——IS与FID
  10. Oracle 多行显示在一行详解(listagg)