利用aspose进行word转pdf、打印pdf

Word 转 PDF:

import com.aspose.words.Document;
import com.aspose.words.SaveFormat;
import com.aspose.words.SaveOptions;
import com.aspose.words.PdfSaveOptions;

public class WordToPdfConverter {

    public static void convertToPdf(String inputFilePath, String outputFilePath) {
        try {
            // 加载 Word 文档
            Document document = new Document(inputFilePath);

            // 设置 PDF 保存选项
            PdfSaveOptions saveOptions = new PdfSaveOptions();
            saveOptions.setSaveFormat(SaveFormat.PDF);

            // 保存为 PDF 文件
            document.save(outputFilePath, saveOptions);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        String inputFilePath = "path/to/your/input.docx";
        String outputFilePath = "path/to/your/output.pdf";

        convertToPdf(inputFilePath, outputFilePath);
        System.out.println("Conversion from Word to PDF completed.");
    }
}

打印 PDF:

import com.aspose.pdf.Document;
import com.aspose.pdf.PrinterSettings;

public class PdfPrinter {

    public static void printPdf(String inputFilePath) {
        try {
            // 加载 PDF 文档
            Document document = new Document(inputFilePath);

            // 创建打印机设置
            PrinterSettings printerSettings = new PrinterSettings();

            // 设置打印机
            printerSettings.setPrinterName("YourPrinterName");

            // 打印 PDF
            document.print(printerSettings);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        String inputFilePath = "path/to/your/input.pdf";

        printPdf(inputFilePath);
        System.out.println("PDF printed successfully.");
    }
}

相关推荐

  1. 利用aspose进行wordpdf打印pdf

    2024-01-29 21:30:01       74 阅读
  2. PDFWord

    2024-01-29 21:30:01       43 阅读
  3. Aspose将doc,pptpdf

    2024-01-29 21:30:01       25 阅读
  4. Python3进行pdf文件分割及word

    2024-01-29 21:30:01       48 阅读
  5. 【工具类】Word PDF

    2024-01-29 21:30:01       63 阅读
  6. word excel pptpdf

    2024-01-29 21:30:01       46 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-29 21:30:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-29 21:30:01       101 阅读
  3. 在Django里面运行非项目文件

    2024-01-29 21:30:01       82 阅读
  4. Python语言-面向对象

    2024-01-29 21:30:01       91 阅读

热门阅读

  1. 爬虫学习笔记-站长素材网站图片下载

    2024-01-29 21:30:01       56 阅读
  2. Linux之父:我们正在从C语言转向Rust

    2024-01-29 21:30:01       52 阅读
  3. 【Python笔记】设计模式

    2024-01-29 21:30:01       64 阅读
  4. 计算机网络之三次握手,四次挥手

    2024-01-29 21:30:01       54 阅读
  5. Mongodb查询投射中的$elemMatch

    2024-01-29 21:30:01       52 阅读
  6. VLM 系列——Monkey——论文解读

    2024-01-29 21:30:01       61 阅读
  7. Web 上升的圆心

    2024-01-29 21:30:01       46 阅读
  8. 用二分法在有序数列中查找元素位置

    2024-01-29 21:30:01       41 阅读