当前位置: 首页 > wzjs >正文

做网站用php智能优化网站

做网站用php,智能优化网站,新冠疫苗上市公司,做发票网站Pdf转Word案例&#xff08;java&#xff09; 需要导入aspose-pdf.jar 需要先手动下载jar包到本地&#xff0c;然后通过systemPath在pom文件中引入。 下载地址&#xff1a;https://releases.aspose.com/java/repo/com/aspose/aspose-pdf/25.4/ <dependency><groupId&…

Pdf转Word案例(java)

需要导入aspose-pdf.jar 需要先手动下载jar包到本地,然后通过systemPath在pom文件中引入。

下载地址:https://releases.aspose.com/java/repo/com/aspose/aspose-pdf/25.4/

        <dependency><groupId>com.aspose</groupId><artifactId>aspose-pdf</artifactId><version>25.4</version><scope>system</scope><systemPath>C:/Users/aaa/Downloads/aspose-pdf-25.4.jar</systemPath></dependency>

主要功能总结

功能描述
PDF 创建与编辑创建、添加文本/图像/表格等
格式转换PDF ↔ Word/Excel/HTML/Image
合并与拆分合并多个 PDF 或按页拆分
安全保护加密/解密、权限设置
表单处理动态表单字段的创建与填充
内容提取提取文本、图像、元数据
高级操作水印、注释、页眉页脚、压缩优化

如果需要word转pdf,需要使用aspose-words.jar包。


1. 创建 PDF 文件

import com.aspose.pdf.Document;
import com.aspose.pdf.Page;
import com.aspose.pdf.TextFragment;public class CreatePdf {public static void main(String[] args) {// 创建空 PDF 文档Document doc = new Document();// 添加页面Page page = doc.getPages().add();// 添加文本TextFragment text = new TextFragment("Hello, Aspose.PDF!");text.getTextState().setFontSize(14);page.getParagraphs().add(text);// 保存 PDFdoc.save("output.pdf");}
}

2. PDF 转 Word (DOCX)

import com.aspose.pdf.Document;
import com.aspose.pdf.SaveFormat;public class PdfToWord {public static void main(String[] args) {Document doc = new Document("input.pdf");doc.save("output.docx", SaveFormat.DocX);}
}

3. PDF 转 HTML

import com.aspose.pdf.Document;
import com.aspose.pdf.HtmlSaveOptions;
import com.aspose.pdf.SaveFormat;public class PdfToHtml {public static void main(String[] args) {Document doc = new Document("input.pdf");HtmlSaveOptions options = new HtmlSaveOptions();doc.save("output.html", options);}
}

4. PDF 转图像(PNG/JPEG)

import com.aspose.pdf.Document;
import com.aspose.pdf.devices.JpegDevice;
import com.aspose.pdf.devices.Resolution;public class PdfToImage {public static void main(String[] args) {Document doc = new Document("input.pdf");// 设置分辨率(300 dpi)Resolution resolution = new Resolution(300);JpegDevice device = new JpegDevice(resolution);// 将每一页转为 JPEGfor (int i = 1; i <= doc.getPages().size(); i++) {device.process(doc.getPages().get_Item(i), "page_" + i + ".jpg");}}
}

5. 合并多个 PDF 文件

import com.aspose.pdf.Document;
import com.aspose.pdf.facades.PdfFileEditor;public class MergePdf {public static void main(String[] args) {PdfFileEditor editor = new PdfFileEditor();// 合并两个 PDF 文件editor.concatenate("input1.pdf", "input2.pdf", "merged.pdf");}
}

6. 拆分 PDF 文件

import com.aspose.pdf.facades.PdfFileEditor;public class SplitPdf {public static void main(String[] args) {PdfFileEditor editor = new PdfFileEditor();// 按页码拆分(例如:拆分前3页)editor.extract("input.pdf", 1, 3, "split.pdf");}
}

7. 添加水印

import com.aspose.pdf.*;
import com.aspose.pdf.facades.WatermarkArtifact;public class AddWatermark {public static void main(String[] args) {Document doc = new Document("input.pdf");// 添加水印文本WatermarkArtifact watermark = new WatermarkArtifact();watermark.setText("Confidential");watermark.getTextState().setFontSize(48);watermark.getTextState().setFont(FontRepository.findFont("Arial"));watermark.setOpacity(0.5);// 添加到每一页for (Page page : doc.getPages()) {page.getArtifacts().add(watermark);}doc.save("output.pdf");}
}

8. 加密/解密 PDF

import com.aspose.pdf.Document;
import com.aspose.pdf.facades.DocumentPrivilege;public class EncryptPdf {public static void main(String[] args) {Document doc = new Document("input.pdf");// 设置密码和权限doc.encrypt("user_pass", "owner_pass", DocumentPrivilege.getPrint(), CryptoAlgorithm.AESx256);doc.save("encrypted.pdf");}
}

9. 提取 PDF 文本

import com.aspose.pdf.Document;
import com.aspose.pdf.TextAbsorber;public class ExtractText {public static void main(String[] args) {Document doc = new Document("input.pdf");TextAbsorber absorber = new TextAbsorber();// 提取所有页面文本doc.getPages().accept(absorber);String extractedText = absorber.getText();System.out.println(extractedText);}
}

10. 添加表单字段

import com.aspose.pdf.*;public class AddFormField {public static void main(String[] args) {Document doc = new Document();Page page = doc.getPages().add();// 添加文本框TextBoxField textBox = new TextBoxField(page, new Rectangle(100, 600, 200, 650));textBox.setPartialName("text_field");textBox.setValue("Default Text");doc.getForm().add(textBox);doc.save("form.pdf");}
}

11. 添加页眉/页脚

import com.aspose.pdf.*;public class AddHeaderFooter {public static void main(String[] args) {Document doc = new Document("input.pdf");// 添加页眉TextFragment header = new TextFragment("Header Text");header.getTextState().setFontSize(12);header.setHorizontalAlignment(HorizontalAlignment.Center);// 添加到每一页for (Page page : doc.getPages()) {page.getParagraphs().add(header);}doc.save("output.pdf");}
}

12. 压缩 PDF

import com.aspose.pdf.Document;
import com.aspose.pdf.optimization.OptimizationOptions;public class CompressPdf {public static void main(String[] args) {Document doc = new Document("input.pdf");OptimizationOptions options = new OptimizationOptions();options.setRemoveUnusedObjects(true);options.setLinkDuplcateStreams(true);doc.optimizeResources(options);doc.save("compressed.pdf");}
}

13. 处理 PDF 注释

import com.aspose.pdf.*;public class AddAnnotation {public static void main(String[] args) {Document doc = new Document();Page page = doc.getPages().add();// 添加高亮注释HighlightAnnotation highlight = new HighlightAnnotation(page, new Rectangle(100, 600, 200, 650));highlight.setTitle("Important Note");highlight.setColor(Color.getYellow());page.getAnnotations().add(highlight);doc.save("annotated.pdf");}
}

注意事项

  1. 许可证:未应用许可证时,生成的文件会包含评估水印。通过以下代码激活:

    com.aspose.pdf.License license = new com.aspose.pdf.License();
    license.setLicense("Aspose.PDF.Java.lic");
    
  2. 依赖管理:建议通过 Maven/Gradle 管理依赖,确保使用最新版本。

  3. 文档参考:完整 API 文档见 Aspose.PDF for Java Documentation。

http://www.dtcms.com/wzjs/23891.html

相关文章:

  • 网站建设mdf360建站系统
  • 网站中文域名续费是什么情况专业北京网站建设公司
  • 比较好看的网站设计怎样建立一个自己的网站
  • 无锡谁做网站好个人网站推广
  • 十大没用的证书冯耀宗seo课程
  • 滕州做网站渠道策略的四种方式
  • 零基础怎么学网页设计seoapp推广
  • 广西网站建设哪里有谷歌网页版入口在线
  • 网站制作哪家便宜竞价托管哪家便宜
  • 三水网站建设企业搜索引擎优化技巧
  • 没有空间可以做网站吗自己做的网址如何推广
  • 企业网站建设排名口碑百度商家怎么入驻
  • 可以直接做ppt的网站自己如何制作一个网站
  • 大连做网站公司排行榜苏州关键词排名系统
  • 常州网站建设机构资源网站优化排名软件
  • 陈村网站建设什么是搜索引擎营销?
  • 厦门微网站建设公司湖南产品网络推广业务
  • 网站建设行业前景如何百度关键词查询排名怎么查
  • 长春火车站出站要求朋友圈广告推广平台
  • 哪些可以免费做网站科技网站建设公司
  • 工程信息网站谁做怎么自己开网站
  • 合肥大型网站制seo博客模板
  • jsp做的婚恋网站免费网站怎么做出来的
  • 溧阳 做网站seo整站优化一年价格多少
  • 淄博 网站设计扬州seo推广
  • 企业网站建设网做网站的费用
  • 网站备案 接口大二网页设计作业成品
  • 上海注册公司核名网站结构优化
  • 2017年政府网站建设的讲话外国网站怎么进入
  • wordpress ajax 主题seo排名优化软件有