pd4ml用来把html生成pdf的实例--需要pd4ml的jar包
2014-01-10 19:43
726 查看
package com.blog.testchpdf; import java.awt.Insets; import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.security.InvalidParameterException; import org.zefer.pd4ml.PD4Constants; import org.zefer.pd4ml.PD4ML; public class GettingStarted1 { protected int topValue = 10; protected int leftValue = 20; protected int rightValue = 10; protected int bottomValue = 10; protected int userSpaceWidth = 1300; public static void main(String[] args) { try { GettingStarted1 jt = new GettingStarted1(); jt.doConversion("http://pd4ml.com/sample.htm", "c:/pd4ml.pdf"); } catch (Exception e) { e.printStackTrace(); } } public void doConversion( String url, String outputPath ) throws InvalidParameterException, MalformedURLException, IOException { File output = new File(outputPath); java.io.FileOutputStream fos = new java.io.FileOutputStream(output); PD4ML pd4ml = new PD4ML(); pd4ml.setHtmlWidth(userSpaceWidth); // set frame width of "virtual web browser" // choose target paper format and "rotate" it to landscape orientation pd4ml.setPageSize(pd4ml.changePageOrientation(PD4Constants.A4)); // define PDF page margins pd4ml.setPageInsetsMM(new Insets(topValue, leftValue, bottomValue, rightValue)); // source HTML document also may have margins, could be suppressed this way // (PD4ML *Pro* feature): pd4ml.addStyle("BODY {margin: 0}", true); // If built-in basic PDF fonts are not sufficient or // if you need to output non-Latin texts, // TTF embedding feature should help (PD4ML *Pro*) pd4ml.useTTF("c:/windows/fonts", true); pd4ml.render(new URL(url), fos); // actual document conversion from URL to file fos.close(); System.out.println( outputPath + "\ndone." ); } }
相关文章推荐
- 利用PD4ML将html 生成PDF 并展示
- jsp中操作Excel需要引入一个外部的jar包(jxl.jar),这个jar包主要是用来构建Excel的骨架的,具体实例如下:
- Html字符串生成pdf的方法 支持中文及中文换行 可行demo和jar
- 读取Doc,Excel,PDF,html,生成Txt文件,读取Txt生成Excel文件
- pd4ml实现HTML转化PDF
- iTextSharp.dll生成pdf 实战实例
- 使用itext将html生成pdf中文换行问题解决方案2
- thymeleaf框架通过java渲染html生成pdf
- C#根据html生成PDF
- 使用FreeMarker生成Html静态文件(实例)
- 通过swagger2markup+asciidoctorj生成html和pdf文档并解决asciidoctorj生成的pdf文件中文显示不全问题(maven方式及java代码方式)
- Maven项目缺少eclipse自带的插件项目需要建立lib目录加上jar包,或者是已经生成有的, 然后 右键build path add libraries web app libraries
- Java生成html为pdf
- C#根据html生成PDF
- freemarker生成excel、word、html、xml实例教程
- PHP实现HTML生成PDF文件的方法
- java项目生成 JAR file 实例
- 读取Doc,Excel,PDF,html,生成Txt文件,读取Txt生成Excel文件
- html生成pdf解析问题
- Html生成PDF文件,并Zip打包下载