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

java图片转pdf

发布时间:2023-06-05 15:02:47

java EMF转为PNG或者pdf

用虚拟打印机,软件有: 1.PDFFactory Pro虚拟打印机,安装后,在任何文档中,选择打印时,选择打印机为pdfFactoryPro,就能生成PDF文件,并可以进行安全设置。 2.SmartPrinter(Doc Pdf xls to pdf/tiff/bmp/jpg/png)一款大家非常熟悉的经典产品,专为转换文件而研发的高品质打印驱动,以运行稳定、转换速度快和图像质量高而着称,通过虚拟打印技术可以完美的将任意可打印文档转换成 PDF、TIFF、JPEG,BMP、PNG、EMF、GIF、TXT格式。 3.雪莹DocConvert虚拟打印转换。雪莹DocConvert是一款文档转化工具,它通过虚拟打印的技术将任何文档转化为PDF,JPG,BMP,TIFF,PCX,PNG等等文档格式。

② java 数据库中2进制流image转成PDF

FileUtils.writeByteArrayToFile(new File("xx.pdf"),p.getBytes());

一般存到数据库的二进制流都是经过加密的,常用的是base64
byte[]bytes = new BASE64Decoder().decodeBuffer(p);
FileUtils.writeByteArrayToFile(new File("xx.pdf"),bytes);

③ 如何使用java将cgm转换成pdf文件

总结对jacob和Itext学习总结.本文试验的是将cgm转换成PDF文件.


实现思路

一、先将cgm转换成HMTL文件格式

二、用流读取HTML文件。将其保存在一个String对象中。

三、用Itext组件,将生成的字符串对象转换成PDF文件。

四、在要生成的PDF文件加入所需信息。

在此:有几点问题如还请前辈解答:1、怎么控制我在PDF文件加入某段文字的字体、大小、间距等。

/**
* 生成PDF文件
* @author 于学明
*
*/
public class CreatePdf {

/**
* 获得PDF文件所需图片
* @param imagePath //图片文件路径
* @return
* @throws BadElementException
* @throws MalformedURLException
* @throws IOException
*/
public Image getImageFile(String imagePath) throws BadElementException, MalformedURLException, IOException{
Image jpg = Image.getInstance(imagePath);
//设置图片居中
jpg.setAlignment(Image.MIDDLE);
return jpg;
}

/**
* 获得文字内容
* @param inputFilePath 原DOC文件路径
* @param outputFilePath 生成HTML文件路径
* @return
*/
public String getPdfContext(String inputFilePath,String outputFilePath){
//读取DOC文件内容
String htmlText = new FileExtracter().extractDoc(inputFilePath, outputFilePath);
//把读取的HTML文件,生成一个字符串
String pdf = new FileExtracter().getContext(htmlText);

return pdf;
}
/**
* 用ITEXT生成指定PDF格式文件
* @param imagePath0
* @param inputFilePath
* @param outputFilePath
* @param imagePath1
* @param outputPdf
* @return
* @throws DocumentException
* @throws IOException
*/
public String createPDF(String imagePath0,String inputFilePath,String outputFilePath,String imagePath1,String outputPdf) throws DocumentException, IOException{

//返回的pdf全路径
String returnPdf="";
File dir=new File("out_pdf");
//若目录不存在则新建该目录
if(!dir.exists()){
dir.mkdir();
}

//新建空白文件
File outPdfPath=new File(dir+"/"+outputPdf);//输出pdf文件的全路径
try {
outPdfPath.createNewFile();
} catch (IOException e1) {
e1.printStackTrace();
returnPdf=null;
}
//定义PDF文件大小和边距
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
//生成PDF文件的路径
PdfWriter writer = PdfWriter.getInstance(document,new FileOutputStream(outPdfPath));
writer.setViewerPreferences(PdfWriter.PageModeFullScreen);
document.open();
//文件头图片
document.add(getImageFile(imagePath0));
//定义字体,可以正常显示中文
BaseFont bfComic = BaseFont.createFont("STSong-Light","UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
Font font = new Font(bfComic, 12, Font.NORMAL);

String pdf = getPdfContext(inputFilePath, outputFilePath);
//String str=new String(pdf.getBytes("ISO-8859-1"),"GB2312");
document.add(new Paragraph(pdf,font));
//文件尾图片
document.add(getImageFile(imagePath1));
document.close();
returnPdf = outPdfPath.getAbsolutePath();
return returnPdf;
}

/**
* 用ITEXT生成指定PDF格式文件
* @param imagePath
* @param inputFilePath
* @param outputFilePath
* @param outputPdf
* @return
* @throws DocumentException
* @throws IOException
*/
public String createPDF(String imagePath,String inputFilePath,String outputFilePath,String outputPdf) throws DocumentException, IOException{

//返回的pdf全路径
String returnPdf="";
File dir=new File("out_pdf");
//若目录不存在则新建该目录
if(!dir.exists()){
dir.mkdir();
}

//新建空白文件
File outPdfPath=new File(dir+"/"+outputPdf);//输出pdf文件的全路径
try {
outPdfPath.createNewFile();
} catch (IOException e1) {
e1.printStackTrace();
returnPdf=null;
}
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
//生成PDF文件的路径
PdfWriter writer = PdfWriter.getInstance(document,new FileOutputStream(outPdfPath));
writer.setViewerPreferences(PdfWriter.PageModeFullScreen);
document.open();
document.add(getImageFile(imagePath));
//定义字体,可以正常显示中文
BaseFont bfComic = BaseFont.createFont("STSong-Light","UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
Font font = new Font(bfComic, 12, Font.NORMAL);

String pdf = getPdfContext(inputFilePath, outputFilePath);
//String str=new String(pdf.getBytes("ISO-8859-1"),"GB2312");
document.add(new Paragraph(pdf,font));
document.close();
returnPdf = outPdfPath.getAbsolutePath();
return returnPdf;
}

public static void main(String [] args){

try {
String s = new CreatePdf().createPDF("c:/a.gif","c:/s.doc", "c:/x.html", "a.pdf");
System.out.println(s);
} catch (DocumentException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
}

④ java生成pdf文件时为什么图片没有原来那么清晰了,这个问题怎么解决

PDF打印机设置的问题,你选的标准打印就会压缩图片,你选高质量、印刷质量之类的就可以了。

⑤ 求个将图片转成pdf文档的java程序,最好有注解,我用pdfbox实现这一要求时,图片不知道为什么没了

给你一个用IText写的吧
// 写PDF文件.
BufferedImage img = ImageIO.read(new File(imgPath));
FileOutputStream fos = new FileOutputStream(pdfFile);
// 创建PDF文档
Document doc = new Document(null, 0, 0, 0, 0);
// 设置尺寸为图片尺寸
doc.setPageSize(new Rectangle(img.getWidth(), img.getHeight()));
Image image = Image.getInstance(imgPath);
PdfWriter.getInstance(doc, fos);
doc.open();
doc.add(image);
doc.close();

阅读全文

与java图片转pdf相关的资料

热点内容
任务管理器打开命令行 浏览:860
彼时曾相伴电影努努 浏览:534
主角重生民国参加黄埔 浏览:414
睿威仕无线摄像用什么app 浏览:198
女儿父亲钩引电影 浏览:174
大香蕉手机 浏览:856
安卓部落冲突服务器地址 浏览:324
唐古拉优选app叫什么名字 浏览:38
打开一个文件夹为什么接着就退出 浏览:50
女主高中就怀孕的小说 浏览:10
app为什么必须要获取手机号码 浏览:58
实用的网页编程 浏览:424
宝鸡小程序定制开发源码 浏览:432
十大军事历史穿越小说 浏览:56
爱的共享韩 浏览:179
中文字幕推荐排行榜 浏览:589
李采镡所有电影 浏览:348
前度2未删减 浏览:866
日本一部关于平行时空的电影 浏览:346
伤寒论原文pdf 浏览:29