PDFium Delphi Component Docs

Composant TPdf

Unité: PDFium
TPdf
Utilisez le composant TPdf pour ouvrir, parcourir, extraire du texte et modifier des documents PDF

Cœur de document indépendant du framework

Utilisez FPdfDocumentCore pour une API document sans dépendance VCL/LCL ni Graphics, ou appelez TPdf.CreateCoreSnapshot pour adosser un composant existant à un instantané RTL seul indépendant

Profil du composant classique sans widgets

Définissez PDFIUMPAS_CORE_ONLY pour compiler l’API document de haut niveau sans le framework de widgets VCL/LCL : TPdfView, TPdfReadingSession et les helpers du viewer sont exclus, et les unités de widgets (Forms, Controls, Dialogs, ExtCtrls, Menus, Messages) disparaissent de la clause uses de l’unité sur les deux branches du compilateur ; seule Vcl.Graphics ou l’unité LCL Graphics reste pour l’API de rendu dans des buffers de pixels

Le profil par défaut conserve l’API classique, si bien que les projets existants compilent à l’identique ; un consommateur headless ajoute la définition et utilise TPdf directement pour le chargement, le texte, l’édition, la sauvegarde et le rendu dans des bitmaps ; CreateCoreSnapshot exporte en plus le document actif en un instantané borné TPdfDocumentCore indépendant

Les différences headless sont explicites : les timers de formulaires scriptés de PDFium se déclarent indisponibles (pas de pompe de messages de fenêtre), les invites JavaScript renvoient la réponse par défaut scriptée sans boîte de dialogue, les alertes utilisent la boîte de message Win32 brute, et les fonctionnalités visuelles du contrôle sont absentes ; le substitut inerte TPdfView garde la colle de remplissage de formulaires compilable sans qu’aucune instance ne soit jamais créée

Exemple

Pdf.FileName := 'document.pdf';
Pdf.Password := 'password';
Pdf.Active := True; // open PDF document
Pdf.PageNumber := 1; // select page
ShowMessage(Pdf.Text); // extract text

Types

type TBookmark = record
  Handle: FPDF_BOOKMARK;
  Title: WString;
  PageNumber: Integer;
  Destination: TDestination;
  DescendantCount: Integer;
  IsOpen: Boolean;
  Action: TPdfAction;
  ActionPageNumber: Integer;
  ActionDestination: TDestination;
  ActionPath: WString;
  HasColor: Boolean;
  Color: TColor;
  Style: TPdfOutlineStyle;
end;

type TBookmarks = array of TBookmark;

Données de signet

 

type TDestination = record
  Handle: FPDF_DEST;
  Name: WString;
  PageNumber: Integer;
  ViewMode: TPdfDestinationViewMode;
  ViewParameterCount: Integer;
  ViewParameters: TPdfDestinationViewParameters;
  HasX: Boolean;
  X: Single;
  HasY: Boolean;
  Y: Single;
  HasZoom: Boolean;
  Zoom: Single;
end;

Données de destination nommée

 

type TPdfDestinationViewMode = (dvmUnknown, dvmXYZ, dvmFit, dvmFitHorizontal, dvmFitVertical, dvmFitRectangle, dvmFitBoundingBox, dvmFitBoundingBoxHorizontal, dvmFitBoundingBoxVertical);

type TPdfDestinationViewParameters = array [0..3] of Single;

Mode de vue de destination et ses paramètres natifs ordonnés

 

type TLinkAnnotation = record
  Handle: FPDF_LINK;
  Rectangle: TPdfRectangle;
  PageNumber: Integer;
  Action: TPdfAction;
  ActionPageNumber: Integer;
  ActionPath: WString;
  Points: array of TQuadrilateralPoint;
end;

type TLinkAnnotations = array of TLinkAnnotation;

type TQuadrilateralPoint = array [1..4] of TPdfPoint;

Données d'annotation de lien

 

type TPdfPermission = (permPrint, permModify, permCopy, permAnnotate, permFillForms, permAccessibility, permAssemble, permPrintHighQuality);

type TPdfPermissions = set of TPdfPermission;

Indicateurs de permission de document typés, décodés depuis le masque de permissions natif

 

type TPdfDocumentMetadata = record
  Title: WString;
  Author: WString;
  Subject: WString;
  Keywords: WString;
  Creator: WString;
  Producer: WString;
  CreationDate: WString;
  ModifiedDate: WString;
end;

Un instantané des champs du dictionnaire Info standard du document

 

type TObjectType = (otUnknown, otText, otPath, otImage, otShading, otForm);

Détermine le type de l'objet PDF

 

type TPageMode = (pmNone, pmOutline, pmThumbs, pmFullScreen, pmOptionalContentGroup, pmAttachments, pmUnknown);

Détermine comment le document PDF doit être affiché à l'ouverture

 

type TPdfAction = (acUnsupported, acGoto, acGotoRemote, acUri, acLaunch);

Détermine le type d'une action associée à un élément de signet

 

type TPdfAnnotation = record
  Subtype: TPdfAnnotationSubtype;
  Flags: TPdfAnnotationFlags;
  HasColor: Boolean;
  Color: TColor;
  ColorAlpha: Byte;
  HasInteriorColor: Boolean;
  InteriorColor: TColor;
  InteriorColorAlpha: Byte;
  HasAttachmentPoints: Boolean;
  AttachmentPoints: TQuadrilateralPoint;
  AttachmentPointSets: TQuadrilateralPoints;
  Rectangle: TPdfRectangle;
  HasContents: Boolean;
  ContentsText: WString;
  HasAuthor: Boolean;
  AuthorText: WString;
  HasName: Boolean;
  Name: WString;
  HasSubject: Boolean;
  Subject: WString;
  HasModificationDate: Boolean;
  ModificationDate: WString;
  HasCreationDate: Boolean;
  CreationDate: WString;
  HasIcon: Boolean;
  Icon: WString;
  HasOpacity: Boolean;
  Opacity: Double;
  HasLineEndpoints: Boolean;
  LineStart: TPdfPoint;
  LineEnd: TPdfPoint;
  HasVertices: Boolean;
  Vertices: array of TPdfPoint;
  HasInkList: Boolean;
  InkList: array of TPdfInkGesture;
  HasBorder: Boolean;
  BorderHorizontalRadius: Single;
  BorderVerticalRadius: Single;
  BorderWidth: Single;
  HasAppearanceNormal: Boolean;
  AppearanceNormal: WString;
  HasAppearanceRollover: Boolean;
  AppearanceRollover: WString;
  HasAppearanceDown: Boolean;
  AppearanceDown: WString;
  HasLinkUri: Boolean;
  LinkUri: WString;
end;

Données d'annotation

 

type TPdfAnnotationFlag = (afInvisible, afHidden, afPrint, afNoZoom, afNoRotate, afNoView, afReadOnly, afLocked, afToggleNoView);

type TPdfAnnotationFlags = set of TPdfAnnotationFlag;

Indicateurs d'annotation

 

type TPdfAnnotationSubtype = (anUnknown, anText, anLink, anFreeText, anLine, anSquare, anCircle, anPolygon, anPolyLine, anHighlight, anUnderline, anSquiggly, anStrikeout, anStamp, anCaret, anInk, anPopup, anFileAttachment, anSound, anMovie, anWidget, anScreen, anPrinterMark, anTrapNet, anWaterMark, anThreed, anRichMedia, anXfaWidget, anRedact);

Le sous-type d'annotation

 

type TPdfBlendMode = (bmDefault, bmColor, bmColorBurn, bmColorDodge, bmDarken, bmDifference, bmExclusion, bmHardLight, bmHue, bmLighten, bmLuminosity, bmMultiply, bmNormal, bmOverlay, bmSaturation, bmScreen, bmSoftLight);

Détermine la façon dont les couches sont fusionnées entre elles

 

type TPdfDisplayMode = (dmSingleContinuous, dmTwoPageContinuous, dmTwoPageContinuousWithCover);

Détermine comment les pages du document PDF sont affichées

 

type TPdfFeature = (feUnknown, feXfaForm, fePortableCollection, feAttachment, feSecurity, feSharedReview, feSharedFormAcrobat, feSharedFormFilesystem, feSharedFormEmail, fe3dAnnotation, feMovieAnnotation, feSoundAnnotation, feScreenMediaAnnotation, feScreenRichMediaAnnotation, feAttachmentAnnotation, feSignatureAnnotation);

Fonctionnalité du document PDF signalée par l'événement OnUnsupportedFeature

 

type TPdfFillMode = (fmNone, fmAlternate, fmWinding);

Détermine comment les zones de remplissage se forment lorsqu'un tracé se croise lui-même

 

type TPdfFormFieldFlag = (ffReadOnly, ffRequired, ffNoExport, ffMultiline, ffChoiceCombo, ffChoiceEdit, ffPassword, ffChoiceMultiSelect);

type TPdfFormFieldFlags = set of TPdfFormFieldFlag;

Indicateurs de champ de formulaire

 

type TPdfFormFieldInfo = record
  Name: WString;
  AlternateName: WString;
  FieldType: TPdfFormFieldType;
  Flags: TPdfFormFieldFlags;
  OptionLabels: array of WString;
  OptionSelected: array of Boolean;
  FontSize: Single;
  Checked: Boolean;
  ExportValue: WString;
  GroupCount: Integer;
  GroupIndex: Integer;
end;

Informations de champ de formulaire

 

type TPdfFormFieldType = (fiUnknown, fiPushButton, fiCheckBox, fiRadioButton, fiComboBox, fiListBox, fiTextField, fiSignature, fiXfa, fiXfaCheckBox, fiXfaComboBox, fiXfaImageField, fiXfaListBox, fiXfaPushButton, fiXfaSignature, fiXfaTextField);

Détermine le type du champ de formulaire

 

type TPdfFormType = (ftUnknown, ftNone, ftAcroForm, ftXfaFull, ftXfaForeground);

Détermine le type de formulaires dans le document PDF

 

type TPdfImage = record
  Width: Integer;
  Height: Integer;
  Data: TBytes;
  RawData: TBytes;
  Filters: TPdfStringArray;
  HorizontalDpi: Single;
  VerticalDpi: Single;
  BitsPerPixel: LongWord;
  ColorSpace: Integer;
  MarkedContentId: Integer;
  IccProfile: TBytes;
end;

Taille en pixels et données de l'objet image PDF

 

type TPdfLineCap = (lcDefault, lcButt, lcRound, lcProjectingSquare);

Forme à utiliser aux extrémités des sous-tracés ouverts

 

type TPdfLineJoin = (ljDefault, ljMiter, ljRound, ljBevel);

Forme à utiliser aux coins des tracés qui sont contourés

 

type TPdfPoint = record
  X, Y: Double;
end;

Point avec coordonnées X et Y

 

type TPdfRectangle = record
  Left, Top, Right, Bottom: Double;
end;
type TPdfRectangles = array of TPdfRectangle;

Zone rectangulaire avec les coordonnées Left, Top, Right et Bottom

 

type TPdfFileIdentifierType = (fidPermanent, fidChanging);

Sélecteur d'identifiant de fichier du trailer. fidPermanent lit la première entrée /ID et fidChanging lit la seconde entrée /ID

 

type TPdfPageBox = (pbMedia, pbCrop, pbBleed, pbTrim, pbArt);

Sélecteur de boîte du dictionnaire de page utilisé par PageBox, GetPageBox et SetPageBox

 

type TPdfJavaScriptAction = record
  Name: WString;
  Script: WString;
end;
type TPdfJavaScriptActions = array of TPdfJavaScriptAction;

Données d'action de l'arbre de noms JavaScript au niveau du document

 

type TPdfSignature = record
  Content: TBytes;
  ByteRange: TPdfIntegerArray;
  Encoding: WString;
  Reason: WString;
  Time: WString;
  Permission: Integer;
end;

Informations de signature numérique

 

type TPdfIntegerArray = array of Integer;

Tableau d'entiers utilisé par les listes d'ID de contenu marqué de l'arbre de structure

 

type TPdfSingleArray = array of Single;

Tableau de flottants en simple précision utilisé par les définitions de position de caractères des objets texte

 

type TPdfPrintPageRange = record
  StartPage: Integer;
  EndPage: Integer;
end;
type TPdfPrintPageRanges = array of TPdfPrintPageRange;

Plages de pages d'impression à base 1 issues des préférences de la visionneuse du document

 

type TPdfStructureElement = record
  Level: Integer;
  ParentIndex: Integer;
  TypeName: WString;
  RawTypeName: WString;
  ObjectType: WString;
  Title: WString;
  AlternateText: WString;
  ActualText: WString;
  Expansion: WString;
  ID: WString;
  Language: WString;
  MarkedContentID: Integer;
  MarkedContentIDs: TPdfIntegerArray;
  ChildCount: Integer;
  ChildMarkedContentIDs: TPdfIntegerArray;
  AttributeCount: Integer;
  Attributes: TPdfStructureAttributeValues;
  ListNumbering: WString;
  Scope: WString;
  HasHeaders: Boolean;
  HeadersIds: array of WString;
  ColSpan: Integer;
  RowSpan: Integer;
  HasPrintField: Boolean;
  NamespaceUri: WString;
  RoleMappedNamespaceUri: WString;
  RoleMappedTypeName: WString;
  HasReference: Boolean;
  HasAssociatedFile: Boolean;
  AssociatedFileRelationship: WString;
  AssociatedFileDescription: WString;
  AssociatedFileDeclaredInCatalog: Boolean;
  AssociatedFileDeclaredInStructure: Boolean;
  AssociatedFileInEmbeddedFilesNameTree: Boolean;
  AssociatedFileHasReadingOrder: Boolean;
  AssociatedFileReadingOrderIndex: Integer;
  AnnotationSubtype: WString;
  AnnotationContents: WString;
  AnnotationAlternateText: WString;
  IsArtifact: Boolean;
  WidgetCount: Integer;
  HasAppearance: Boolean;
  LabelText: WString;
  FieldAlternateName: WString;
end;

type TPdfStructureElements = array of TPdfStructureElement;

Données aplaties des éléments de structure logique pour les pages PDF balisées

 

type TPdfFormSelectionRect = record
  PageNumber: Integer;
  Bounds: TPdfRectangle;
end;

Rectangle dans l'espace de page fourni par l'appelant, signalé par la sélection de texte de formulaire native

 

type TPdfStructureReadOptions = record
  MaxDepth: Integer;
  MaxElements: Integer;
  MaxAttributeValues: Integer;
  DeadlineMilliseconds: Cardinal;
  IncludeAttributes: Boolean;
  class function Default: TPdfStructureReadOptions; static;
end;

Budgets de ressources pour la traversée itérative native de l'arbre de structure

type TPdfStructureReadStatus = record
  Completed: Boolean;
  ElementsVisited: Integer;
  AttributeValuesVisited: Integer;
  DepthLimitReached: Boolean;
  ElementLimitReached: Boolean;
  AttributeLimitReached: Boolean;
  DeadlineReached: Boolean;
  VisitorStopped: Boolean;
end;

Détails d'achèvement et de troncature renvoyés par les méthodes de traversée de structure

 

type TPdfVersion = (pvUnknown, pv10, pv11, pv12, pv13, pv14, pv15, pv16, pv17, pv20);

La version d'un fichier PDF ou d'une cible SaveAs explicite. Valeurs possibles : version inconnue, versions PDF 1.0 à 1.7 et 2.0. Les cibles SaveAs explicites de PDF 1.3 à PDF 2.0 sont normalisées et validées par rapport à la version PDF choisie

 

type TPrintPaperHandling = (phUndefined, phSimplex, phDuplexFlipShortEdge, phDuplexFlipLongEdge);

Options de manipulation du papier à l'impression

 

type TPdfPrintMode = (prEmf, prTextOnly, prPostScript2, prPostScript3, prPostScript2PassThrough, prPostScript3PassThrough, prEmfImageMasks, prPostScript3Type42, prPostScript3Type42PassThrough);

Mode de sortie d'impression PDFium Windows sélectionné par SetPdfPrintMode

 

type TRenderOption = (reAnnotations, reLcd, reNoNativeText, reGrayscale, reDebugInfo, reNoCatchException, reLimitCache, reHalftone, rePrinting, reReverseByteOrder, reNoSmoothText, reNoSmoothImage, reNoSmoothPath, reInvert, reNightDuotone);

type TRenderOptions = set of TRenderOption;

Indicateurs de rendu de page

 

type TRotation = (ro0, ro90, ro180, ro270);

La rotation de la page PDF. La rotation de page s'effectue dans le sens horaire

 

type TSaveOption = (saNone, saIncremental, saNoIncremental, saRemoveSecurity, saSubsetNewFonts);

Détermine comment le document PDF sera enregistré

 

type TSearchOption = (seCaseSensitive, seWholeWord, seConsecutive);

type TSearchOptions = set of TSearchOption;

Indicateurs de recherche

 

type TWebLink = record
  Url: WString;
  Rectangles: TPdfRectangles;
  StartCharIndex: Integer;
  CharCount: Integer;
end;

type TWebLinks = array of TWebLink;

Informations URL et limites du lien Web

 

type WString = {$IFDEF FPC} WideString {$ELSE} string {$ENDIF};

Chaîne large

 

Constantes

const PointsPerInch: Integer = 72;

PDF utilise des points avec une densité de 72 points par pouce

 

const FLAT_NORMALDISPLAY = 0;
const FLAT_PRINT = 1;

Profils d'aplatissement passés à FlattenPage / FlattenAllPages. FLAT_NORMALDISPLAY cible l'affichage écran ; FLAT_PRINT cible la sortie imprimée

 

const FLATTEN_FAIL = 0;
const FLATTEN_SUCCESS = 1;
const FLATTEN_NOTHINGTODO = 2;

Codes de résultat renvoyés par FlattenPage

 

type TPdfReadingUnit = record
  Text: WString;
  Kind: TPdfContentFragmentKind;
  HeadingLevel: Integer;
  Page: Integer;
  Rects: TPdfRectangles;
  FragmentIndex: Integer;
  SentenceIndex: Integer;
  IsAlternateText: Boolean;
  Language: WString;
  SourceFragment: TPdfContentFragment;
  TableContext: TPdfReaderTableContext;
  ListContext: TPdfReaderListContext;
  TextStartIndex: Integer;
end;

type TPdfReadingUnits = array of TPdfReadingUnit;

Unités de lecture au niveau de la phrase utilisées par la synthèse vocale et les flux de lecture assistée

 

type TPdfWordBox = record
  Text: WString;
  StartIndex: Integer;
  Count: Integer;
  Rect: TPdfRectangle;
  Page: Integer;
  CharacterIndices: TPdfIntegerArray;
end;

type TPdfWordBoxes = array of TPdfWordBox;

Plages de texte au niveau du mot et rectangles de page utilisés par les surlignages de lecture synchronisée

 

type TPdfSpokenSpan = record
  SpokenStart: Integer;
  SpokenCount: Integer;
  Page: Integer;
  StartIndex: Integer;
  Count: Integer;
  ContextOnly: Boolean;
end;

type TPdfSpokenSpans = array of TPdfSpokenSpan;

Segments appariés qui renvoient les offsets du moteur vocal au texte de page PDF

 

type TPdfSpokenText = record
  Text: WString;
  Spans: TPdfSpokenSpans;
end;

type TPdfSpokenTexts = array of TPdfSpokenText;

Fragments parlés et mappages source utilisés par les flux de lecture à voix haute et TPdfReadingSession

 

type TPdfReadingSessionState = (pssIdle, pssSpeaking, pssPaused);

État de lecture signalé par TPdfReadingSession

 

Variables globales

var LibraryName: string = 'pdfium.dll';

Nom de la bibliothèque PDFium standard utilisée lorsque EnableV8Engine est False. Peut être modifié avant l'appel de LoadLibrary

 

var EnableV8Engine: Boolean = False;

Définir sur True avant le chargement pour sélectionner pdfium.v8.dll dans le dossier DLLs Win32 ou Win64 correspondant

 

Fonctions globales

Propriétés

Méthodes

Événements

La destruction d'un TPdf lié désactive ses vues survivantes et efface leurs références Pdf ; les handles natifs de document et de page précédemment obtenus ne doivent plus être utilisés