Browse Source

因pdf.js采用canvas绘制,其打印字迹模糊,所以重写打印功能

sunyj 9 years ago
parent
commit
655f1b09a8

+ 7 - 2
src/main/webapp/WEB-INF/views/preview.html

@@ -224,11 +224,15 @@ See https://github.com/adobe-type-tools/cmap-resources
 								<span data-l10n-id="open_file_label">Open</span>
 								<span data-l10n-id="open_file_label">Open</span>
 							</button>
 							</button>
 
 
+							<!-- pdf.js自带打印功能,因为使用canvas,打印效果不好,字迹模糊 -->
 							<button id="print" class="toolbarButton print hiddenMediumView"
 							<button id="print" class="toolbarButton print hiddenMediumView"
-								title="Print" tabindex="33" data-l10n-id="print">
+								title="Print" tabindex="33" data-l10n-id="print" hidden='true'>
 								<span data-l10n-id="print_label">Print</span>
 								<span data-l10n-id="print_label">Print</span>
 							</button>
 							</button>
-
+							<!-- 自己实现打印功能 -->
+							<button id="print2" class="toolbarButton print hiddenMediumView" title="打印" tabindex="33" data-l10n-id="print">
+								<i class="fa fa-print"></i>
+							</button>
 							<button id="download" hidden='true'
 							<button id="download" hidden='true'
 								class="toolbarButton download hiddenMediumView" title="Download"
 								class="toolbarButton download hiddenMediumView" title="Download"
 								tabindex="34" data-l10n-id="download">
 								tabindex="34" data-l10n-id="download">
@@ -525,6 +529,7 @@ See https://github.com/adobe-type-tools/cmap-resources
 		</div>
 		</div>
 	</div>
 	</div>
 
 
+<iframe id="hiddenframe" hidden='true'></iframe>
 </body>
 </body>
 
 
 <script src="static/lib/pdf.js/web/compatibility.js"></script>
 <script src="static/lib/pdf.js/web/compatibility.js"></script>

+ 10 - 0
src/main/webapp/resources/js/preview/app.js

@@ -1,3 +1,12 @@
+//隐藏的iframe,用于加载pdf,以便打印(pdf.js自带的打印有问题)
+var hiddenframe = document.getElementById("hiddenframe");
+$("#print2").click(function() {
+	if (hiddenframe.src) {
+		hiddenframe.contentWindow.print();
+	} else {
+		window.document.write("Hidden pdf iframe did not load");
+	}
+});
 $("#download_pdf").click(function() {
 $("#download_pdf").click(function() {
 	downloadReport("pdf");
 	downloadReport("pdf");
 });
 });
@@ -73,6 +82,7 @@ function loadData() {
 		url : loadDataUrl,
 		url : loadDataUrl,
 		success : function(data) {
 		success : function(data) {
 			DEFAULT_URL = data.pdfPath;
 			DEFAULT_URL = data.pdfPath;
+			hiddenframe.src = data.pdfPath;
 		}
 		}
 	});
 	});