Skip to content

可访问性 (Accessibility)

从 8.4 版本开始,福昕 PDF SDK 支持对 PDF 文件进行标记 (tag)。

系统要求

  • 平台:Windows、Mac 和 Linux
  • 开发语言:C、C++、Java、C#、Python、Objective-C 和 Node.js
  • 授权许可:包含 Accessibility 模块的授权码
  • SDK 版本
    • 福昕 PDF SDK(C、C++、C#、Java、Python、Objective-C):8.4 或更高版本
    • 福昕 PDF SDK(Node.js):10.0 或更高版本

标记 PDF 文档

\examples\simple_demo\taggedpdf 文件夹下,福昕 PDF SDK 提供了一个标记 PDF 的示例程序,用来展示如何使用福昕 PDF SDK 对 PDF 文档进行标记。

c++
#include "include/common/fs_common.h"
#include "include/pdf/fs_pdfdoc.h"
#include "include/pdf/fs_pdfpage.h"
#include "include/addon/accessibility/fs_taggedpdf.h"

using namespace std;
using namespace foxit;
using namespace foxit::common;
using foxit::common::Library;
using namespace pdf;
using namespace foxit::addon::accessibility;
...
PDFDoc pdfDoc(input_file);
pdfDoc.Load();
TaggedPDF taggedpdf(pdfDoc);
Progressive progressive = taggedpdf.StartTagDocument(NULL);
Progressive::State progressState = Progressive::e_ToBeContinued;
while (Progressive::e_ToBeContinued == progressState)
progressState = progressive.Continue();
pdfDoc.SaveAs(output_file_path);
...
C
#include "include/fs_basictypes_c.h"
#include "include/fs_common_c.h"
#include "include/fs_pdfdoc_c.h"
#include "include/fs_pdfpage_c.h"
#include "include/fs_search_c.h"
#include "include/fs_convert_c.h"
#include "include/fs_taggedpdf_c.h"
...
FS_PDFDOC_HANDLE pdf_doc;
FSDK_PDFDoc_Create0(input_file, &pdf_doc);
FSDK_PDFDoc_Load(pdf_doc, NULL);
FS_TAGGEDPDF_HANDLE tagged_pdf;
error_code = FSDK_TaggedPDF_Create(pdf_doc, &tagged_pdf);
FS_PROGRESSIVE_HANDLE progressive;
FSDK_TaggedPDF_StartTagDocument(tagged_pdf, NULL, &progressive);
FSState progressive_state = e_FSToBeContinued;
while (progressive_state == e_FSToBeContinued)
  FSDK_Progressive_Continue(progressive, &progressive_state);
FS_BOOL return_value = false;
error_code = FSDK_PDFDoc_SaveAs(pdf_doc, output_file, 0, &return_value);
FSDK_TaggedPDF_Release(tagged_pdf);
FSDK_PDFDoc_Release(pdf_doc);
...
java
import com.foxit.sdk.common.Progressive;
import com.foxit.sdk.pdf.PDFDoc;
import com.foxit.sdk.addon.accessibility.*;
import com.foxit.sdk.common.fxcrt.RectF;
....
PDFDoc pdfDoc= new PDFDoc(input_file);
pdfDoc.load(null);
TaggedPDF taggedpdf = new TaggedPDF(pdfDoc);
Progressive progressive = taggedpdf.startTagDocument(null);
int progressState = Progressive.e_ToBeContinued;
while (Progressive.e_ToBeContinued == progressState)
  progressState = progressive.resume();

pdfDoc.saveAs(output_file_path, 0);
....
py
import sys
import site

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

if _PYTHON2_:
    site.addsitedir('../../../')
    from FoxitPDFSDKPython2 import *
else:
    from FoxitPDFSDKPython3 import *
....
pdfDoc = PDFDoc(input_file)
pdfDoc.Load("")
taggedpdf = TaggedPDF(pdfDoc)
progressive = taggedpdf.StartTagDocument(None)
progressState = Progressive.e_ToBeContinued
while (Progressive.e_ToBeContinued == progressState):
    progressState = progressive.Continue()

pdfDoc.SaveAs(output_file_path, PDFDoc.e_SaveFlagNoOriginal)
objc
#include "FSPDFObjC.h"
...
FSPDFDoc* doc = [[FSPDFDoc alloc] initWithPath:inputFile];
FSErrorCode errorCode = [doc load:nil];
if (errorCode != FSErrSuccess) {
    NSLog(@"The Doc [%@] Error: %ld", inputFile, errorCode);
    return -1;
}
FSTaggedPDF* taggedpdf = [[FSTaggedPDF alloc] initWithDoc:doc];
FSProgressive* progressive = [taggedpdf startTagDocument:nil];
while([progressive resume] == FSProgressiveToBeContinued){
    ;
}
[doc saveAs:outputFile save_flags:FSPDFDocSaveFlagNoOriginal];
...
js
const FSDK = require("@foxitsoftware/foxit-pdf-sdk-node");
...

let pdfDoc = new FSDK.PDFDoc(input_file);
pdfDoc.Load("");
let taggedpdf = new FSDK.TaggedPDF(pdfDoc);
let progressive = taggedpdf.StartTagDocument(null);
let progressState = FSDK.Progressive.e_ToBeContinued;
while (FSDK.Progressive.e_ToBeContinued == progressState)
    progressState = progressive.Continue();
pdfDoc.SaveAs(output_file_path, FSDK.PDFDoc.e_SaveFlagNormal);
csharp
using foxit.common;
using foxit.common.fxcrt;
using foxit.addon.conversion;
using foxit.pdf;
using foxit.addon.accessibility;
...

using(pdf_doc=newPDFDoc(input_file))
{
    pdf_doc.Load(null);
    using(vartaggedpdf=newTaggedPDF(pdf_doc))
    {
        Progressiveprogressive=taggedpdf.StartTagDocument(null);
        Progressive.Statestate=Progressive.State.e_ToBeContinued;
        while(state==Progressive.State.e_ToBeContinued)
        {
            state=progressive.Continue();
        }
    }
    pdf_doc.SaveAs(output_file,0);
}
...