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(); } );
相关文章推荐
- JS-prototype的掌握
- JSP学习笔记
- JS-return的使用
- 基于Arcgis for javascript实现百度地图ABCD marker的效果
- 分分钟搞懂JS-闭包函数
- ExtJs jsonStore加载的监听
- JS-面向对象-封装
- javascript 模拟java 实现继承的5种方式
- js学习笔记(二),数组的方法
- js学习笔记(一)
- javascript高级程序设计知识点总结(4)
- (二)我的JavaScript系列:JavaScript面向对象旅程(下)
- 高性能JavaScript--加载和执行(简要学习笔记一)
- JS函数创建的具体过程
- JS函数调用的四种方法
- 配置JSDoc用conf.json
- JavaScript运动框架(全)
- <Java Web学习初级阶段>JavaScript实现注册页面的表单验证
- IE11错误:Exception in window.onload: An error has occuredJSPlugin.3005 解决方案
- <Java Web学习初级阶段>JavaScript实现简单网页计算器