引用pdfbox jar包
平和網站建設公司創新互聯公司,平和網站設計制作,有大型網站制作公司豐富經驗。已為平和成百上千提供企業網站建設服務。企業網站搭建\外貿網站制作要多少錢,請找那個售后服務好的平和做網站的公司定做!
PDDocument pdDocument = new PDDocument();
BufferedImage image = ImageIO.read(f);
int width = 612;
int height = 792;
PDPage pdPage = new PDPage(new PDRectangle(width, height));
pdDocument.addPage(pdPage);
PDImageXObject pdImageXObject = LosslessFactory.createFromImage(pdDocument, image);
PDPageContentStream contentStream = new PDPageContentStream(pdDocument, pdPage);
contentStream.drawImage(pdImageXObject, 0, 0, width, height);
contentStream.close();
pdDocument.save(srcPath + candidate + File.separator
+ f.getName().substring(0, f.getName().length() - 4) + ".pdf");
pdDocument.close();
import?java.io.File;??
import?java.io.FileOutputStream;??
import?java.io.IOException;??
import?com.itextpdf.text.*;??
import?com.itextpdf.text.pdf.PdfWriter;??
public?class?PdfTest??
{??
public?static?void?main(String[]?args)?throws?Exception??
{??
Document?pdfDoc?=?new?Document();??
//?將要生成的?pdf?文件的路徑輸出流??
FileOutputStream?pdfFile?=???
new?FileOutputStream(new?File("F:/study/test/firstPdf.pdf"));??
//?pdf?文件中的一個文字段落??
Paragraph?paragraph?=?new?Paragraph("My?first?PDF?file?with?an?image?...");??
Image?image?=?Image.getInstance("F:/study/test/洛克?李.jpg");??
//?用?Document?對象、File?對象獲得?PdfWriter?輸出流對象??
PdfWriter.getInstance(pdfDoc,?pdfFile);??
pdfDoc.open();??//?打開?Document?文檔??
//?添加一個文字段落、一張圖片??
pdfDoc.add(paragraph);??
pdfDoc.add(image);??
pdfDoc.close();??
}??
}
不知道你用什么方法生成 的,你可以去百度搜索 java IText 用那個生成PDF幾句代碼就行了
百度有現成的例子
大約是。。。他可以直接把圖片,生成PDF
Document doc = new Document(null, 0, 0, 0, 0);
Image image = Image.getInstance(imgPath);
PdfWriter.getInstance(doc, fos);
新聞標題:java代碼圖片轉pdf,java代碼圖片轉換文字
網站地址:http://m.kartarina.com/article46/hsdeeg.html
成都網站建設公司_創新互聯,為您提供云服務器、網站建設、自適應網站、網站設計公司、微信公眾號、小程序開發
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯