THotPDF.AddStructureElement 및 태그 지정 PDF 도우미
이 page는 현재 THotPDF tagged-PDF 및 PDF/UA structure-tree helper를 문서화합니다. Code identifier는 public declaration과 일치합니다
현재 Delphi 외관
function AddStructureElement(const Role: AnsiString; Parent: THPDFDictionaryObject;
PageIndex: Integer = -1; MCID: Integer = -1): THPDFDictionaryObject; overload;
function AddStructureElement(const Role: AnsiString; Parent: THPDFDictionaryObject;
PageIndex: Integer; MCID: Integer;
const AltText: AnsiString; const ActualText: AnsiString): THPDFDictionaryObject; overload;
function AddStructureElement(const Role: AnsiString; Parent: THPDFDictionaryObject;
PageIndex: Integer; MCID: Integer;
const AltText: AnsiString; const ActualText: AnsiString;
const IDStr: AnsiString): THPDFDictionaryObject; overload;
function AddStructureElement(T: THPDFStandardStructureType; Parent: THPDFDictionaryObject;
PageIndex: Integer = -1; MCID: Integer = -1): THPDFDictionaryObject; overload;
procedure SetStructureElementLanguage(Elem: THPDFDictionaryObject; const Lang: AnsiString);
procedure SetStructureElementExpansionText(Elem: THPDFDictionaryObject; const ExpansionText: AnsiString);
procedure SetStructureElementTitle(Elem: THPDFDictionaryObject; const Title: AnsiString);
procedure AddStructRoleMap(const SourceRole: AnsiString; const TargetRole: AnsiString);
function BeginTaggedContent(const Role: AnsiString; Parent: THPDFDictionaryObject;
const Lang: AnsiString = ''; const Alt: AnsiString = '';
const ActualText: AnsiString = ''; const ExpansionText: AnsiString = ''): THPDFDictionaryObject;
procedure EndTaggedContent;
function EmitTaggedHeading(Level: Integer; Parent: THPDFDictionaryObject; X, Y: Single; const Text: WideString): THPDFDictionaryObject;
function BeginTaggedList(Parent: THPDFDictionaryObject; const NumberingStyle: AnsiString = 'None'): THPDFDictionaryObject;
function EmitTaggedListItem(ListElem: THPDFDictionaryObject; LblX, LblY: Single; const LabelText: WideString; BodyX, BodyY: Single; const BodyText: WideString): THPDFDictionaryObject;
function BeginTaggedTable(Parent: THPDFDictionaryObject): THPDFDictionaryObject;
function AddTaggedTableRow(TableElem: THPDFDictionaryObject): THPDFDictionaryObject;
function EmitTaggedTableHeader(TRElem: THPDFDictionaryObject; X, Y: Single; const Text: WideString; const Scope: AnsiString): THPDFDictionaryObject;
function EmitTaggedTableCell(TRElem: THPDFDictionaryObject; X, Y: Single; const Text: WideString): THPDFDictionaryObject;
function BeginTaggedFigure(Parent: THPDFDictionaryObject; const AltText: AnsiString; const BBox: array of Single): THPDFDictionaryObject;
procedure EndTaggedFigure;
procedure RegisterAnnotForStructure(AnnotDict: THPDFDictionaryObject; StructElem: THPDFDictionaryObject);
function StandardStructureTypeToName(T: THPDFStandardStructureType): AnsiString;
function IsStandardStructureType(const Name: AnsiString): Boolean;
구조 요소 생성
AddStructureElement는 /StructElem dictionary를 만들고 Parent의 child로 append합니다(structure tree root 아래에 붙이려면 nil 전달). PageIndex는 /Pg를 통해 element를 해당 page에 연결합니다. 생략하려면 negative value를 전달하십시오. MCID가 0 이상이면 page의 marked-content sequence를 element와 연결하고 document /ParentTree에 등록합니다. Six-argument overload는 /Alt(figure와 formula 같은 non-text content를 소리 내어 읽을 때 사용하는 alternative description) 및 /ActualText(추출하기 어려운 glyph의 copy/paste 반환 replacement text)를 추가합니다. Seven-argument overload는 다른 structure element가 ID로 해당 element를 target할 수 있도록 document-unique /ID도 작성합니다(ISO 32000-1 §14.7.2)
표준 구조 유형 (Table 333)
THPDFStandardStructureType enum overload는 type-safe entry point입니다. Emit되는 /S role name은 ISO 32000-1 §14.8.4 Table 333의 standard structure type 중 하나임이 보장되므로 open-string overload의 typo 및 case-sensitivity 위험을 제거합니다. Enum은 이름을 specification family별로 묶습니다
- 그룹화:
sstDocument,sstPart,sstArt,sstSect,sstDiv,sstBlockQuote,sstCaption,sstTOC,sstTOCI,sstIndex,sstNonStruct,sstPrivate - 블록 수준:
sstH,sstH1-sstH6,sstP,sstL,sstLI,sstLbl,sstLBody,sstTable,sstTR,sstTH,sstTD,sstTHead,sstTBody,sstTFoot - 인라인 수준:
sstSpan,sstQuote,sstNote,sstReference,sstBibEntry,sstCode,sstLink,sstAnnot - 루비 및 와리추:
sstRuby,sstRB,sstRT,sstRP,sstWarichu,sstWT,sstWP - 일러스트레이션:
sstFigure,sstFormula,sstForm
sstLbl / sstLBody의 lowercase letter에 유의하십시오. Literal PDF role name은 Lbl 및 LBody입니다. Custom role name은 여전히 AnsiString overload로 전달하고 AddStructRoleMap으로 standard role에 다시 mapping할 수 있습니다
예제
PDF.PDFUACompliance := pdfuaPDFUA1;
PDF.BeginDoc;
Doc := PDF.AddStructureElement(sstDocument, nil);
H1 := PDF.AddStructureElement(sstH1, Doc);
PDF.SetStructureElementLanguage(Doc, 'en-US');
PDF.SetStructureElementTitle(H1, 'Annual Report');
// Alt / ActualText ride on the AnsiString overload; reuse the
// spec-prescribed role name via StandardStructureTypeToName
Fig := PDF.AddStructureElement(StandardStructureTypeToName(sstFigure), Doc, 0, -1,
'Sales by quarter: Q1 4.2M, Q2 5.1M, Q3 5.8M, Q4 6.4M', '');
구조 특성 및 역할 매핑
SetStructureElementLanguage는 BCP-47 /Lang override를 쓰고, SetStructureElementExpansionText는 /E expansion text를 쓰며, SetStructureElementTitle은 사람이 읽을 수 있는 /T title을 쓰고, AddStructRoleMap은 custom structure role을 standard PDF role로 다시 mapping합니다. StandardStructureTypeToName은 THPDFStandardStructureType 값에 대한 PDF role name을 반환하고, IsStandardStructureType은 role name이 standard role 중 하나인지 검사합니다
고급 태그 지정 도우미
EmitTaggedHeading, BeginTaggedList, EmitTaggedListItem, BeginTaggedTable, AddTaggedTableRow, EmitTaggedTableHeader, EmitTaggedTableCell, BeginTaggedFigure, EndTaggedFigure, RegisterAnnotForStructure는 호출자가 MCID를 수동으로 관리하지 않아도 common PDF/UA heading, list, table, figure, annotation wiring을 처리합니다
일반적인 워크플로
Tagged output 또는 PDFUACompliance를 enable하고 root structure element를 만든 뒤 helper family를 사용해 semantic content를 emit하십시오. EndDoc 전에 시작된 모든 tagged-content 또는 figure sequence를 닫아야 합니다