在Casper中设置paperSize以进行PDF打印 [英] Setting paperSize for PDF printing in Casper

查看:87
本文介绍了在Casper中设置paperSize以进行PDF打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Phantom中生成PDF时,我可以这样设置纸张大小:

In generating PDFs in Phantom, I can set the paper size like this:

page.paperSize = {
  height: '8.5in',
  width: '11in',
  orientation: 'landscape',
  border: '0.4in'
};

然后page.render(output)函数会正确生成PDF。换句话说,它的大小是正确的,并且有很多相同大小的页面。

then the page.render(output) function generates a PDF properly. In other words, the size is correct and it has many pages of that size.

我无法在Casper中使用它(我不确定是否它被支持)。因此,例如,以下内容:

I can't get this to work in Casper (and I'm not sure if it is supported). So for example, the following:

var casper = require('casper').create({
    paperSize: {
      height: '8.5in',
      width: '11in',
      orientation: 'landscape',
      border: '0.4in'
    },
    logLevel: 'debug',
    verbose: true
});

....this.capture('print.pdf'); ...

用一个非常长的页面创建PDF。设置 viewportSize 不能解决问题。

creates a PDF with a single, very long page. Setting viewportSize does not fix the problem.

有什么方法可以从Casperjs内部访问pageSize对象?

Is there any way to access the pageSize object from within Casperjs?

推荐答案

您可以通过 casper.page.paperSize 访问 paperSize ,但是您需要在调用 casper.start(),否则 casper.page 等于null。

You can access paperSize through casper.page.paperSize, however you will need to set this after calling casper.start(), otherwise casper.page will be equal to null.

下面是一个示例:

var casper = require("casper").create();
casper.start();

casper.page.paperSize = {
  width: '11in',
  height: '8.5in',
  orientation: 'landscape',
  border: '0.4in'
};

casper.thenOpen('http://www.facebook.com/', function() {
  this.capture('test.pdf');
  this.echo('created pdf.');
});

casper.run();

这篇关于在Casper中设置paperSize以进行PDF打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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