導航:首頁 > 文字圖片 > javaword轉圖片

javaword轉圖片

發布時間:2023-12-11 05:57:14

1. 求使用java在word中添加圖片的樣例代碼,最好能添加到指定位置,如果使用poi最好。急急急!!!

首先你得打開這個word文檔,然後你再把這個圖片做成文件流的格式,然後把它寫進去。
但是這個過程如果你用java自帶的文件流格式打開的話,寫進去會是亂碼。我做過的方法是用開源框架包,poi.jar可以用來做有關office的打開、寫入、讀出等操作,具體代碼沒有了,但是demo裡面的代碼都已經足夠了,你自己稍微看看就能知道怎麼做了。這個包還是比較穩定的。 求採納

2. 用Java從word中提取出圖片

因為太長了, 我放我空間了
思路是2003以後, word就可存為xml, 二進制數據按base64編碼
然後可以按解析xml文檔方式獲取圖片數據
然後對它進行解碼--

3. java想要對已有word文檔追加圖片,應該怎麼做

以前做過其他office的沒做過微軟的,不過大同小異
這個你就需要在java中獲取到word的某種對象,方法有很多,但是要看你用什麼方式調用的office了,如果是某個牌子的中間件,那就用那個中間件的二次開發文檔裡面應該就有提到這些方法,如果是第三方的jar包,應該也不麻煩,通過jar包中的方法,可能要有一個word的實例創建的過程吧,然後獲取到range或者textrange等這些對象(應該是這倆對象……)通過這對象然後找到插入圖片的方法,然後傳入位置參數(可能是兩個數用逗號隔開)

4. 有什麼方法可以用java 將word或者Excel文件轉換成圖片文件

可以用openoffice將word轉化為pdf,再使用swftools把pdf轉換為swf

5. java 把office word,ppt轉化為圖片

從一個大神那裡學來的,已測試無誤
package com;

import java.awt.Dimension;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;

import org.apache.poi.hslf.model.TextRun;
import org.apache.poi.hslf.usermodel.RichTextRun;
import org.apache.poi.hslf.usermodel.SlideShow;

public class ExportPPT {

public static void main(String[] args) {
// 讀入PPT文件
File file = new File("D:\\UPH.ppt");
doPPTtoImage(file);
}

public static boolean doPPTtoImage(File file) {
boolean isppt = checkFile(file);
if (!isppt) {
System.out.println("The image you specify don't exit!");
return false;
}
try {
FileInputStream is = new FileInputStream(file);
SlideShow ppt = new SlideShow(is);
is.close();
Dimension pgsize = ppt.getPageSize();
org.apache.poi.hslf.model.Slide[] slide = ppt.getSlides();
for (int i = 0; i < slide.length; i++) {
TextRun[] truns = slide[i].getTextRuns();
for (int k = 0; k < truns.length; k++) {
RichTextRun[] rtruns = truns[k].getRichTextRuns();
for (int l = 0; l < rtruns.length; l++) {
rtruns[l].setFontIndex(1);
rtruns[l].setFontName("宋體");
}
}
BufferedImage img = new BufferedImage(pgsize.width, pgsize.height,
BufferedImage.TYPE_INT_RGB);

Graphics2D graphics = img.createGraphics();
graphics.setPaint(Color.BLUE);
graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));
slide[i].draw(graphics);

// 這里設置圖片的存放路徑和圖片的格式(jpeg,png,bmp等等),注意生成文件路徑
File path = new File("D:/images");
if (!path.exists()) {
path.mkdir();
}
FileOutputStream out = new FileOutputStream(path + "/" + (i + 1)
+ ".jpg");
javax.imageio.ImageIO.write(img, "jpeg", out);
out.close();
}
System.out.println("success!!");
return true;
} catch (FileNotFoundException e) {
System.out.println(e);
} catch (IOException e) {
}
return false;
}

// function 檢查文件是否為PPT
public static boolean checkFile(File file) {

boolean isppt = false;
String filename = file.getName();
String suffixname = null;
if (filename != null && filename.indexOf(".") != -1) {
suffixname = filename.substring(filename.lastIndexOf("."));
if (suffixname.equals(".ppt")) {
isppt = true;
}
return isppt;
} else {
return isppt;
}
}

}

閱讀全文

與javaword轉圖片相關的資料

熱點內容
女同電影 瀏覽:367
在線能直接免費看的網站網頁 瀏覽:719
穿紅色衣服吹雪的圖片 瀏覽:825
韓國李熙拍了哪些電影 瀏覽:44
恐龍怎麼畫的圖片 瀏覽:6
不要放動畫片女孩的圖片 瀏覽:156
word調整圖片大小怎麼鎖定 瀏覽:581
在線播放電影國外 瀏覽:756
精彩動作電影 瀏覽:481
公主片公主片,公主 瀏覽:475
感恩的動漫圖片 瀏覽:781
女生ktv喝酒圖片 瀏覽:975
帶女孩看私人影院有什麼電影 瀏覽:661
最新那個啥網 瀏覽:19
男男電影H推薦 瀏覽:660
如何把圖片放於背景圖片下 瀏覽:356
超清壁紙動漫男生圖片 瀏覽:350
電影院簡筆畫圖片 瀏覽:894
怎麼發表qq說說與圖片 瀏覽:891
孔雀簡單拼盤圖片 瀏覽:489