zotero-better-notes/addon/chrome/content/pdfPrinter.xhtml

105 lines
2.9 KiB
HTML

<?xml version="1.0"?>
<!-- prettier-ignore -->
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
rel="stylesheet"
type="text/css"
href="chrome://__addonRef__/content/lib/css/github-markdown-light.min.css"
/>
<link
rel="stylesheet"
href="chrome://__addonRef__/content/lib/css/katex.min.css"
crossorigin="anonymous"
/>
<script>
document.addEventListener("DOMContentLoaded", function () {
var { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm",
);
var { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm",
);
window.XPCOMUtils = XPCOMUtils;
delete window.PrintPreview;
Services.scriptloader.loadSubScript(
"chrome://global/content/printUtils.js",
window,
);
});
// Add message to print window
window.onmessage = async function (e) {
if (e.data.type === "print") {
document.querySelector(".markdown-body").innerHTML = e.data.html;
const settings = PrintUtils.getPrintSettings("", false);
const doPrint = await PrintUtils.handleSystemPrintDialog(
window.browsingContext.topChromeWindow,
false,
settings,
);
if (doPrint) {
window.browsingContext.print(settings);
// An ugly hack to close the browser window that has a static clone
// of the content that is being printed. Without this, the window
// will be open while transferring the content into system print queue,
// which can take time for large PDF files
const emptyWin =
Services.wm.getMostRecentWindow("navigator:browser");
if (emptyWin?.document?.getElementById("statuspanel")) {
emptyWin.close();
}
}
}
};
</script>
<style>
@page {
margin: 25mm 20mm 25mm 20mm;
size: A4;
}
@media print {
body {
height: auto;
margin: 0;
-webkit-print-color-adjust: exact;
color-adjust: exact;
}
@page: footer {
display: none;
}
@page: header {
display: none;
}
}
.markdown-body {
box-sizing: border-box;
min-width: 200px;
max-width: 980px;
margin: 0 auto;
padding: 0px;
}
td,
th {
word-break: break-all;
}
@media (max-width: 767px) {
.markdown-body {
padding: 15px;
}
}
</style>
</head>
<body>
<article class="markdown-body">
<h1>Print to PDF</h1>
<p>Waiting for data...</p>
</article>
</body>
</html>