great_0630
悲惨世界可爱的我
2015-08-17 08:37

XMLWorkHelper将html转换成pdf的时候,有分页,错行怎么处理?求各位大神解决下,着急

  • xml

包如下:
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import com.itextpdf.text.Document;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.tool.xml.XMLWorkerHelper;

代码如下:
Document document = new Document();
// step 2
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("C:/Users/longlong/Desktop/demo.pdf"));

        // step 3
        document.open();

// InputStreamReader isr = new InputStreamReader(new FileInputStream("C:/Users/longlong/Desktop/customer.html"), "UTF-8");
InputStream in = new FileInputStream(new File("C:/Users/longlong/Desktop/customer.html"));
// step 4
// XMLWorkerHelper.getInstance().parseXHtml(writer, document,isr);
XMLWorkerHelper.getInstance().parseXHtml(writer, document, in, null, new MyFont());
//step 5
document.close();

        System.out.println( "PDF Created!" );
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答