導航:首頁 > 文檔加密 > poipdf

poipdf

發布時間:2022-07-02 01:47:58

java中怎麼利用poi和itext生成pdf文檔

生成PDF文檔代碼如下:

packagepoi.itext;
importjava.io.FileOutputStream;
importjava.io.IOException;
importjava.awt.Color;
importcom.lowagie.text.*;
importcom.lowagie.text.pdf.*;
importcom.lowagie.text.pdf.BaseFont;
/**
*創建Pdf文檔
*@authorAdministrator
*
*/
publicclassHelloPdf
{
publicstaticvoidmain(String[]args)throwsException
{
BaseFontbfChinese=BaseFont.createFont("STSong-Light","UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);
FontFontChinese=newFont(bfChinese,12,Font.NORMAL);
//第一步,創建document對象
RectanglerectPageSize=newRectangle(PageSize.A4);

//下面代碼設置頁面橫置
//rectPageSize=rectPageSize.rotate();

//創建document對象並指定邊距
Documentdoc=newDocument(rectPageSize,50,50,50,50);
Documentdocument=newDocument();
try
{
//第二步,將Document實例和文件輸出流用PdfWriter類綁定在一起
//從而完成向Document寫,即寫入PDF文檔
PdfWriter.getInstance(document,newFileOutputStream("src/poi/itext/HelloWorld.pdf"));
//第3步,打開文檔
document.open();
//第3步,向文檔添加文字.文檔由段組成
document.add(newParagraph("HelloWorld"));
Paragraphpar=newParagraph("世界你好",FontChinese);
document.add(par);
PdfPTabletable=newPdfPTable(3);
for(inti=0;i<12;i++)
{
if(i==0)
{
PdfPCellcell=newPdfPCell();
cell.setColspan(3);
cell.setBackgroundColor(newColor(180,180,180));
cell.addElement(newParagraph("表格頭",FontChinese));
table.addCell(cell);
}
else
{
PdfPCellcell=newPdfPCell();
cell.addElement(newParagraph("表格內容",FontChinese));
table.addCell(cell);
}
}
document.add(table);
}
catch(DocumentExceptionde)
{
System.err.println(de.getMessage());
}
catch(IOExceptionioe)
{
System.err.println(ioe.getMessage());
}
//關閉document
document.close();

System.out.println("生成HelloPdf成功!");
}


}

希望對你有幫助。

② Apache POI 實現word轉pdf會有線程方面的問題嗎有要,如何解決。

Iterator<HSSFRow> iterator = sheet.iterator();
POI中沒有Row類,一般都是以HSSF開始的類。

③ 如何使用POI轉換.DOC / DOCX為PDF在Java

如果只是文字的話,直接讀出來,然後用07的存回去,poi能實現。但是有目錄什麼的就麻煩了,03的讀出來目錄是一行代碼,就容易出問題
我用的poi正好在糾結,最後沒辦法,用按鍵精靈一個個轉的。有個word文檔批處理貌似能做到,但是要收費。
下面的是我讀取word文字的代碼
03讀取:
InputStream is = new FileInputStream(docfile);
WordExtractor ex = new WordExtractor(is);
text = ex.getText();
System.out.println(text);
07讀取:
OPCPackage opcPackage = POIXMLDocument.openPackage(docxfile.getAbsolutePath());
POIXMLTextExtractor extractor = new XWPFWordExtractor(opcPackage);
text = extractor.getText();
System.out.println(text);
最後:doc不一定是03的,也可能是07的

④ 怎樣用poi jar包生成一個PDF文件

下載轉換工具
網上大把的

⑤ poi可以寫pdf嗎

不可以,poi主要是操作Excel的!

⑥ java中poi如何將word文檔轉換成pdf

itext等等,可以方便轉換的了
~
~
~
~

閱讀全文

與poipdf相關的資料

熱點內容
oracle查看資料庫狀態命令 瀏覽:840
查汽車app叫什麼 瀏覽:747
經濟學英文pdf下載 瀏覽:798
python列表順序 瀏覽:698
雲南邊緣計算伺服器雲伺服器 瀏覽:105
小公司如何選擇伺服器 瀏覽:791
android指紋識別驅動 瀏覽:447
榮耀手機的系統有方舟編譯器嗎 瀏覽:629
單片機應用的論文 瀏覽:474
什麼app可以查網購的真偽 瀏覽:444
培訓班的程序員怎麼樣找工作 瀏覽:813
codeblocks編譯器位數 瀏覽:447
bios加密怎麼設置 瀏覽:350
台電u盤加密大師損壞 瀏覽:850
secure網站加密 瀏覽:124
電視顯示加密是怎麼回事 瀏覽:6
hadoophdfs書籍源碼 瀏覽:584
電極伺服器什麼意思 瀏覽:10
MI預編譯系統 瀏覽:596
python數據篩選教程 瀏覽:965