龍網-新重慶3月4日19時30分訊(記者 姜念月)今(4)日,重慶市教育考試院公布了2022年高職分類考試專業技能測試(其他類除外)準考證打印及考點網址。重慶教育考試院提醒,請各考生自行打印、妥善保管。并請各位考生及時登錄各考點網址,認真仔細閱讀、熟知應考須知,按照防疫要求做好自身防疫工作,沉著、誠信、安全參加測試。
具體安排如下:
準考證打印時間:2022年3月7日起至測試前
考點網址如下:
重慶電子工程職業學院
https://ks.cqcet.edu.cn/
重慶城市管理職業學院
http://www.cswu.cn/zzsgz/list.htm
重慶第二師范學院
http://www.cque.edu.cn/jjy/
重慶工程職業技術學院
http://sac2.cqvie.edu.cn/dkdz/bm_print.asp
重慶工業職業技術學院
http://183.230.255.84:12302/examsstu
重慶三峽職業學院
http://www.cqsxedu.com/flzs/index.htm
重慶醫藥高等專科學校
http://183.230.33.66:8081/login.php
重慶三峽醫藥高等專科學校
https://www.sxyyc.net/html/22/dkgzjnks/
(本文來自新重慶客戶端APP,請至各大應用市場下載)
html轉為pdf的組件有很多,但是還沒有哪一款能達到這個效果,其只要原因是wkhtmltopdf使用webkit網頁渲染引擎開發的用來將 html轉成 pdf的工具,可以跟多種腳本語言進行集成來轉換文檔。但是就使用簡便性來說還是itext等組件占據優勢,如果你要轉換格式有比較高的要求,那么wkhtmltopdf絕對是不二之選!
下載路徑
官網地址 wkhtmltopdf.org/
github地址 github.com/wkhtmltopdf…
使用方法
java調用demo
public class HtmlToPdfInterceptor extends Thread { private InputStream is; public HtmlToPdfInterceptor(InputStream is){ this.is = is; } public void run(){ try{ InputStreamReader isr = new InputStreamReader(is, "utf-8"); BufferedReader br = new BufferedReader(isr); String line = null; while ((line = br.readLine()) != null) { System.out.println(line.toString()); //輸出內容 } }catch (IOException e){ e.printStackTrace(); } }}public class HtmlToPdf { //wkhtmltopdf在系統中的路徑 private static final String toPdfTool = "D:\wkhtmltopdf\bin\wkhtmltopdf.exe"; /** * html轉pdf * @param srcPath html路徑,可以是硬盤上的路徑,也可以是網絡路徑 * @param destPath pdf保存路徑 * @return 轉換成功返回true */ public static boolean convert(String srcPath, String destPath){ File file = new File(destPath); File parent = file.getParentFile(); //如果pdf保存路徑不存在,則創建路徑 if(!parent.exists()){ parent.mkdirs(); } StringBuilder cmd = new StringBuilder(); cmd.append(toPdfTool); cmd.append(" "); cmd.append(" --header-line");//頁眉下面的線 cmd.append(" --header-center 這里是頁眉這里是頁眉這里是頁眉這里是頁眉 ");//頁眉中間內容 //cmd.append(" --margin-top 30mm ");//設置頁面上邊距 (default 10mm) cmd.append(" --header-spacing 10 ");//(設置頁眉和內容的距離,默認0) cmd.append(srcPath); cmd.append(" "); cmd.append(destPath); boolean result = true; try{ Process proc = Runtime.getRuntime().exec(cmd.toString()); HtmlToPdfInterceptor error = new HtmlToPdfInterceptor(proc.getErrorStream()); HtmlToPdfInterceptor output = new HtmlToPdfInterceptor(proc.getInputStream()); error.start(); output.start(); proc.waitFor(); }catch(Exception e){ result = false; e.printStackTrace(); } return result; } public static void main(String[] args) { HtmlToPdf.convert("https://my.oschina.net/papio/blog/835645", "d:/wkhtmltopdf.pdf"); }}復制代碼
wkhtmltopdf 參數詳解
wkhtmltopdf [OPTIONS]... <input file> [More input files] <output file>常規選項 --allow <path> 允許加載從指定的文件夾中的文件或文件(可重復) --book* 設置一會打印一本書的時候,通常設置的選項 --collate 打印多份副本時整理 --cookie <name> <value> 設置一個額外的cookie(可重復) --cookie-jar <path> 讀取和寫入的Cookie,并在提供的cookie jar文件 --copies <number> 復印打印成pdf文件數(默認為1) --cover* <url> 使用HTML文件作為封面。它會帶頁眉和頁腳的TOC之前插入 --custom-header <name> <value> 設置一個附加的HTTP頭(可重復) --debug-javascript 顯示的javascript調試輸出 --default-header* 添加一個缺省的頭部,與頁面的左邊的名稱,頁面數到右邊,例如: --header-left '[webpage]' --header-right '[page]/[toPage]' --header-line --disable-external-links* 禁止生成鏈接到遠程網頁 --disable-internal-links* 禁止使用本地鏈接 --disable-javascript 禁止讓網頁執行JavaScript --disable-pdf-compression* 禁止在PDF對象使用無損壓縮 --disable-smart-shrinking* 禁止使用WebKit的智能戰略收縮,使像素/ DPI比沒有不變 --disallow-local-file-access 禁止允許轉換的本地文件讀取其他本地文件,除非explecitily允許用 --allow --dpi <dpi> 顯式更改DPI(這對基于X11的系統沒有任何影響) --enable-plugins 啟用已安裝的插件(如Flash --encoding <encoding> 設置默認的文字編碼 --extended-help 顯示更廣泛的幫助,詳細介紹了不常見的命令開關 --forms* 打開HTML表單字段轉換為PDF表單域 --grayscale PDF格式將在灰階產生 --help Display help --htmldoc 輸出程序HTML幫助 --ignore-load-errors 忽略claimes加載過程中已經遇到了一個錯誤頁面 --lowquality 產生低品質的PDF/ PS。有用縮小結果文檔的空間 --manpage 輸出程序手冊頁 --margin-bottom <unitreal> 設置頁面下邊距 (default 10mm) --margin-left <unitreal> 將左邊頁邊距 (default 10mm) --margin-right <unitreal> 設置頁面右邊距 (default 10mm) --margin-top <unitreal> 設置頁面上邊距 (default 10mm) --minimum-font-size <int> 最小字體大小 (default 5) --no-background 不打印背景 --orientation <orientation> 設置方向為橫向或縱向 --page-height <unitreal> 頁面高度 (default unit millimeter) --page-offset* <offset> 設置起始頁碼 (default 1) --page-size <size> 設置紙張大小: A4, Letter, etc. --page-width <unitreal> 頁面寬度 (default unit millimeter) --password <password> HTTP驗證密碼 --post <name> <value> Add an additional post field (repeatable) --post-file <name> <path> Post an aditional file (repeatable) --print-media-type* 使用的打印介質類型,而不是屏幕 --proxy <proxy> 使用代理 --quiet Be less verbose --read-args-from-stdin 讀取標準輸入的命令行參數 --readme 輸出程序自述 --redirect-delay <msec> 等待幾毫秒為JS-重定向(default 200) --replace* <name> <value> 替換名稱,值的頁眉和頁腳(可重復) --stop-slow-scripts 停止運行緩慢的JavaScripts --title <text> 生成的PDF文件的標題(第一個文檔的標題使用,如果沒有指定) --toc* 插入的內容的表中的文件的開頭 --use-xserver* 使用X服務器(一些插件和其他的東西沒有X11可能無法正常工作) --user-style-sheet <url> 指定用戶的樣式表,加載在每一頁中 --username <username> HTTP認證的用戶名 --version 輸出版本信息退出 --zoom <float> 使用這個縮放因子 (default 1) 頁眉和頁腳選項--header-center* <text> (設置在中心位置的頁眉內容) --header-font-name* <name> (default Arial) (設置頁眉的字體名稱)--header-font-size* <size> (設置頁眉的字體大小)--header-html* <url> (添加一個HTML頁眉,后面是網址)--header-left* <text> (左對齊的頁眉文本)--header-line* (顯示一條線在頁眉下)--header-right* <text> (右對齊頁眉文本)--header-spacing* <real> (設置頁眉和內容的距離,默認0)--footer-center* <text> (設置在中心位置的頁腳內容) --footer-font-name* <name> (設置頁腳的字體名稱) --footer-font-size* <size> (設置頁腳的字體大小default 11)--footer-html* <url> (添加一個HTML頁腳,后面是網址)--footer-left* <text> (左對齊的頁腳文本)--footer-line* 顯示一條線在頁腳內容上)--footer-right* <text> (右對齊頁腳文本)--footer-spacing* <real> (設置頁腳和內容的距離)./wkhtmltopdf --footer-right '[page]/[topage]' http://www.baidu.com baidu.pdf./wkhtmltopdf --header-center '報表' --header-line --margin-top 2cm --header-line http://192.168.212.139/oma/ oma.pdf表內容選項中 --toc-depth* <level> Set the depth of the toc (default 3) --toc-disable-back-links* Do not link from section header to toc --toc-disable-links* Do not link from toc to sections --toc-font-name* <name> Set the font used for the toc (default Arial) --toc-header-font-name* <name> The font of the toc header (if unset use --toc-font-name) --toc-header-font-size* <size> The font size of the toc header (default 15) --toc-header-text* <text> The header text of the toc (default Table Of Contents) --toc-l1-font-size* <size> Set the font size on level 1 of the toc (default 12) --toc-l1-indentation* <num> Set indentation on level 1 of the toc (default 0) --toc-l2-font-size* <size> Set the font size on level 2 of the toc (default 10) --toc-l2-indentation* <num> Set indentation on level 2 of the toc (default 20) --toc-l3-font-size* <size> Set the font size on level 3 of the toc (default 8) --toc-l3-indentation* <num> Set indentation on level 3 of the toc (default 40) --toc-l4-font-size* <size> Set the font size on level 4 of the toc (default 6) --toc-l4-indentation* <num> Set indentation on level 4 of the toc (default 60) --toc-l5-font-size* <size> Set the font size on level 5 of the toc (default 4) --toc-l5-indentation* <num> Set indentation on level 5 of the toc (default 80) --toc-l6-font-size* <size> Set the font size on level 6 of the toc (default 2) --toc-l6-indentation* <num> Set indentation on level 6 of the toc (default 100) --toc-l7-font-size* <size> Set the font size on level 7 of the toc (default 0) --toc-l7-indentation* <num> Set indentation on level 7 of the toc (default 120) --toc-no-dots* Do not use dots, in the toc輪廓選項 --dump-outline <file> 轉儲目錄到一個文件 --outline 顯示目錄(文章中h1,h2來定) --outline-depth <level> 設置目錄的深度(默認為4)頁腳和頁眉 * [page] 由當前正在打印的頁的數目代替 * [frompage] 由要打印的第一頁的數量取代 * [topage] 由最后一頁要打印的數量取代 * [webpage] 通過正在打印的頁面的URL替換 * [section] 由當前節的名稱替換 * [subsection] 由當前小節的名稱替換 * [date] 由當前日期系統的本地格式取代 * [time] 由當前時間,系統的本地格式取代
作者:曹元
鏈接:https://juejin.im/post/6856547881873047559
來源:掘金
著作權歸作者所有。商業轉載請聯系作者獲得授權,非商業轉載請注明出處。
務場景常見于一些訂單記錄發票等的一些pdf 打印,保留了樣式,可以打印彩色內容也可以打印黑白內容,如果業務復雜的比如添加水印的目前不支持,一般會特定處理,通過canvas 的方式處理。
print.js
// 打印類屬性、方法定義
/* eslint-disable */
const Print = function(dom, options) {
if (!(this instanceof Print)) return new Print(dom, options);
this.options = this.extend(
{
noPrint: ".no-print"
},
options
);
if (dom instanceof String) {
this.dom = document.querySelector(dom);
} else {
this.isDOM(dom);
this.dom = this.isDOM(dom) ? dom : dom.$el;
}
this.init();
};
Print.prototype = {
init: function() {
var content = this.getStyle() + this.getHtml();
this.writeIframe(content);
},
extend: function(obj, obj2) {
for (var k in obj2) {
obj[k] = obj2[k];
}
return obj;
},
getStyle: function() {
var str = "",
styles = document.querySelectorAll("style,link");
for (var i = 0; i < styles.length; i++) {
str += styles[i].outerHTML;
}
str +=
"<style>" +
(this.options.noPrint ? this.options.noPrint : ".no-print") +
"{display:none;}</style>";
return str;
},
getHtml: function() {
var inputs = document.querySelectorAll("input");
var textareas = document.querySelectorAll("textarea");
var selects = document.querySelectorAll("select");
for (var k = 0; k < inputs.length; k++) {
if (inputs[k].type == "checkbox" || inputs[k].type == "radio") {
if (inputs[k].checked == true) {
inputs[k].setAttribute("checked", "checked");
} else {
inputs[k].removeAttribute("checked");
}
} else if (inputs[k].type == "text") {
inputs[k].setAttribute("value", inputs[k].value);
} else {
inputs[k].setAttribute("value", inputs[k].value);
}
}
for (var k2 = 0; k2 < textareas.length; k2++) {
if (textareas[k2].type == "textarea") {
textareas[k2].innerHTML = textareas[k2].value;
}
}
for (var k3 = 0; k3 < selects.length; k3++) {
if (selects[k3].type == "select-one") {
var child = selects[k3].children;
for (var i in child) {
if (child[i].tagName == "OPTION") {
if (child[i].selected == true) {
child[i].setAttribute("selected", "selected");
} else {
child[i].removeAttribute("selected");
}
}
}
}
}
return this.dom.outerHTML;
},
writeIframe: function(content) {
var w,
doc,
iframe = document.createElement("iframe"),
f = document.body.appendChild(iframe);
iframe.id = "myIframe";
//iframe.style = "position:absolute;width:0;height:0;top:-10px;left:-10px;";
iframe.setAttribute(
"style",
"position:absolute;width:0;height:0;top:-10px;left:-10px;"
);
w = f.contentWindow || f.contentDocument;
doc = f.contentDocument || f.contentWindow.document;
doc.open();
doc.write(content);
doc.close();
var _this = this;
iframe.onload = function() {
_this.toPrint(w);
setTimeout(function() {
document.body.removeChild(iframe);
}, 100);
};
},
toPrint: function(frameWindow) {
try {
setTimeout(function() {
frameWindow.focus();
try {
if (!frameWindow.document.execCommand("print", false, null)) {
frameWindow.print();
}
} catch (e) {
frameWindow.print();
}
frameWindow.close();
}, 10);
} catch (err) {
console.log("err", err);
}
},
isDOM:
HTMLElement instanceof Object
? function(obj) {
return obj instanceof HTMLElement;
}
: function(obj) {
return (
obj &&
obj instanceof Object &&
obj.nodeType === 1 &&
obj.nodeName instanceof String
);
}
};
const MyPlugin = {};
MyPlugin.install = function(Vue, options) {
// 4. 添加實例方法
Vue.prototype.$print = Print;
};
export default MyPlugin;
print.js
在vue項目main.js 中加入
import Print from "./print";
Vue.use(Print);
說明: 在需要打印的地方添加ref,不需要打印的地方添加 no-print 的class 類名,通過 $print 去調用需要打印的ref(或者用定義id然后調用id節點的方式也可以,vue中推薦用ref)
說明: 在需要打印的地方添加ref,通過 $print 去調用需要打印的ref<template>
<div class="wrapper">
<button @click="$print($refs.print)">打印</button>
<button @click="handleClick">JS調用打印</button>
<div ref="print">
<h1>這是打印區域</h1>
<small style="color:red">字體顏色備注</small>
<p class="no-print">這是不用打印區域</p>
</div>
</div>
</template>
<script>
export default {
name: 'demo',
methods: {
// JS 操作調用
handleClick() {
this.$print(this.$refs.print)
}
}
}
</script>
<style lang="scss" scoped>
.wrapper {
padding: 2rem;
background: #ffffff;
margin: 1rem;
}
</style>
打印前
打印后
這兩個文檔都很完善,我簡單介紹下安裝使用
Print.js
地址: https://printjs.crabbly.com/
// 下載
npm install print-js --save
// 用的地方導入
import printJS from 'print-js'
<el-button @click="handleClickPrint">打印</el-button>
<div id="print">
<el-table :data="tableData"
style="width: 100%">
<el-table-column prop="date"
label="日期"
width="180">
</el-table-column>
<el-table-column prop="name"
label="姓名"
width="180">
</el-table-column>
<el-table-column prop="address"
label="地址">
</el-table-column>
</el-table>
</div>
methods: {
handleClickPrint() {
## 設置樣式
const style = '@page { margin: 0 } @media print { }'// 自定義樣式
## 調用方法
printJS({
printable: 'form', // 要打印內容的id
type: 'html', // 打印類型 pdf, html, image, json and raw-html
style: style,
scanStyles: false
})
},
// 圖片打印
handleClickPrintImg() {
printJS('http://img.zdnet.com.cn/4/90/liRMFbh31Ka2.jpg?rand=153', 'image')
}
}
vue-print-nb
地址: https://github.com/Power-kxLee/vue-print-nb
npm install vue-print-nb --save
main.js 中導入注冊
import Print from 'vue-print-nb'
Vue.use(Print);
<el-button type="primary" v-print="'#printDetail'">打印</el-button>
<div id="printDetail">
.... 要打印的內容
</div>
其他細節可以看官方文檔,每一個技術官方文檔最詳細的,最起碼都應該看一遍的。
前端開發——工具篇
*請認真填寫需求信息,我們會在24小時內與您取得聯系。