1. 首页
  2. Foxit PDF SDK(安卓版)
  3. 如何从指定的PDF文件路径打开一个PDF文档?

如何从指定的PDF文件路径打开一个PDF文档?

Foxit PDF SDK for Android提供了多个接口用来打开PDF文档。您可以从指定的PDF文件路径或从内存缓冲区打开一个PDF文档。对于指定的PDF文件路径,有两种方法可以使用。

第一种是使用openDoc接口,该接口包括以下的操作:创建PDF文档对象(PDFDoc(String path)),加载文档内容(load),以及将PDF文档对象设置给视图控件(setDoc)。以下是示例代码:

备注:openDoc接口仅可用于从文件路径打开PDF文档。如果需要自定义加载PDF文档,可以在回调函数 (FileRead) 中实现,然后使用带有回调函数FireRead 的PDFDoc (FileRead fileRead) 接口创建文档对象。接下来,使用load加载文档内容,并使用setDoc将PDF文档对象设置给视图控件。

// Assuming A PDFViewCtrl has been created.
// Open an unencrypted PDF document from a specified PDF file path.
String path = "/mnt/sdcard/input_files/Sample.pdf"; 
pdfViewCtrl.openDoc(path, null);

第二种是使用PDFDoc(String path) 接口创建PDF文档对象,使用load 接口加载文档内容,然后使用setDoc将PDF文档对象设置给视图控件。以下是示例代码:

// Assuming A PDFViewCtrl has been created.
String path = "/mnt/sdcard/input_files/Sample.pdf"; 
try {
       // Initialize a PDFDoc object with the path to the PDF file.
       PDFDoc document = new PDFDoc(path);

       // Load the unencrypted document content.
       document.load(null);

       // Set the document to view control.
       pdfViewCtrl.setDoc(document);
} catch (Exception e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
}
更新于 2020年3月23日

这篇文章有用吗?

相关文章