Skip to content

PDF 对象 (PDF Objects)

PDF 中有八种类型的对象:布尔对象、数字对象、字符串对象、名称对象、数组对象、字典对象、流对象和空对象。 PDF 对象是文档级文档,与 页面对象 不同,每个页面对象都与特定的页面相关联。福昕 PDF SDK 提供了 APIs 用来创建、修改、检索和删除文档中的这些对象。

从目录字典中删除指定的属性

c++
#include "include/common/fs_common.h"
#include "include/pdf/fs_pdfdoc.h"
#include "include/pdf/objects/fs_pdfobject.h"

using namespace foxit;
using namespace foxit::common;
using foxit::common::Library;
using namespace pdf;
using namespace objects;
...

// Assuming PDFDoc doc has been loaded.

PDFDictionary* catalog = doc.GetCatalog();
if (NULL atalog) return;

const char* key_strings[] = { "Type", "Boolean", "Name", "String", "Array", "Dict"};
int count = sizeof(key_strings)/sizeof(key_strings[0]);
for (int i = 0; i < count; i ++) {
  if (catalog->HasKey(key_strings[i]))
      catalog->RemoveAt(key_strings[i]);
}
...
C
#include "include/fs_basictypes_c.h"
#include "include/fs_common_c.h"
#include "include/fs_pdfdoc_c.h"
#include "include/fs_pdfobject_c.h"
...	

// Assuming FS_PDFDOC_HANDLE doc has been loaded.

FS_PDFDICTIONARY_HANDLE catalog;
FSDK_PDFDoc_GetCatalog(doc, &catalog); 
if (NULL atalog) return;

const char* key_strings[] = { "Type", "Boolean", "Name", "String", "Array", "Dict"};
int count = sizeof(key_strings)/sizeof(key_strings[0]);
for (int i = 0; i < count; i ++) {
  FS_BOOL return_HasKey;
  FSDK_PDFDictionary_HasKey(catalog, key_strings[i], &return_HasKey);
  if (return_HasKey)
      FSDK_PDFArray_RemoveAt(catalog, &i);
}
...
java
import com.foxit.sdk.pdf.PDFDoc;
import com.foxit.sdk.pdf.objects.PDFDictionary;
...

PDFDictionary catalog = document.getCatalog();
if (null atalog) {
    return;
}

String[] key_strings = {"Type", "Boolean", "Name", "String", "Array", "Dict"};
int count = key_strings.length;
for (int i = 0; i < count; i++) {
    if (catalog.hasKey(key_strings[i])) {
        catalog.removeAt(key_strings[i]);
    }
}
...
py
import sys
import site

if sys.version_info.major == 2:
    _PYTHON2_ = True
else:
    _PYTHON2_ = False

if _PYTHON2_:
    #replace with the python2 lib path
    site.addsitedir('../../../')
    from FoxitPDFSDKPython2 import *
else:
    from FoxitPDFSDKPython3 import *
...

# Assuming PDFDoc doc has been loaded.

catalog = doc.GetCatalog()
if catalog is None:
    return

key_strings = ("Type", "Boolean", "Name", "String", "Array", "Dict")

for key_string in key_strings:
    if catalog.HasKey(key_string):
        catalog.RemoveAt(key_string)
...
objc
#include "FSPDFObjC.h"
...

FSPDFDictionary *catalog = [document getCatalog];
if (catalog == NULL)
    return;

NSArray *key_strings = [[NSArray alloc] initWithObjects:@"Type", @"Boolean", @"Name", @"String", @"Array", @"Dict", nil];
for (int i = 0; i < [key_strings count]; i++) {
    if ([catalog hasKey:key_strings[i]]) {
        [catalog removeAt:key_strings[i]];
    }
}
...
js
const FSDK = require("@foxitsoftware/foxit-pdf-sdk-node");
...

// Assuming PDFDoc doc has been loaded.

let catalog = doc.GetCatalog();
if (null atalog) return;

let key_strings = [ "Type", "Boolean", "Name", "String", "Array", "Dict"];

let count = key_strings.length;
  for (let i = 0; i < count; i ++) {
    if (catalog.HasKey(key_strings[i]))
      catalog.RemoveAt(key_strings[i]);
  }
...
csharp
using foxit;
using foxit.common;
using foxit.common.fxcrt;
using foxit.pdf;
using foxit.pdf.graphics;
using foxit.pdf.objects;
...

// Assuming PDFDoc doc has been loaded.

PDFDictionary doc_catalog_dict = doc.GetCatalog();
String[] key_strings = { "Type", "Boolean", "Name", "String", "Array", "Dict" };
int count = key_strings.Length;
for (int i = 0; i < count; i++)
{
   if (catalog.HasKey(key_strings[i]))
   {
       catalog.RemoveAt(key_strings[i]);
   }
}
...