FPdfDocumentCore는 RTL 유닛과 FPdfAsync에만 의존하며, PDFium, FPdfView, VCL, LCL, Graphics, 윈도우 컨트롤을 임포트하지 않습니다
TPdfDocumentCore는 독립적인 네이티브 문서와 입력 바이트를 소유합니다. 로드/스트림 스냅샷, Unicode 추출, 페이지 크기, raw BGRA 렌더링, 빈 페이지 삽입, 페이지 삭제, 회전, 상한이 있는 전체 저장 바이트를 지원합니다
클래식 컴포넌트와 통합할 때는 기존 TPdf.CreateCoreSnapshot 어댑터를 사용하세요. 기존 TPdf와 뷰어 소스는 그대로 호환되며, 반환된 코어를 편집해도 원본 래퍼는 바뀌지 않습니다
독립적인 RTL 호스트가 PDFium을 로드하고 초기화한 뒤 TPdfCoreSymbolResolver와 IInterface 수명 소유자를 BindPdfDocumentCoreRuntime에 넘기고, 반환된 IPdfDocumentCoreRuntime을 코어 문서에 전달합니다
리졸버는 문서를 열기 전에 필요한 모든 익스포트를 바인딩합니다. 수명 소유자는 마지막 참조가 해제될 때까지 같은 초기화된 네이티브 모듈과 그 설정을 살려 두어야 합니다
코어는 호출자의 네이티브 모듈을 직접 초기화하거나 파괴하지 않습니다. 여러 문서가 하나의 런타임을 공유할 수 있고, 모든 핸들/버퍼는 런타임의 수명 소유자보다 먼저 해제됩니다
클래식 스냅샷 어댑터는 설정된 래퍼 모듈을 고정하며, 코어 런타임이 살아 있는 동안 명시적인 UnloadLibrary는 거부합니다. 호스트/유닛 종료 전에 코어를 해제하세요
PDFium 호출의 동기화 책임은 호출자에게 그대로 있습니다. 런타임과 코어 문서는 백그라운드 작업을 추가하거나 네이티브 API를 thread-safe하게 만들지 않습니다
LoadBytes는 소스 바이트를 복사하고 네이티브 로드와 페이지/폼 검사를 통과한 뒤에만 새 문서를 받아들입니다. 잘못된 입력이나 취소 시에는 이전 활성 문서를 유지합니다
LoadStream은 입력 예산 안에서 오프셋 0부터 스트림 전체를 읽고, 교체 문서를 받아들이기 전에 원래 위치를 복원합니다. LoadFile은 쓰기 공유를 거부하며 파일을 열어 LoadStream으로 넘깁니다
암호는 embedded null이 없는 명시적인 네이티브 UTF-8 바이트 문자열입니다. Password와 SecurityHandlerRevision은 활성 문서의 보안 상태를 들여다보고, SaveBytes(RemoveSecurity)는 저장할 때 암호화를 유지하거나 벗겨 냅니다. InsertBlankPage, DeletePage, RotatePage는 암호로 보호된 문서의 암호화를 유지하면서 서명된 문서는 거부합니다
XFA 초기화, JavaScript 호스트 UI, 폼 작성 오버레이, 위젯 편집은 여전히 클래식 컴포넌트의 책임입니다. 코어 렌더링은 폼 작성 환경 없이 네이티브 페이지 콘텐츠와 일반 주석을 그립니다
모든 페이지 인덱스는 0 기반입니다. PageText는 네이티브 문자 및 UTF-16 출력 한도를 모두 적용해, 추출 과정에서 생성된 공백을 포함한 실제 네이티브 UTF-16 텍스트를 반환합니다. GetMetaText는 표준 Info 사전 태그(Title, Author, Subject, Keywords, Creator, Producer, CreationDate, ModDate 등)를 상한 있는 UTF-16 텍스트로 읽고, GetPageLabel은 0 기반 페이지의 라벨 문자열을 읽으며, GetFileVersion, GetDocPermissions, GetUserPermissions은 PDF 헤더 버전(PDF 1.7이면 17)과 권한 비트마스크를 들여다봅니다
GetMediaBox, GetCropBox, GetTrimBox, GetBleedBox, GetArtBox, GetPageBoundingBox는 페이지 바운딩 박스를 TPdfCoreBox(Left, Bottom, Right, Top)로 읽고 박스가 없으면 False를 돌려줍니다. SetMediaBox, SetCropBox, SetTrimBox, SetBleedBox, SetArtBox는 유한한 양수 박스 크기를 검증해 스테이징된 편집 파이프라인에서 대상 페이지를 갱신하고, FlattenPage는 스테이징된 편집 파이프라인에서 페이지 주석이나 widget을 평탄화합니다(평탄화했으면 1, 필요 없었으면 2 반환)
ImportPages는 전체 페이지 또는 1 기반 PDFium 페이지 범위 문자열(1,3-5 같은)을 임포트하고, ImportPagesByIndex는 다른 활성 비폼 TPdfDocumentCore의 0 기반 source 페이지 인덱스 배열을 스테이징된 편집 파이프라인 안에서 0 기반 삽입 위치에(-1이면 끝에) 임포트하며 MaxPages와 바이트 예산을 강제합니다
GetBookmarks는 순환 방지를 갖춘 채 문서 아웃라인 계층을 순회해 Title, 0 기반 Depth, ChildCount, IsOpen, 0 기반 TargetPageIndex(없으면 -1), ActionUri를 담은 TPdfCoreBookmarks를 돌려줍니다. GetAttachmentCount, GetAttachmentInfo, AddAttachment, DeleteAttachment는 스테이징된 편집 파이프라인에서 임베디드 첨부를 들여다보고 바꾸고, GetSignatureCount와 GetSignatureInfo는 디지털 서명 객체(SubFilter, Time, Reason, DocMDPPermission, ByteRange, Contents)를 들여다보고, GetPageCharCount, GetPageCharUnicode, GetPageCharBox, FindPageText는 문자별 코드포인트와 user-space 바운딩 박스, 부분 문자열 검색 결과를 노출하며, SaveBytesWithVersion, SaveToStream, SaveToFile은 PDF 헤더 버전 재정의(10..20) 옵션과 함께 비증분 스냅샷을 export합니다
페이지 편집에는 대화형 폼이 없는 문서가 필요합니다. 폼을 인식하는 편집은 여전히 클래식 래퍼에 있습니다
InsertBlankPage, DeletePage, RotatePage는 내부 전체 저장/다시 열기 단계에서 동작하며, 네이티브 지오메트리/개수 검사와 취소 검사를 통과한 뒤에만 활성 문서를 교체합니다
SaveBytes는 비증분 스냅샷을 반환합니다. 네이티브 라이터 콜백이 출력 예산을 강제하고 콜백 예외를 받아 처리해서 Pascal 예외가 C 경계를 넘지 않도록 합니다
RenderPage는 촘촘히 이어진 위→아래 방향 네이티브 BGRA 바이트와 Width, Height, Stride를 담은 TPdfCorePixels를 반환합니다. Stride는 Width의 4배이고 bitmap/canvas 객체는 만들지 않습니다
배경은 packed ARGB 값이며 기본값은 불투명 흰색입니다. Rotation은 0에서 3까지의 90도 단위 회전이고, 렌더링 프로파일에는 일반 주석이 포함됩니다
네이티브 연산은 부동 소수점 트랩을 일시적으로 마스킹하고 네이티브 pending exception 플래그를 지운 다음 호출자의 원래 예외 마스크를 복원합니다. 덕분에 호출자의 트랩 정책을 영구 바꾸지 않으면서 FPC에서도 유효한 네이티브 폰트 연산이 가능합니다
TPdfDocumentCoreOptions.Default는 입력/출력 128 MiB, 페이지 10,000장, 네이티브 문자/UTF-16 출력 단위 16,777,216개, 렌더링 픽셀 16,777,216개를 허용합니다
절대 최댓값은 입력/출력 512 MiB, 페이지 100,000장, 문자/UTF-16 출력 단위 16,777,216개, signed 버퍼 크기 제약을 받는 픽셀 268,435,456개, 삽입 페이지/렌더링 차원당 포인트/픽셀 32,768개입니다
협조적 취소는 네이티브 호출 전후와 라이터 콜백 안에서 검사합니다. 네이티브 로드, 텍스트, 렌더링 내부는 호출 도중에 중단되지 않습니다
단독 RTL 프로브는 선언된 교체 DLL로 Delphi와 FPC Win64에서 통과합니다. 클래식 래퍼/뷰어 브리지는 Delphi Win64에서 별도로 검증되며, 다른 플랫폼은 기존에 문서화된 검증 한도를 유지합니다
uses SysUtils, Classes, FPdfAsync;
type
EPdfDocumentCore=class(Exception);
{$IFDEF MSWINDOWS}
TPdfCoreUnsignedLong=Cardinal;
{$ELSE}
TPdfCoreUnsignedLong=NativeUInt;
{$ENDIF}
TPdfCoreSymbolResolver=function(const Name:AnsiString):Pointer of object;
TPdfCoreLoadMemory=function(Data:Pointer; Size:NativeUInt; Password:PAnsiChar):Pointer; cdecl;
TPdfCoreClose=procedure(Handle:Pointer); cdecl;
TPdfCoreCount=function(Handle:Pointer):Integer; cdecl;
TPdfCoreLoadPage=function(Document:Pointer; Index:Integer):Pointer; cdecl;
TPdfCoreDimension=function(Page:Pointer):Single; cdecl;
TPdfCoreTextPage=function(Page:Pointer):Pointer; cdecl;
TPdfCoreReadText=function(TextPage:Pointer; Start,Count:Integer; Buffer:PWideChar):Integer; cdecl;
TPdfCoreBitmapCreate=function(Width,Height,Format:Integer; Buffer:Pointer; Stride:Integer):Pointer; cdecl;
TPdfCoreBitmapFill=function(Bitmap:Pointer; Left,Top,Width,Height:Integer; Color:TPdfCoreUnsignedLong):Integer; cdecl;
TPdfCoreRender=procedure(Bitmap,Page:Pointer; X,Y,Width,Height,Rotation,Flags:Integer); cdecl;
TPdfCoreLastError=function:TPdfCoreUnsignedLong; cdecl;
PPdfCoreFileWrite=^TPdfCoreFileWrite;
TPdfCoreWriteBlock=function(Self:PPdfCoreFileWrite; Buffer:Pointer; Size:TPdfCoreUnsignedLong):Integer; cdecl;
TPdfCoreFileWrite=record
Version:Integer;
WriteBlock:TPdfCoreWriteBlock;
end;
TPdfCoreSave=function(Document:Pointer; Writer:PPdfCoreFileWrite; Flags:TPdfCoreUnsignedLong):Integer; cdecl;
TPdfCoreNewDocument=function:Pointer; cdecl;
TPdfCoreNewPage=function(Document:Pointer; Index:Integer; Width,Height:Double):Pointer; cdecl;
TPdfCoreDeletePage=procedure(Document:Pointer; Index:Integer); cdecl;
TPdfCoreRotatePage=procedure(Page:Pointer; Rotation:Integer); cdecl;
TPdfCoreMetaText=function(Document:Pointer; Tag:PAnsiChar; Buffer:PWideChar; BufferLen:TPdfCoreUnsignedLong):TPdfCoreUnsignedLong; cdecl;
TPdfCorePageLabel=function(Document:Pointer; PageIndex:Integer; Buffer:PWideChar; BufferLen:TPdfCoreUnsignedLong):TPdfCoreUnsignedLong; cdecl;
TPdfCoreFileVersion=function(Document:Pointer; var FileVersion:Integer):Integer; cdecl;
TPdfCorePermissions=function(Document:Pointer):TPdfCoreUnsignedLong; cdecl;
TPdfCoreGetPageBox=function(Page:Pointer; var Left,Bottom,Right,Top:Single):Integer; cdecl;
TPdfCoreSetPageBox=procedure(Page:Pointer; Left,Bottom,Right,Top:Single); cdecl;
TPdfCoreRectF=record Left,Top,Right,Bottom:Single end;
TPdfCoreGetPageBoundingBox=function(Page:Pointer; var Rect:TPdfCoreRectF):Integer; cdecl;
TPdfCoreFlattenPage=function(Page:Pointer; Flag:Integer):Integer; cdecl;
TPdfCoreImportPages=function(DestDoc,SrcDoc:Pointer; PageRange:PAnsiChar; Index:Integer):Integer; cdecl;
TPdfCoreImportPagesByIndex=function(DestDoc,SrcDoc:Pointer; PageIndices:PInteger; Length:TPdfCoreUnsignedLong; Index:Integer):Integer; cdecl;
TPdfCoreSaveWithVersion=function(Document:Pointer; Writer:PPdfCoreFileWrite; Flags:TPdfCoreUnsignedLong; FileVersion:Integer):Integer; cdecl;
TPdfCoreBookmarkRel=function(Document,Handle:Pointer):Pointer; cdecl;
TPdfCoreBufferRead=function(Handle,Buffer:Pointer; BufferLen:TPdfCoreUnsignedLong):TPdfCoreUnsignedLong; cdecl;
TPdfCoreActionUriPath=function(Document,Action,Buffer:Pointer; BufferLen:TPdfCoreUnsignedLong):TPdfCoreUnsignedLong; cdecl;
TPdfCoreDestPageIndex=function(Document,Dest:Pointer):Integer; cdecl;
TPdfCoreAddAttachment=function(Document:Pointer; Name:PWideChar):Pointer; cdecl;
TPdfCoreDeleteAttachment=function(Document:Pointer; Index:Integer):Integer; cdecl;
TPdfCoreAttachmentSetFile=function(Attachment,Document,Contents:Pointer; Len:TPdfCoreUnsignedLong):Integer; cdecl;
TPdfCoreAttachmentGetFile=function(Attachment,Buffer:Pointer; BufferLen:TPdfCoreUnsignedLong; var OutBufLen:TPdfCoreUnsignedLong):Integer; cdecl;
TPdfCoreTextUnicode=function(TextPage:Pointer; Index:Integer):Cardinal; cdecl;
TPdfCoreTextCharBox=function(TextPage:Pointer; Index:Integer; var Left,Right,Bottom,Top:Double):Integer; cdecl;
TPdfCoreTextFindStart=function(TextPage:Pointer; FindWhat:PWideChar; Flags:TPdfCoreUnsignedLong; StartIndex:Integer):Pointer; cdecl;
TPdfCoreSigByteRange=function(Signature:Pointer; Buffer:PInteger; Length:TPdfCoreUnsignedLong):TPdfCoreUnsignedLong; cdecl;
TPdfCoreSigPermission=function(Signature:Pointer):Cardinal; cdecl;
TPdfCoreApi=record
LoadMemory:TPdfCoreLoadMemory;
CloseDocument,ClosePage,CloseTextPage,DestroyBitmap,TextFindClose:TPdfCoreClose;
PageCount,CharacterCount,FormType,SignatureCount,SecurityRevision,PageRotation,
BookmarkGetCount,AttachmentCount,TextFindNext,TextGetSchResultIndex,TextGetSchCount:TPdfCoreCount;
LoadPage,GetAttachment,GetSignatureObject:TPdfCoreLoadPage;
PageWidth,PageHeight:TPdfCoreDimension;
LoadTextPage,BookmarkGetAction:TPdfCoreTextPage;
ReadText:TPdfCoreReadText;
CreateBitmap:TPdfCoreBitmapCreate;
FillBitmap:TPdfCoreBitmapFill;
Render:TPdfCoreRender;
LastError:TPdfCoreLastError;
Save:TPdfCoreSave;
SaveWithVersion:TPdfCoreSaveWithVersion;
NewDocument:TPdfCoreNewDocument;
NewPage:TPdfCoreNewPage;
DeletePage:TPdfCoreDeletePage;
RotatePage:TPdfCoreRotatePage;
MetaText,AttachmentGetStringValue:TPdfCoreMetaText;
PageLabel:TPdfCorePageLabel;
FileVersion:TPdfCoreFileVersion;
DocPermissions,UserPermissions,ActionGetType:TPdfCorePermissions;
GetMediaBox,GetCropBox,GetTrimBox,GetBleedBox,GetArtBox:TPdfCoreGetPageBox;
SetMediaBox,SetCropBox,SetTrimBox,SetBleedBox,SetArtBox:TPdfCoreSetPageBox;
GetPageBoundingBox:TPdfCoreGetPageBoundingBox;
FlattenPage:TPdfCoreFlattenPage;
ImportPages:TPdfCoreImportPages;
ImportPagesByIndex:TPdfCoreImportPagesByIndex;
BookmarkGetFirstChild,BookmarkGetNextSibling,BookmarkGetDest,ActionGetDest:TPdfCoreBookmarkRel;
BookmarkGetTitle,AttachmentGetName,SigGetContents,SigGetSubFilter,SigGetReason,SigGetTime:TPdfCoreBufferRead;
ActionGetUriPath:TPdfCoreActionUriPath;
DestGetPageIndex:TPdfCoreDestPageIndex;
AddAttachment:TPdfCoreAddAttachment;
DeleteAttachment:TPdfCoreDeleteAttachment;
AttachmentSetFile:TPdfCoreAttachmentSetFile;
AttachmentGetFile:TPdfCoreAttachmentGetFile;
TextGetUnicode:TPdfCoreTextUnicode;
TextGetCharBox:TPdfCoreTextCharBox;
TextFindStart:TPdfCoreTextFindStart;
SigGetByteRange:TPdfCoreSigByteRange;
SigGetDocMDPPermission:TPdfCoreSigPermission;
end;
IPdfDocumentCoreRuntime=interface
['{92C8C1EB-5EE2-437D-A2A1-EF50DBB30A68}']
function Api:TPdfCoreApi;
end;
TPdfDocumentCoreOptions=record
MaxDocumentBytes,MaxOutputBytes,MaxPages,MaxCharacters,MaxRenderPixels:Integer;
CancellationToken:IPdfCancellationToken;
class function Default:TPdfDocumentCoreOptions; static;
end;
TPdfCorePageSize=record Width,Height:Double end;
TPdfCoreBox=record Left,Bottom,Right,Top:Double end;
TPdfCorePixels=record
Width,Height,Stride:Integer;
Samples:TBytes;
end;
TPdfCoreBookmarkInfo=record
Title:WideString;
Depth,ChildCount,TargetPageIndex:Integer;
IsOpen:Boolean;
ActionUri:AnsiString;
end;
TPdfCoreBookmarks=array of TPdfCoreBookmarkInfo;
TPdfCoreAttachmentInfo=record
Name,CreationDate,ModificationDate,Checksum:WideString;
Data:TBytes;
end;
TPdfCoreTextMatch=record
StartIndex,Count:Integer;
end;
TPdfCoreTextMatches=array of TPdfCoreTextMatch;
TPdfCoreSignatureInfo=record
SubFilter,Time:AnsiString;
Reason:WideString;
DocMDPPermission:Cardinal;
ByteRange:array of Integer;
Contents:TBytes;
end;
TPdfDocumentCore=class
private
FRuntime:IPdfDocumentCoreRuntime;
FApi:TPdfCoreApi;
FOptions:TPdfDocumentCoreOptions;
FDocument:Pointer;
FSource:TBytes;
procedure Check;
procedure RequireActive;
function GetActive:Boolean;
function GetPageCount:Integer;
function OpenPage(Index:Integer):Pointer;
procedure AcceptDocument(Document:Pointer; const Source:TBytes);
procedure ChangePage(Kind,Index,QuarterTurns:Integer; Width,Height:Double);
procedure ChangePageBox(IsCrop:Boolean; Index:Integer; const Box:TPdfCoreBox);
public
constructor Create(const Runtime:IPdfDocumentCoreRuntime; const Options:TPdfDocumentCoreOptions);
destructor Destroy; override;
procedure Close;
procedure LoadBytes(const Data:TBytes; const Password:AnsiString='');
procedure LoadStream(Source:TStream; const Password:AnsiString='');
procedure LoadFile(const FileName:string; const Password:AnsiString='');
procedure NewDocument;
function GetMetaText(const Tag:AnsiString):WideString;
function GetPageLabel(Index:Integer):WideString;
function GetFileVersion:Integer;
function GetDocPermissions:Cardinal;
function GetUserPermissions:Cardinal;
function GetBookmarks:TPdfCoreBookmarks;
function GetAttachmentCount:Integer;
function GetAttachmentInfo(Index:Integer):TPdfCoreAttachmentInfo;
procedure AddAttachment(const Name:WideString; const Data:TBytes);
procedure DeleteAttachment(Index:Integer);
function GetSignatureCount:Integer;
function GetSignatureInfo(Index:Integer):TPdfCoreSignatureInfo;
function PageSize(Index:Integer):TPdfCorePageSize;
function GetMediaBox(Index:Integer; out Box:TPdfCoreBox):Boolean;
procedure SetMediaBox(Index:Integer; const Box:TPdfCoreBox);
function GetCropBox(Index:Integer; out Box:TPdfCoreBox):Boolean;
procedure SetCropBox(Index:Integer; const Box:TPdfCoreBox);
function GetTrimBox(Index:Integer; out Box:TPdfCoreBox):Boolean;
procedure SetTrimBox(Index:Integer; const Box:TPdfCoreBox);
function GetBleedBox(Index:Integer; out Box:TPdfCoreBox):Boolean;
procedure SetBleedBox(Index:Integer; const Box:TPdfCoreBox);
function GetArtBox(Index:Integer; out Box:TPdfCoreBox):Boolean;
procedure SetArtBox(Index:Integer; const Box:TPdfCoreBox);
function GetPageBoundingBox(Index:Integer; out Box:TPdfCoreBox):Boolean;
function FlattenPage(Index:Integer; ForPrint:Boolean=False):Integer;
function PageText(Index:Integer):WideString;
function GetPageCharCount(Index:Integer):Integer;
function GetPageCharUnicode(Index,CharIndex:Integer):Cardinal;
function GetPageCharBox(Index,CharIndex:Integer; out Box:TPdfCoreBox):Boolean;
function FindPageText(Index:Integer; const Pattern:WideString;
MatchCase:Boolean=False; MatchWholeWord:Boolean=False):TPdfCoreTextMatches;
function RenderPage(Index,Width,Height:Integer; Rotation:Integer=0;
Background:Cardinal=$FFFFFFFF):TPdfCorePixels;
procedure InsertBlankPage(Index:Integer; Width,Height:Double);
procedure DeletePage(Index:Integer);
procedure RotatePage(Index,QuarterTurns:Integer);
procedure ImportPages(Source:TPdfDocumentCore; const PageRange:AnsiString=''; InsertIndex:Integer=-1);
procedure ImportPagesByIndex(Source:TPdfDocumentCore; const PageIndices:array of Integer; InsertIndex:Integer=-1);
function SaveBytes(RemoveSecurity:Boolean=False):TBytes;
function SaveBytesWithVersion(FileVersion:Integer; RemoveSecurity:Boolean=False):TBytes;
procedure SaveToStream(Dest:TStream; RemoveSecurity:Boolean=False; FileVersion:Integer=0);
procedure SaveToFile(const FileName:string; RemoveSecurity:Boolean=False; FileVersion:Integer=0);
property Active:Boolean read GetActive;
property PageCount:Integer read GetPageCount;
property SecurityHandlerRevision:Integer read GetSecurityHandlerRevision;
property Password:AnsiString read FPassword;
end;
// The lifetime object owns an already initialized native library
// The runtime pins it until every core document releases its reference
function BindPdfDocumentCoreRuntime(Resolver:TPdfCoreSymbolResolver;
const Lifetime:IInterface):IPdfDocumentCoreRuntime;