您的位置:首页 > Web前端 > JavaScript

phantomjs rendering

2015-09-12 15:02 926 查看

http://wwwy3y3.ghost.io/pageres-phantomjs-capture-sreenshot-chinese-fonts-not-render-correctly/
在使用中文时可能出现乱码,上面的链接可能能够解决问题

var system = require( 'system' );
var args   = system.args;
var url    = args[ 1 ];
var page   = require( 'webpage' ).create();

/**
* Proper error handling
*/
phantom.onError = function( msg, trace ) {
var msgStack = [ 'PHANTOM ERROR: ' + msg ];
if ( trace && trace.length ) {
msgStack.push( 'TRACE:' );
trace.forEach( function( t ) {
msgStack.push( ' -> ' + ( t.file || t.sourceURL ) + ': ' + t.line + ( t.function ? ' (in function ' + t.function + ')' : '' ) );
} );
}
console.error( msgStack.join('\n') );
phantom.exit( 1 );
};

if ( args.length === 1 ) {
throw new Error( 'URL as system argument missing.' );
}

page.viewportSize = {
height : 1000,
width  : 1200
};

page.open( url, function( status ) {
console.log( '********************************************' );
console.log( 'Opened ' + url + ' with status: ' + status );

page.render( 'image-1200.png' );
console.log( 'Rendered ' + url + ' with width of 1200px' );

page.viewportSize = {
height : 1000,
width  : 800
};

page.render( 'image-800.png' );
console.log( 'Rendered ' + url + ' with width of 800px' );

page.viewportSize = {
height : 1000,
width  : 500
};

page.render( 'image-500.png' );
console.log( 'Rendered ' + url + ' with width of 500px' );

page.clipRect = {
top: 0, left: 0, width: 500, height: 300
};

page.render( 'image-header-500.png' );
console.log( 'Rendered header of ' + url + ' with width of 500px' );

phantom.exit();
} );
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: