在pdf中横向调整内容 [英] Fit content width-wise in pdf

查看:102
本文介绍了在pdf中横向调整内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当渲染为pdf时,我需要html页面为打印宽度的100%.否则内容将被切断.有没有简单的方法可以做到这一点?

When rendering to pdf, I need the html page to be 100% of the print width. Otherwise content gets cut off. Is there an easy way to do this?

我想出了一种解决方法,该方法可在渲染后获取html宽度,然后设置缩放系数以强制使用正确的宽度.

I came up with a work-around, which gets the html width after rendering and then sets the zoom factor to force the correct width.

var page = require('webpage').create(),
    system = require('system'),
    dpi = 89.9, // strange, but that's what I get on Mac
    pageWidth = 210; // in mm

var getWidth = function() {
    return page.evaluate(function() {
        // get width manually
        // ...
        return width;
    });
};

page.paperSize = {format: 'A4', orientation: 'portrait'};

page.open(system.args[1], function (status) {
    window.setTimeout(function () {
        page.zoomFactor = (pageWidth / 25.4) * dpi / getWidth();
        page.render(system.args[2]);
        phantom.exit();
    }, 200);
});

寻找直接的解决方案,因为要获得宽度,由于我使用的框架,需要我做一些技巧.

Looking for a straight forward solution, because getting the width requires me to do some tricks due to the framework I use.

推荐答案

设法通过添加以下CSS规则来解决此问题,该规则将缩小页面并使之适合:

Managed to solve this by adding the following CSS rule which will zoom out the page and make it fit:

 html {
    zoom: 0.60; 
  }

这篇关于在pdf中横向调整内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆