導航:首頁 > 文字圖片 > 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轉圖片相關的資料

熱點內容
男生新年圖片大全 瀏覽:149
小陽台裝修效果圖大全2013圖片 瀏覽:507
天梭女士表價格及圖片 瀏覽:294
浪漫愛情文字圖片唯美 瀏覽:551
ad原理圖如何放入圖片 瀏覽:492
花朵畫教程簡單圖片 瀏覽:989
wps中word批量插入pdf圖片 瀏覽:833
女孩子車禍受傷圖片 瀏覽:577
漂亮女孩壁紙高清圖片 瀏覽:788
簡單圓形邊框圖片 瀏覽:844
至尊寶衣服小學生圖片 瀏覽:898
可愛紙箱汽車圖片 瀏覽:151
過來舉高高圖片帶文字 瀏覽:616
一群短發女生背影圖片 瀏覽:234
警察開會照片高清圖片 瀏覽:781
女生帆布鞋真實圖片 瀏覽:604
三頭身的動漫人物圖片 瀏覽:468
李科宏荷花高清圖片 瀏覽:994
男生包莖前後對比圖片 瀏覽:942
簡單的水彩畫步驟圖片 瀏覽:72