导航:首页 > 文档加密 > itextpdf转图片

itextpdf转图片

发布时间:2023-06-06 00:48:48

java itext转换pdf

public void GenerateAllParts() {
Document document = new Document();

try {
PdfWriter.getInstance(document, new FileOutputStream("d:\\all.pdf"));

// 生成字体
BaseFont bfChinese = BaseFont.createFont("STSongStd-Light", "UniGB-UCS2-H", false);
// 标题字体
Font f30 = new Font(bfChinese, 30, Font.NORMAL, Color.BLACK);
// 正文字体
Font f12 = new Font(bfChinese, 12, Font.NORMAL, Color.BLACK);
Font f6 = new Font(bfChinese, 6, Font.NORMAL, Color.BLACK);
Font f8 = new Font(bfChinese, 8, Font.NORMAL, Color.BLACK);

document.open();

// 标题
document.add(new Paragraph("报表实例", f30));
// 换行
document.add(new Chunk("\n\n"));
//
document.add(
new Paragraph(
new Chunk(".......................点击查看报表", f12)
.setLocalGoto("table")));
// 换行
document.add(new Chunk("\n\n"));
document.add(
new Paragraph(
new Chunk(".......................点击查看图片", f12)
.setLocalGoto("image")));
document.add(new Chunk("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"));

///////////////////////////////////////////////////
// 报表位置
document.add(new Chunk("报表实例", f12).setLocalDestination("table"));
// 添加table实例
PdfPTable table = new PdfPTable(5);
table.setWidthPercentage(100);
table.setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
PdfPCell cell = new PdfPCell();
cell.setBackgroundColor(new Color(213, 141, 69));
cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);

// 表格标题
cell.setPhrase(new Paragraph("标题一", f8));
table.addCell(cell);
cell.setPhrase(new Paragraph("标题二", f8));
table.addCell(cell);
cell.setPhrase(new Paragraph("标题三", f8));
table.addCell(cell);
cell.setPhrase(new Paragraph("标题四", f8));
table.addCell(cell);
cell.setPhrase(new Paragraph("标题五", f8));
table.addCell(cell);

// 表格数据
PdfPCell newcell = new PdfPCell();
newcell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
newcell.setPhrase(new Paragraph("数据一", f8));
table.addCell(newcell);
newcell.setPhrase(new Paragraph("数据二", f8));
table.addCell(newcell);
newcell.setPhrase(new Paragraph("数据三", f8));
table.addCell(newcell);
newcell.setPhrase(new Paragraph("数据四", f8));
table.addCell(newcell);
newcell.setPhrase(new Paragraph("数据五", f8));
table.addCell(newcell);

document.add(table);
////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////
// 添加连接
document.add(new Chunk("图片实例", f12).setLocalDestination("image"));
Image jpg = Image.getInstance("d:\\3.jpg");
document.add(jpg);
//////////////////////////////////////////////////////////

document.close();
} catch (Exception e) {
// TODO: handle exception
}
}

② java做 pdf转换成图片 时出现Unknown CMap: UniGB-UCS2-H急~

用jasperreport的exportpdffile那个方法生成pdf到指定的磁盘目录下,所有的pdf文件生成是生成了,文件大小也不一.但是打开任何pdf文件都是空白的,不知道为什么,而我换exporthtmlfile的那个方法生成的html文件都能展现正常.由于这个程序是在后台生成文件给mail发送的所以不通过jsp,action的流程,只能在后台指定目录中生成一个pdf文件,然后用mail去调用的.所以不能用response流生成pdf文件.都是通过传来的数据生成的pdf,我其他什么都没有改动,就只是用exportpdffile生成的pdf文件是空白的,但用exporthtmlfile的方法生成的能展现,说明数据源是没问题的.不知道为什么,困绕很久,由于需求只要求传pdf文件,所以不能用html的文件来传送,不知道是不是这两个方法的参数设置有什么不同吗?而且pdf的那两个itext中文包我也导入了,所以不存在字符转换问题

③ java pdf转图片问题

搜索添加spire.pdf.jar文件为依赖,pdf转图片代码如下:

  1. import java.awt.image.BufferedImage;

  2. import java.io.File;

  3. import java.io.IOException;

  4. import com.spire.pdf.PdfDocument;

  5. import javax.imageio.ImageIO;


  6. public class toImage {


  7. public static void main(String[] args) throws IOException {

  8. //加载PDF文件

  9. PdfDocument doc = new PdfDocument();

  10. doc.loadFromFile("Sample.pdf");

  11. //保存PDF的每一页到图片

  12. BufferedImage image;

  13. for (int i = 0; i < doc.getPages().getCount(); i++) {

  14. image = doc.saveAsImage(i);

  15. File file = new File( String.format("ToImage-img-%d.png", i));

  16. ImageIO.write(image, "PNG", file);

  17. }

  18. doc.close();

  19. }

  20. }

阅读全文

与itextpdf转图片相关的资料

热点内容
如何我的世界服务器地址 浏览:189
编程猫源码精灵2021年最新兑换码 浏览:670
世界上最快的动物是什么app 浏览:889
一打开微信文件夹就卡 浏览:265
什么软件可以做指标源码 浏览:465
java程序员饱和 浏览:150
路由器怎么加密更安全 浏览:695
内存卡加密卡是什么意思 浏览:695
帮别人做app需要注意什么 浏览:668
android获取string字符 浏览:182
python中的计数器 浏览:622
海地加密驱动安装 浏览:844
慧净电子12单片机开发板 浏览:940
什么网段服务器好 浏览:599
服务器商店怎么造 浏览:934
有什么跳鬼步舞的app 浏览:250
倚天2如何自己搭建服务器 浏览:553
我的世界如何让服务器刷神宠 浏览:624
为什么程序员要尽量进大厂 浏览:3
phpfiletype 浏览:937