简体   繁体   English

基于宽度的文本缩放

[英]Text Scaling based on width

I converted a PDF into an HTML using an online converter.我使用在线转换器将 PDF 转换为 HTML。 Here's an example result: http://www.ww2incolor.com/500px/e8efe9ed-37d4-45c4-bd12-178d9bac0947/e8efe9ed-37d4-45c4-bd12-178d9bac0947.html这是一个示例结果: http : //www.ww2incolor.com/500px/e8efe9ed-37d4-45c4-bd12-178d9bac0947/e8efe9ed-37d4-45c4-bd12-178d9bac0947.html

It does a pretty good job, but is it possible to have it scale to 100% width to make it mobile friendly?它做得很好,但是否可以将其缩放到 100% 宽度以使其适合移动设备? Getting the image to scale to 100% width is pretty easy, but the text doesn't seem to wanna scale at all.将图像缩放到 100% 宽度非常容易,但文本似乎根本不想缩放。 I've looked into font scaling, but that messes up the location of the text which is important.我已经研究过字体缩放,但这弄乱了重要的文本位置。 Essentially both image and text need to scale in tandem.本质上,图像和文本都需要同步缩放。 transform: scale(X) does what I want it to do, but the width of the PDF can change, so it's not a good solution unless you can make it dynamic. transform: scale(X) 做我想要它做的事情,但 PDF 的宽度可以改变,所以它不是一个好的解决方案,除非你可以让它动态。 Does anybody know if that is possible?有谁知道这是否可能?

Perhaps with the ONRESIZE event in your PDF's container:也许在您的 PDF 容器中使用 ONRESIZE 事件:

<div id="PDFbox" onresize="DoScale();"></div>




 function DoScale(){

 // Get your new container dimensions...

 var W=PDFbox.outerWidth;

 var H=PDFbox.outerHeight;  

 // and then based on whatever logic you prefer, dynamically scale
 whatever is neccessary...


AnotherID.style.transform='scale(2,2)';
}

I hope I understood you well.我希望我能很好地理解你。

You can use js to scale the page, like this:您可以使用 js 来缩放页面,如下所示:

var page = document.querySelector('#pf1');

var getRatio = function(elem){
    return document.body.offsetWidth / elem.offsetWidth;
};

page.style.transformOrigin = 'center top';

var applyZoom = function(){
    page.style.transform = 'scale(' + getRatio(page) + ')';
}

Call this on document ready, resize, and orientation change events:在文档就绪、调整大小和方向更改事件上调用它:

document.addEventListener('DOMContentLoaded', () => applyZoom());
window.addEventListener('resize', () => applyZoom());
window.addEventListener('orientationchange', () => applyZoom()); // probably not needed

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM