导航:首页 > 编程语言 > javaword转图片

javaword转图片

发布时间:2022-08-24 05:58:32

Ⅰ 求java WORD 转图片 方法 有代码更好!

给你说个思路吧!
用java将word转换为图片,道理就是用java读取word然后写到图片上,就像生成验证码似的
其中会遇到的瓶颈是:1、word里面插入的图片,这个你要分开来判断。2、对于word多少页生成一张图片。还是整个word生成一个图片。
希望可以帮到你。

Ⅱ 用Java从word中提取出图片

因为太长了, 我放我空间了
思路是2003以后, word就可存为xml, 二进制数据按base64编码
然后可以按解析xml文档方式获取图片数据
然后对它进行解码--

Ⅲ 有什么方法可以用java 将word或者Excel文件转换成图片文件

可以用openoffice将word转化为pdf,再使用swftools把pdf转换为swf

Ⅳ java如何把excel和Word文档的每一页转换为图片

你可以看看
Apache POI HSSF and XSSF 快速指南帮助文档API poi-3.15————这个是excel的
还有word的api,不知道里面是否有你需要的
去Apache的官网看看吧,专门给office开发的,如果没有就没有了

Ⅳ 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;
}
}

}

Ⅵ 用java怎么将word文档转成图片格式

可以使用Spire.Doc for Java在Java中利用代码进行转换。需要在 Java 程序中添加Free Spire.Doc.jar文件作为依赖项。可以从这个链接下载 JAR 文件;如果使用Maven,则可以通过在 pom.xml 文件中添加以下代码导入 JAR 文件。

repositories>
<repository>
<id>com.e-iceblue</id>
<url>https://repo.e-iceblue.cn/repository/maven-public/</url>
</repository></repositories><dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.doc.free</artifactId>
<version>5.2.3</version>
</dependency></dependencies>

Java代码如下:

import com.spire.doc.Document;

import com.spire.doc.FileFormat;

import com.spire.doc.documents.ImageType;

import javax.imageio.ImageIO;

import java.awt.image.BufferedImage;

import java.io.File;

import java.io.IOException;

public class ConvertWordToOtherFormats {

public static void main(String[] args) throws IOException {

//创建Document对象
Document doc = new Document();

//加载Word文档
doc.loadFromFile("C:\Users\Administrator\Desktop\sample.docx");

//将指定页保存为BufferedImage
BufferedImage image= doc.saveToImages(0, ImageType.Bitmap);

//将图片数据保存为PNG格式文档
File file= new File("output/ToPNG.png");
ImageIO.write(image, "PNG", file);

//将Word保存为SVG格式
doc.saveToFile("output/ToSVG.svg",FileFormat.SVG);

//将Word保存为RTF格式
doc.saveToFile("output/ToRTF.rtf",FileFormat.Rtf);

//将Word保存为XPS格式
doc.saveToFile("output/ToXPS.xps",FileFormat.XPS);

//将Word保存为XML格式
doc.saveToFile("output/ToXML.xml",FileFormat.Xml);

//将Word保存为TXT格式
doc.saveToFile("output/ToTXT.txt",FileFormat.Txt);
}

}

Ⅶ java能把word文档和ppt转成图片格式的文件吗

网上论坛收收应该是有的。我在论坛上都下载了最难的PDF转换为word的还必须是中文的插件都有。

Ⅷ 用java程序如何读取word里面的图片

试试jacob,这个操作word的功能还是蛮多的。

Ⅸ JAVA编辑WORD文件插入图片

试试这个代码,需要添加spire.doc jar依赖

importcom.spire.doc.Document;
importcom.spire.doc.FileFormat;
importcom.spire.doc.Section;
importcom.spire.doc.documents.*;
importcom.spire.doc.fields.DocPicture;

publicclassInsertImage{

publicstaticvoidmain(String[]args){

//实例化Document对象
Documentdoc=newDocument();
//加载文档
doc.loadFromFile("C:\Users\Administrator\Desktop\test.docx");
//获取第一个section
Sectionsection=doc.getSections().get(0);
//添加一个段落
Paragraphpara=section.addParagraph();
//添加图片到段落
DocPicturepicture=para.appendPicture("C:\Users\Administrator\Desktop\Cartoon.png");
//设置文字环绕方式(居于文字上方)
picture.setTextWrappingStyle(TextWrappingStyle.In_Front_Of_Text);
//指定图片的相对位置
picture.setHorizontalOrigin(HorizontalOrigin.Page);
picture.setHorizontalPosition(250f);
picture.setVerticalOrigin(VerticalOrigin.Top_Margin_Area);
picture.setVerticalPosition(150f);
//设置图片大小
picture.setWidth(80f);
picture.setHeight(80f);
//保存到文档
doc.saveToFile("output/InsertImage.docx",FileFormat.Docx);
}
}

生成的Word:

Ⅹ java中怎么将word文档怎么生成图片

public class CreateWordDemo
{

public void createDocContext(String file)
throws DocumentException,IOException {

//
设置纸张大小

Document document = new
Document(PageSize.A4);

//
建立一个书写器(Writer)与document对象关联,通过书写器(Writer)可以将文档写入到磁盘中
RtfWriter2.getInstance(document, new
FileOutputStream(file));

document.open();

//
设置中文字体

BaseFont bfChinese =
BaseFont.createFont("STSongStd-Light", "UniGB-UCS2-H",
BaseFont.NOT_EMBEDDED);

//
标题字体风格

Font titleFont = new Font(bfChinese, 12,
Font.BOLD);

//
正文字体风格

Font contextFont = new Font(bfChinese, 10,
Font.NORMAL);

Paragraph title = new
Paragraph("标题");

//
设置标题格式对齐方式

title.setAlignment(Element.ALIGN_CENTER);

title.setFont(titleFont);

document.add(title);

String contextString =
"iText是一个能够快速产生PDF文件的java类库。"

+ " \n"//
换行
+
"iText的java类对于那些要产生包含文本,"

+ "表格,图形的只读文档是很有用的。它的类库尤其与java
Servlet有很好的给合。"

+
"使用iText与PDF能够使你正确的控制Servlet的输出。";

Paragraph context = new
Paragraph(contextString);

//
正文格式左对齐

context.setAlignment(Element.ALIGN_LEFT);

context.setFont(contextFont);

//
离上一段落(标题)空的行数

context.setSpacingBefore(5);

//
设置第一行空的列数

context.setFirstLineIndent(20);

document.add(context);

//
利用类FontFactory结合Font和Color可以设置各种各样字体样式Paragraph underline = new Paragraph("下划线的实现",
FontFactory.getFont(
FontFactory.HELVETICA_BOLDOBLIQUE, 18,
Font.UNDERLINE, new Color(0, 0,
255)));

document.add(underline);

// 设置 Table
表格

Table aTable = new
Table(3);

int width[] = { 25, 25, 50
};

aTable.setWidths(width);//
设置每列所占比例

aTable.setWidth(90); // 占页面宽度
90%

aTable.setAlignment(Element.ALIGN_CENTER);//
居中显示

aTable.setAlignment(Element.ALIGN_MIDDLE);//
纵向居中显示

aTable.setAutoFillEmptyCells(true); //
自动填满

aTable.setBorderWidth(1); //
边框宽度

aTable.setBorderColor(new Color(0, 125, 255)); //
边框颜色

aTable.setPadding(2);//
衬距,看效果就知道什么意思了

aTable.setSpacing(3);//
即单元格之间的间距

aTable.setBorder(2);//
边框
//
设置表头Cell haderCell = new
Cell("表格表头");

haderCell.setHeader(true);

haderCell.setColspan(3);

aTable.addCell(haderCell);

aTable.endHeaders();

Font fontChinese = new Font(bfChinese, 12, Font.NORMAL,
Color.GREEN);

Cell cell = new Cell(new Phrase("这是一个测试的 3*3 Table 数据",
fontChinese));
cell.setVerticalAlignment(Element.ALIGN_TOP);

cell.setBorderColor(new Color(255, 0,
0));

cell.setRowspan(2);

aTable.addCell(cell);

aTable.addCell(new
Cell("#1"));

aTable.addCell(new
Cell("#2"));

aTable.addCell(new
Cell("#3"));

aTable.addCell(new
Cell("#4"));

Cell cell3 = new Cell(new Phrase("一行三列数据",
fontChinese));

cell3.setColspan(3);

cell3.setVerticalAlignment(Element.ALIGN_CENTER);

aTable.addCell(cell3);

document.add(aTable);

document.add(new
Paragraph("\n"));

//
添加图片 Image.getInstance即可以放路径又可以放二进制字节流

Image img =
Image.getInstance("d:\\img01800.jpg");

img.setAbsolutePosition(0,
0);

img.setAlignment(Image.RIGHT);//
设置图片显示位置

img.scaleAbsolute(60, 60);//
直接设定显示尺寸

//
img.scalePercent(50);//表示显示的大小为原尺寸的50%

// img.scalePercent(25,
12);//图像高宽的显示比例

//
img.setRotation(30);//图像旋转一定角度

document.add(img);

document.close();

}public static void main(String[] args)
{

CreateWordDemo word = new
CreateWordDemo();

String file =
"d:/demo1.doc";

try
{

word.createDocContext(file);

} catch (DocumentException e)
{

e.printStackTrace();

} catch (IOException e)
{

e.printStackTrace();

}

}
}

阅读全文

与javaword转图片相关的资料

热点内容
阿里云服务器终端在哪里 浏览:144
app纸有什么用 浏览:219
cuteftp命令 浏览:502
最开始的编程语言是什么 浏览:757
at远程命令 浏览:490
云服务器哪家好点 浏览:211
android系统源码阅读 浏览:924
dumpjava分析工具 浏览:678
怎么下载cpu源码 浏览:154
代码加密怎么取消 浏览:888
编译原理代码在哪里运行 浏览:584
解密摄影pdf 浏览:72
算法编程中级题目 浏览:250
c语言编译器毕业设计 浏览:717
医保卡申请app哪个好 浏览:945
阿里云服务器上传源码 浏览:602
营销管理科特勒pdf 浏览:696
愿望清单app哪个好 浏览:461
安卓外放声音怎么解决 浏览:196
脉脉app干什么用的 浏览:361