fix: use consistent scale for PDFs

This commit is contained in:
Johannes Frohnmeyer 2024-05-31 09:46:39 +02:00
parent 751d89bf75
commit 3e3955d886
Signed by: Johannes
GPG Key ID: E76429612C2929F4

View File

@ -17,6 +17,7 @@ private fun getCssColor(key: ColorKey): String {
private val backgroundColor = ColorKey.createColorKey("Editor.background", JBColor.WHITE)
private const val pdfJsVersion = "3.11.174"
private const val scale = "1.5"
@Language("HTML")
fun pdfBootstrap(pdf: ByteArray) = """
@ -45,7 +46,7 @@ fun pdfBootstrap(pdf: ByteArray) = """
pdf.getPage(i).then(function(page) {
console.log('Page loaded');
const scale = 1.5;
const scale = $scale;
const viewport = page.getViewport({scale: scale});
// Prepare canvas using PDF page dimensions
@ -59,11 +60,10 @@ fun pdfBootstrap(pdf: ByteArray) = """
canvas.width = viewport.width;
// Render PDF page into canvas context
const renderContext = {
const renderTask = page.render({
canvasContext: context,
viewport: viewport
};
const renderTask = page.render(renderContext);
});
renderTask.promise.then(function () {
return page.getTextContent()
}).then(function (textContent) {
@ -93,6 +93,17 @@ fun pdfBootstrap(pdf: ByteArray) = """
body {
background-color: ${getCssColor(backgroundColor)};
}
:root {
--scale-factorsc$scale;
}
/* for debugging:
span {
color: red !important;
z-index: 99999;
border: 1px solid red;
}*/
</style>
<script>
${JBCefScrollbarsHelper.getOverlayScrollbarsSourceJS()}