PDFium Delphi Component Docs

หน่วย FPdfLayout

สร้างแผนการจัดวางแบบ flow ที่วัดขนาดได้ พร้อมองค์ประกอบประจำหน้า คอลัมน์ ตารางข้ามหน้า ลิงก์ โหนดที่ใช้ซ้ำได้ อินพุต markup และความหมายแบบ tagged-PDF

Exceptions and enumerations

TypeValues or purpose
EPdfLayoutErrorexception ที่เกิดจากอินพุตการจัดวางไม่ถูกต้อง เกินขีดจำกัด และโครงสร้างเชิงความหมายไม่สอดคล้องกัน
TPdfLayoutAlignmentplaLeft, plaCenter, plaRight
TPdfLayoutCommandKindplcText, plcRule, plcImage, plcPageXObject, plcCachedNode, plcLink, plcRectangle
TPdfLayoutItemKindpliText, pliSpacer, pliRule, pliImage, pliPageXObject, pliPageBreak, pliCachedNode, pliLink, pliSemanticNode, pliTable
TPdfLayoutSemanticRoleplsrArtifact, plsrParagraph, plsrHeading1, plsrHeading2, plsrHeading3, plsrHeading4, plsrHeading5, plsrHeading6, plsrList, plsrListItem, plsrListLabel, plsrListBody, plsrTable, plsrTableRow, plsrTableHeader, plsrTableData, plsrFigure, plsrCaption, plsrLink, plsrSection, plsrDivision
TPdfLayoutTableScopepltsNone, pltsRow, pltsColumn, pltsBoth
TPdfLayoutListNumberingplnNone, plnDisc, plnCircle, plnSquare, plnDecimal, plnUpperRoman, plnLowerRoman, plnUpperAlpha, plnLowerAlpha
TPdfLayoutGridTrackKindplgtkFixed, plgtkFraction, plgtkAuto
TPdfMarkupFormatpmfMarkdown, pmfHtml

Layout records

TypePublic members
TPdfLayoutSemanticsRole, ParentID, ElementID, AlternateText, ActualText, Language, HeaderIDs, TableScope, ColumnSpan, RowSpan, ListNumbering, Artifact, Paragraph, Figure
TPdfLayoutTextStyleFontName, FontSize, Color, Alpha, LineHeight, Alignment, KeepTogether, BreakLongWords, SpaceBefore, SpaceAfter, Default
TPdfLayoutConstraintsKeepTogether, KeepWithNext, PageBreakBefore, PageBreakAfter, OrphanLines, WidowLines, Default
TPdfLayoutPageSettingsWidth, Height, MarginLeft, MarginTop, MarginRight, MarginBottom, HeaderHeight, FooterHeight, A4, Letter
TPdfLayoutRectLeft, Top, Width, Height
TPdfLayoutGridTrackKind, Value, Minimum, Maximum, MeasuredContent
TPdfLayoutGridTracksอาร์เรย์แบบ dynamic ของ TPdfLayoutGridTrack
TPdfLayoutGridSizesอาร์เรย์แบบ dynamic ของขนาด track ที่ resolve แล้ว
TPdfLayoutTableOptionsCellPadding, BorderWidth, BorderColor, BorderAlpha, RepeatHeaderRows, Default
TPdfMarkupOptionsBaseStyle, HeadingScale, MaxInputCharacters, MaxNodes, Default
TPdfLayoutSemanticElementSemantics, ParentElementIndex
TPdfLayoutSemanticElementsอาร์เรย์แบบ dynamic ของ TPdfLayoutSemanticElement
TPdfLayoutCommandKind, PageNumber, Bounds, Text, FontName, FontSize, Color, Alpha, Alignment, Thickness, FileName, Uri, Source, SourcePageIndex, SemanticElementIndex, MarkedContentID, AnnotationIndex
TPdfLayoutCommandsอาร์เรย์แบบ dynamic ของ TPdfLayoutCommand
TPdfLayoutPlanPageSettings, PageCount, Commands, SemanticElements, TextLineCount, RuleCount, RectangleCount, ImageCount, PageXObjectCount, CachedNodeCount, LinkCount, TaggedContentCount, ArtifactCount, MeasuredTextCount, TotalPageReferenceCount, ReservedPageDigits, CacheHitCount, CacheMissCount, ReusedXObjectCount, ColumnCount, ColumnGap

Layout classes

TypePublic members
TPdfLayoutMeasurerMeasureTextWidth, CacheIdentity
TPdfLayoutItemKind
TPdfLayoutTableCellText, Uri, Style, ColumnSpan, RowSpan, Header, ElementID, HeaderIDs, Scope
TPdfLayoutTableRowAddCell, Cells, Header, AllowSplit, MinimumHeight
TPdfLayoutTableCreate, Destroy, AddRow, SetCaption, Columns, Rows, Options, Caption, CaptionStyle, ElementID, ParentID
TPdfLayoutPagedPlanCreate, Destroy, ClearPageCache, MaterializePage, Reset, Summary, CommandCount, StorageByteCount, SourceCount, Completed, งบประมาณ MaxCommandCount, MaxStorageBytes, MaxPageCommands, MaxSourceCount และ MaxCachedPages และสถิติ cache CachedPageCount, CacheHitCount, CacheMissCount และ PeakCachedPageCount
TPdfLayoutDocumentCreate, Destroy, Clear, AddText, AddSpacer, AddRule, AddImage, AddPageXObject, AddCachedNode, AddLink, AddSemanticNode, SetLastItemSemantics, SetLastItemConstraints, AddTable, AddPageBreak, LoadMarkup, InvalidateCache, BuildPlan, BuildPagedPlan, PageSettings, HeaderText, FooterText, HeaderStyle, FooterStyle, ReservedPageDigits, ColumnCount, ColumnGap, Items
TPdfLayoutCachedNodeCreate, Destroy, Invalidate, BeginEmission, EndEmission, Content, Width, Height, Built

Pagination constraints

เรียก SetLastItemConstraints หลังเพิ่ม flow item ที่มองเห็นได้ทุกชิ้น เพื่อให้ item อยู่รวมกันเป็นก้อน ต่อยึดกับต้นของ item ถัดไป หรือบังคับขึ้นหน้าใหม่จริงก่อนหรือหลัง item นั้น

OrphanLines คือจำนวนบรรทัดย่อหน้าขั้นต่ำที่คงไว้ท้ายพื้นที่หนึ่ง ส่วน WidowLines คือจำนวนขั้นต่ำที่ยกไปวางต้นพื้นที่ถัดไป; ทั้งสองค่า default เป็นหนึ่ง เพื่อคงพฤติกรรมการแบ่งหน้าเดิม

เงื่อนไขเหล่านี้ใช้กับ item ที่เป็นย่อหน้า ลิงก์ รายการ รูปภาพ และตารางอย่างเท่าเทียม ส่วน container ที่มีเฉพาะความหมายไม่มีมิติทางเรขาคณิต จึงปฏิเสธ pagination constraints

item แบบ pliTable ยอมรับเฉพาะ PageBreakBefore กับ PageBreakAfter; การแบ่งแถวและการยึดจุดเริ่มตารางถูกควบคุมโดยโมเดลตาราง

ตัววางแผน cache บรรทัดที่ตัดคำไว้ระหว่างการ build ดังนั้นการทำนาย keep-with-next กับการปล่อย command สุดท้ายจึงไม่ต้องวัดข้อความเดียวกันสองครั้ง

Paged command plans

สร้าง TPdfLayoutPagedPlan เหนือ TStream เฉพาะที่ seekable และปรับขนาดได้ แล้วเรียก BuildPagedPlan หรือส่งมันต่อให้ TPdf.GeneratePagedLayout

ตัววางแผน serialize command ทันที คืนพื้นที่ของผลลัพธ์ wrapped-text ที่เสร็จแล้วแต่ละชิ้น และปล่อยให้ Plan.Commands ว่างเปล่า โดยยังเก็บการตั้งค่าหน้า semantic elements ตัวนับ และผลรวมหน้าที่เสถียรไว้ใน summary

command ของเนื้อหาและ command header หรือ footer ที่เกิดทีหลังจะถูกจัดดัชนีเป็น page segment แบบโยงกัน ทำให้ MaterializePage คืนหน้าฉบับสมบูรณ์ได้โดยไม่ต้องสแกน command ของหน้าอื่น

MaxCachedPages จำกัดเฉพาะอาร์เรย์หน้าที่แผนถือครอง; ผู้เรียกที่เก็บอาร์เรย์ที่คืนไว้จะยืดอายุของมันเอง และ PDFium จะยังถือหน้า native ที่สร้างไว้จนกว่าเอกสารปลายทางจะถูกบันทึกหรือปิด

รูปแบบการเก็บข้อมูลเป็นสถานะเซสชันส่วนตัว ไม่ใช่รูปแบบไฟล์พกพา ห้ามแชร์หรือแก้ไข stream นี้จากภายนอก และอ็อบเจกต์ต้นทางที่ page XObject หรือ cached node อ้างถึงต้องมีอายุยาวกว่า paged plan

ใช้ TPdfRandomAccessStore เมื่อต้องการให้ command อยู่ในหน่วยความจำถึงเกณฑ์ที่เลือกหนึ่งค่า แล้วค่อยไหลไปเก็บเป็นไฟล์ชั่วคราวแบบลบเมื่อปิด

Cross-page tables

สร้าง TPdfLayoutTable ด้วย grid track แบบค่าคงที่ สัดส่วน หรือตามขนาดเนื้อหา เพิ่มแถวและเซลล์ แล้วเรียก AddTable; เอกสารจะเก็บ snapshot ที่เป็นเจ้าของไว้ ทำให้การแก้ไขภายหลังของผู้เรียกไม่ทำให้ page cache ที่มีอยู่ใช้ไม่ได้

แถว header ต้องติดกันตั้งแต่ต้นตาราง และจะถูกทำซ้ำหลังเปลี่ยนหน้าหรือคอลัมน์เมื่อ RepeatHeaderRows เป็น true; span ของแถว header ห้ามยืดเข้าไปในแถวเนื้อหา

แถวเนื้อหาแบ่งได้เมื่อ AllowSplit เป็น true เท่านั้น และต้องไม่อยู่ในกลุ่ม row-spanning; เซลล์ทุกเซลล์ใน chunk ที่ถูกแบ่งจะใช้แนวบรรทัด padding และเรขาคณิตของเส้นขอบเดียวกัน

caption จะยึดกับบล็อก header ที่ถูกทำซ้ำและจุดเริ่มต้นขั้นต่ำของกลุ่มเนื้อหาแรก ส่วนกลุ่ม row-spanning แบบส่งผลต่อกันจะเคลื่อนเป็นหน่วยเดียวแบบ atomic

ตัววางแผนปล่อย Table element หนึ่งอัน, Caption เมื่อมี, TR ลูก และเซลล์ TH หรือ TD ไม่ว่าจะแบ่งกี่หน้า; command ของ header ที่ถูกทำซ้ำใช้ semantic index เดิม และเซลล์ TD จะได้รับ header ID ที่ทับซ้อนกันโดยอัตโนมัติ เว้นแต่ผู้เรียกให้ ID ที่ถูกต้องมาเอง

เส้นขอบตารางเป็น command plcRectangle แบบ artifact ที่เรนเดอร์ผ่าน path object แบบ native ของ PDFium ส่วนข้อความ caption และเซลล์ยังเป็นเนื้อหาแบบ tagged

Top-level routines

RoutineDescription
ResolveLayoutTextขยาย placeholder เลขหน้าโดยใช้ความกว้างหลักที่สงวนไว้
PdfLayoutSemanticRoleNameคืนชื่อโครงสร้าง tagged-PDF ของบทบาทเชิงความหมายหนึ่งค่า
BuildTaggedLayoutPdfนำแผนจัดวางและโครงสร้าง tagged ที่เสร็จแล้วไปใช้กับไบต์ PDF ต้นทาง
ResolvePdfLayoutGridTracksresolve grid track แบบค่าคงที่ สัดส่วน และตามขนาดเนื้อหา ภายในความกว้างที่มีอยู่

See Also