//import java.awt.Image;
//import java.awt.Rectangle;
//import java.awt.image.BufferedImage;
//import java.awt.image.RenderedImage;
//import java.io.File;
//import java.io.FileNotFoundException;
//import java.io.FileOutputStream;
//import java.io.IOException;
//import java.io.OutputStream;
//import java.io.RandomAccessFile;
//import java.nio.ByteBuffer;
//import java.nio.MappedByteBuffer;
//import java.nio.channels.FileChannel;
//import java.security.AccessController;
//import java.security.PrivilegedAction;
//import java.util.Enumeration;
//import java.util.Vector;
//import java.lang.reflect.*;
//
//import javax.imageio.ImageIO;
//
//import org.xhtmlrenderer.pdf.ITextFontResolver;
//import org.xhtmlrenderer.pdf.ITextRenderer;
//
//
//
//import com.jasson.muse.msp.app.service.preview.FileConvertUtil;
//
//import org.icepdf.core.exceptions.PDFException;
//import org.icepdf.core.exceptions.PDFSecurityException;
//import org.icepdf.core.pobjects.Document;
//import org.icepdf.core.pobjects.Page;
//import org.icepdf.core.util.GraphicsRenderingHints;
//
//import com.lowagie.text.DocumentException;
//import com.lowagie.text.pdf.BaseFont;
//import com.sun.image.codec.jpeg.JPEGCodec;
//import com.sun.image.codec.jpeg.JPEGEncodeParam;
//import com.sun.image.codec.jpeg.JPEGImageEncoder;
//import com.sun.pdfview.PDFFile;
//import com.sun.pdfview.PDFPage;
//import com.sun.pdfview.PDFXref;
//import com.sun.pdfview.font.PDFFont;
//
//public class Test3 {
// static{
//// //BaseFont.AddToResourceSearch(Server.MapPath(".") + "\\bin\\iTextAsian.dll");
//// //BaseFont.AddToResourceSearch(Server.MapPath(".") + "\\bin\\iTextAsianCmaps.dll");
//// //BaseFont bf = BaseFont.CreateFont("c:\\windows\\fonts\\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
//// try {
//// //BaseFont bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
//// //PDFFont pdffont= new PDFFont();
//// } catch (DocumentException e) {
//// // TODO Auto-generated catch block
//// e.printStackTrace();
//// } catch (IOException e) {
//// // TODO Auto-generated catch block
//// e.printStackTrace();
//// }
//
// }
// public static void main(String[] args) throws Exception {
// //demo_1();
// demo_2();
// }
//
// // 不支持中文
// public void demo_1() throws Exception {
// String inputFile = "D:/Test/flying.html";
// String url = new File(inputFile).toURI().toURL().toString();
// String outputFile = "D:/Test/flying.pdf";
// OutputStream os = new FileOutputStream(outputFile);
// ITextRenderer renderer = new ITextRenderer();
// renderer.setDocument(url);
// renderer.layout();
// renderer.createPDF(os);
// os.close();
// }
//
// // 支持中文
// public static void demo_2() throws Exception {
// //convertPDF2PNG("");
// String outputFile = "D:/demo_7.pdf";
// OutputStream os = new FileOutputStream(outputFile);
// ITextRenderer renderer = new ITextRenderer();
//
// String html = "<p>显示中文 </p>";
// //String html="<html><head></head><body><p>2323tyyu</p><table border='1'><tr><td></td><td>456</td></tr><tr><td>123</td><td>456</td></tr></table><img src='http://www.baidu.com/img/baidu_sylogo1.gif' /></body></html>";
// renderer.setDocumentFromString(html);
//
// // 解决图片的相对路径问题
// //renderer.getSharedContext().setBaseURL("file:/D:/");
//
// renderer.layout();
// renderer.createPDF(os);
//
// os.close();
// System.out.println("生成成功!");
// //changePdfToImg();
// //convertPDF2PNG(outputFile);
// //toImage(outputFile);
// //FileConvertUtil.convertPDF2PNG(outputFile, 1);
//
// }
// public static void convertPDF2PNG(String pdf) throws IOException {
//
// // load a pdf from a byte buffer
// File file = new File(pdf);
// RandomAccessFile raf = new RandomAccessFile(file, "r");
// FileChannel channel = raf.getChannel();
// ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
// PDFFile pdffile = new PDFFile(buf);
//
//
//
// System.out.println("页数: " + pdffile.getNumPages());
//
// String getPdfFilePath = "e:\\test";
//
// System.out.println("getPdfFilePath is :"+getPdfFilePath);
//
// for (int i = 1; i <= pdffile.getNumPages(); i++) {
// // draw the first page to an image
// PDFPage page = pdffile.getPage(i);
//
// // get the width and height for the doc at the default zoom
// Rectangle rect = new Rectangle(0, 0, (int) page.getBBox()
// .getWidth(), (int) page.getBBox().getHeight());
//
// // generate the image
// Image img = page.getImage(rect.width, rect.height, // width &
// // height
// rect, // clip rect
// null, // null for the ImageObserver
// true, // fill background with white
// true // block until drawing is done
// );
//
// BufferedImage tag = new BufferedImage(rect.width, rect.height,
// BufferedImage.TYPE_INT_RGB);
// tag.getGraphics().drawImage(img, 0, 0, rect.width, rect.height,
// null);
//
//
//
// FileOutputStream out = new FileOutputStream( getPdfFilePath+"\\" + i + ".jpg");
// // 输出到文件流
// System.out.println("成功保存图片到 : " +getPdfFilePath+"\\" + i + ".jpg");
//
// JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
// encoder.encode(tag); // JPEG编码
//
// out.close();
// }
//
// // show the image in a frame
// // JFrame frame = new JFrame("PDF Test");
// // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// // frame.add(new JLabel(new ImageIcon(img)));
// // frame.pack();
// // frame.setVisible(true);
// }
// public static void changePdfToImg() {
//
// try {
//
// File file = new File("E:\\test.pdf");
// RandomAccessFile raf = new RandomAccessFile(file, "r");
// FileChannel channel = raf.getChannel();
// MappedByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY ,0 ,channel.size());
//
// PDFFile pdffile = new PDFFile(buf);
//
// for (int i = 1; i <= pdffile.getNumPages(); i++) {
//
// PDFPage page = pdffile.getPage(i);
//
// Rectangle rect = new Rectangle(0, 0, ((int) page.getBBox().getWidth()) ,((int) page.getBBox().getHeight()));
//
// Image img = page.getImage(rect.width, rect.height, rect,
// null, // null for the ImageObserver
//
// true, // fill background with white
//
// true // block until drawing is done
//
// );
//
// BufferedImage tag = new BufferedImage(rect.width, rect.height ,BufferedImage.TYPE_INT_RGB);
//
// tag.getGraphics().drawImage(img ,0 ,0 ,rect.width ,rect.height, null);
//
// FileOutputStream out = new FileOutputStream("E:\\test\\img\\" + i + ".jpg"); // 输出到文件流
//
// JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
//
// JPEGEncodeParam param2 = encoder.getDefaultJPEGEncodeParam(tag);
//
// param2.setQuality(1f ,false);// 1f提高生成图片质量
//
// encoder.setJPEGEncodeParam(param2);
//
// encoder.encode(tag); // JPEG编码
//
// out.close();
//
// }
//
html局部页面转化生成图片
3星 · 超过75%的资源 需积分: 50 164 浏览量
2014-09-29
10:48:00
上传
评论
收藏 4.5MB RAR 举报
wasim_星空
- 粉丝: 0
- 资源: 43
最新资源
- 基于stm32f103c单片机+MPU6050+0.96英寸OLED显示屏双柄遥控器硬件(原理图+PCB)工程文件.zip
- 整理的关于少儿编程的学习路径,以及如何在小升初,初升高和大学充分的利用起来编程经验的优势
- 足球比赛结果统计表2006-2011年大约28W场比赛
- 基于PHP+mysql的社区交流系统(源代码)
- yolov5,SSD 可能使用到的一些代码
- 一键批量生成多层次文件夹结构,使用Python脚本实现嵌套文件夹批量生成
- 基于c51单片机+DS1302+DHT11温湿度模块+LCD1602显示的万年历硬件原理图+BOM+软件程源码序+仿真图.zip
- NSGA2的MATLAB代码
- Messagepassingtest_GCN_DGL.py
- Sh,Docker 运维好帮手,一招通过 sh 脚本批量快速启动和重启多个Docker 容器
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈