Skip to content

Commit

Permalink
Alternative fix fonts issue in printing FranckFreiburger#156
Browse files Browse the repository at this point in the history
  • Loading branch information
arnebm committed Jul 18, 2023
1 parent 1a47de9 commit d307293
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/pdfjsWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,14 @@ export default function(PDFJS) {
var CSS_UNITS = 96.0 / 72.0;

var iframeElt = document.createElement('iframe');
var tempElt = document.createElement('div');
tempElt.style.cssText = 'display: none';
window.document.body.appendChild(tempElt);

function removeIframe() {

iframeElt.parentNode.removeChild(iframeElt);
tempElt.parentNode.removeChild(tempElt);
}

new Promise(function(resolve, reject) {
Expand Down Expand Up @@ -120,7 +124,7 @@ export default function(PDFJS) {
var viewport = page.getViewport({ scale: 1 });
win.document.head.appendChild(win.document.createElement('style')).textContent =
'@supports ((size:A4) and (size:1pt 1pt)) {' +
'@page { margin: 1pt; size: ' + ((viewport.width * PRINT_UNITS) / CSS_UNITS) + 'pt ' + ((viewport.height * PRINT_UNITS) / CSS_UNITS) + 'pt; }' +
'@page { size: ' + ((viewport.width * PRINT_UNITS) / CSS_UNITS) + 'pt ' + ((viewport.height * PRINT_UNITS) / CSS_UNITS) + 'pt; }' +
'}' +

'@media print {' +
Expand Down Expand Up @@ -151,7 +155,8 @@ export default function(PDFJS) {

var viewport = page.getViewport({ scale: 1 });

var printCanvasElt = win.document.body.appendChild(win.document.createElement('canvas'));
// var printCanvasElt = win.document.body.appendChild(win.document.createElement('canvas'));
var printCanvasElt = tempElt.appendChild(document.createElement('canvas'));
printCanvasElt.width = (viewport.width * PRINT_UNITS);
printCanvasElt.height = (viewport.height * PRINT_UNITS);

Expand All @@ -170,6 +175,16 @@ export default function(PDFJS) {

Promise.all(allPages)
.then(function() {

for (var i = 0; i < tempElt.children.length; ++i) {
var child = tempElt.children[i];
var canvas = child.cloneNode(true);

var ctx = canvas.getContext('2d');
ctx.drawImage(child, 0, 0);

win.document.body.appendChild(canvas);
}

win.focus(); // Required for IE
if (win.document.queryCommandSupported('print')) {
Expand Down

0 comments on commit d307293

Please sign in to comment.