diff --git a/swh/web/assets/src/bundles/webapp/pdf-rendering.js b/swh/web/assets/src/bundles/webapp/pdf-rendering.js --- a/swh/web/assets/src/bundles/webapp/pdf-rendering.js +++ b/swh/web/assets/src/bundles/webapp/pdf-rendering.js @@ -15,7 +15,7 @@ let pageNum = 1; let pageRendering = false; let pageNumPending = null; - let scale = 1.5; + let defaultScale = 1.5; let canvas = $('#pdf-canvas')[0]; let ctx = canvas.getContext('2d'); @@ -24,6 +24,9 @@ pageRendering = true; // Using promise to fetch the page pdfDoc.getPage(num).then(page => { + let divWidth = $('.swh-content').width(); + let scale = Math.min(defaultScale, divWidth / page.getViewport(1).width); + let viewport = page.getViewport(scale); canvas.width = viewport.width; canvas.height = viewport.height; @@ -95,6 +98,11 @@ // PDF loading error console.error(reason); }); + + // Render PDF on resize + $(window).on('resize', function() { + queueRenderPage(pageNum); + }); }); } diff --git a/swh/web/assets/src/utils/showdown.css b/swh/web/assets/src/utils/showdown.css --- a/swh/web/assets/src/utils/showdown.css +++ b/swh/web/assets/src/utils/showdown.css @@ -23,3 +23,7 @@ .swh-showdown table tr:nth-child(even) { background-color: #f2f2f2; } + +.swh-showdown img { + max-width: 100%; +} diff --git a/swh/web/templates/includes/content-display.html b/swh/web/templates/includes/content-display.html --- a/swh/web/templates/includes/content-display.html +++ b/swh/web/templates/includes/content-display.html @@ -29,7 +29,7 @@
{{ content }}
{% elif "image/" in mimetype and content %}
-
+
{% elif "application/pdf" == mimetype %}