没有找到合适的产品?
联系客服协助选型:023-68661681
提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
翻译|行业资讯|编辑:胡涛|2023-08-17 11:24:58.980|阅读 50 次
概述:在本文中,您将学习如何使用Spire.Doc for Java将 Word 转换为流行的图像格式,例如JPG、PNG和SVG。欢迎查阅~
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
相关链接:
您可能需要将 Word 文档转换为图像的原因有很多。例如,很多设备不需要任何特殊软件就可以直接打开并显示图像,并且图像在传输时其内容很难被篡改。在本文中,您将学习如何使用Spire.Doc for Java将 Word 转换为流行的图像格式,例如JPG、PNG和SVG。
Spire.Doc 是一款专门对 Word 文档进行操作的 类库。在于帮助开发人员无需安装 Microsoft Word情况下,轻松快捷高效地创建、编辑、转换和打印 Microsoft Word 文档。拥有近10年专业开发经验Spire系列办公文档开发工具,专注于创建、编辑、转换和打印Word/PDF/Excel等格式文件处理,小巧便捷,除此之外,你也可以浏览E-iceblue 旗下其他不同语言的文档开发工具~
Spire.Doc for.net下载 Spire.Doc for java下载
首先,您需要将 Spire.Doc.jar 文件添加为 Java 程序中的依赖项。可以从此链接下载 JAR 文件。如果您使用 Maven,则可以通过将以下代码添加到项目的 pom.xml 文件中来轻松将 JAR 文件导入到应用程序中。
<repositories> <repository> <id>com.e-iceblue</id> <name>e-iceblue</name> <url>//repo.e-iceblue.com/nexus/content/groups/public/</url> </repository> </repositories> <dependencies> <dependency> <groupId>e-iceblue</groupId> <artifactId>spire.doc</artifactId> <version>11.8.1</version> </dependency> </dependencies>
Spire.Doc for Java 提供Document.saveToImages()方法将整个 Word 文档转换为单独的BufferedImage图像。然后,每个 BufferedImage 都可以保存为BMP、EMF、JPEG、PNG、GIF或WMF文件。以下是使用此库将 Word 转换为 JPG 的步骤。
import com.spire.doc.Document; 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 ConvertWordToJPG { public static void main(String[] args) throws IOException { //Create a Document object Document doc = new Document(); //Load a Word document doc.loadFromFile("C:\\Users\\Administrator\\Desktop\\ConvertTemplate.docx"); //Convert the whole document into individual buffered images BufferedImage[] images = doc.saveToImages(ImageType.Bitmap); //Loop through the images for (int i = 0; i < images.length; i++) { //Get the specific image BufferedImage image = images[i]; //Re-write the image with a different color space BufferedImage newImg = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB); newImg.getGraphics().drawImage(image, 0, 0, null); //Write to a JPG file File file = new File("C:\\Users\\Administrator\\Desktop\\Images\\" + String.format(("Image-%d.jpg"), i)); ImageIO.write(newImg, "JPEG", file); } } }
使用 Spire.Doc for Java,您可以将 Word 文档保存为字节数组列表。然后可以将每个字节数组写入 SVG 文件。将Word转换为SVG的详细步骤如下。
import com.spire.doc.Document; import java.io.FileOutputStream; import java.io.IOException; import java.util.List; public class ConvertWordToSVG { public static void main(String[] args) throws IOException { //Create a Document object Document doc = new Document(); //Load a Word document doc.loadFromFile("C:\\Users\\Administrator\\Desktop\\ConvertTemplate.docx"); //Save the document as a list of byte arrays List<byte[]> svgBytes = doc.saveToSVG(); //Loop through the items in the list for (int i = 0; i < svgBytes.size(); i++) { //Get a specific byte array byte[] byteArray = svgBytes.get(i); //Specify the output file name String outputFile = String.format("Image-%d.svg", i); //Write the byte array to a SVG file try (FileOutputStream stream = new FileOutputStream("C:\\Users\\Administrator\\Desktop\\Images\\" + outputFile)) { stream.write(byteArray); } } } }
分辨率越高的图像通常越清晰。您可以按照以下步骤在将 Word 转换为 PNG 时自定义图像分辨率。
import com.spire.doc.Document; 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 ConvertWordToPNG { public static void main(String[] args) throws IOException { //Create a Document object Document doc = new Document(); //Load a Word document doc.loadFromFile("C:\\Users\\Administrator\\Desktop\\ConvertTemplate.docx"); //Convert the whole document into individual buffered images with customized resolution BufferedImage[] images = doc.saveToImages(0, doc.getPageCount(), ImageType.Bitmap, 150, 150); //Loop through the images for (int i = 0; i < images.length; i++) { //Get the specific image BufferedImage image = images[i]; //Write to a PNG file File file = new File("C:\\Users\\Administrator\\Desktop\\Images\\" + String.format(("Image-%d.png"), i)); ImageIO.write(image, "PNG", file); } } }
以上便是如何在Java中将 Word 转换为图像,如果您有其他问题也可以继续浏览本系列文章,获取相关教程,你还可以给我留言或者加入我们的官方技术交流群。
欢迎下载|体验更多E-iceblue产品
获取更多信息请咨询 ;技术交流Q群(767755948)
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@wqylolg.cn
SolidWorks eDrawings 通过 HOOPS 技术赋能多平台支持、模块化设计和功能扩展(如 AR/VR),推动制造业设计流程的创新与优化。
本文将从产品功能、核心优势及行业应用场景三个维度,解析Aspose的热门产品如何助力企业提升文档管理效率。
产线级 MES 通过与检测设备的深度集成,实现数据的自动采集和智能分析,为企业提供更加精准、高效的质量管理方案。
Spire.Doc for .NET 是一款专门对 Word 文档进行操作的 .NET 类库。
Spire.Doc for JavaSpire.Doc for Java是Java Word组件,具有生成、读取、转换Word文档等功能
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@wqylolg.cn
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢