導航:首頁 > 文檔加密 > 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相關的資料

熱點內容
恐怖電影國語 瀏覽:947
有吃乳汁電影嗎 瀏覽:888
李采潭出演的善良的女老師3 瀏覽:173
台灣影視在線免費看 瀏覽:106
支付寶跳蹬app源碼下載 瀏覽:886
倩女銷魂 紀倩倩 瀏覽:53
周星馳粵語電影 瀏覽:516
5個小時的愛情電影在線觀看 瀏覽:975
求飛機類游戲源碼 瀏覽:406
樂釣app怎麼寫出五星報告 瀏覽:626
類似團鬼六的電影有哪些 瀏覽:660
學校門口向右轉是電影院的英文 瀏覽:961
大樂透五行演算法 瀏覽:142
英語圖解pdf 瀏覽:612
智能租房系統源碼 瀏覽:346
c編程軟體哪個好 瀏覽:674
程序員寫什麼代碼最好 瀏覽:980
大尺度電影名字 瀏覽:897
重生民國收母 瀏覽:723
男主當鴨子的韓劇電影 瀏覽:488