Een HotPDF-voorbeeld voor verticale tekstlay-out in PDF-documenten, inclusief positionering, rotatie en leesbaarheid.
Dit artikel is bedoeld voor ontwikkelaars die met pdf-programmeren werken. Productnamen, API-namen, bestandsnamen en codefragmenten zijn bewust ongewijzigd gehouden, zodat de voorbeelden direct met de oorspronkelijke documentatie en broncode te vergelijken zijn.
Overzicht
De pagina beschrijft het probleemgebied, de relevante implementatiekeuzes en de controles die belangrijk zijn voordat de oplossing in een echte toepassing wordt gebruikt.
Codevoorbeeld
Het onderstaande codefragment is ongewijzigd uit de Engelse bron overgenomen om identifiers, API-aanroepen en syntaxis exact te behouden.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
{***********************************************************} // HotPDF PDF Component // Copyright(c)2007-2025, https://www.loslab.com {***********************************************************} { Unit: uVerticalText Purpose: Demonstrates vertical text output capabilities in HotPDF Features: - Horizontal and vertical text rendering - Multi-language support (English, Korean, Japanese, Chinese) - Unicode character handling - Font embedding for proper display } unit uVerticalText; interface {$I ..\..\..\Lib\HotPDF.inc} uses {$IFDEF XE2+} WinApi.Windows, WinApi.Messages, System.SysUtils, System.Classes, Vcl.Graphics, Vcl.StdCtrls, Vcl.Controls, Vcl.Dialogs, Vcl.Forms, {$ELSE} Windows, Messages, SysUtils, Graphics, Controls, StdCtrls, Classes, Dialogs, Forms, {$ENDIF} HPDFDoc; // HotPDF component for PDF generation type // Main form class for the vertical text demonstration TForm1 = class(TForm) Button1: TButton; // Button to trigger PDF generation procedure Button1Click(Sender: TObject); private {Private declarations} public {Public declarations} end; var Form1: TForm1; // Main form instance HotPDF: THotPDF; // HotPDF component instance implementation {$R *.DFM} // Important Note: Old version of Delphi cannot handle Unicode characters correctly. // You need Delphi 2009 or above to open this file. { Method: Button1Click Purpose: Demonstrates vertical and horizontal text output with multiple languages Parameters: Sender - The object that triggered the event Features: - Creates a PDF with both horizontal and vertical text - Shows text in multiple languages (English, Korean, Japanese, Chinese) - Uses Unicode font for proper character display - Demonstrates different text positioning techniques } procedure TForm1.Button1Click(Sender: TObject); begin // Create HotPDF instance HotPDF := THotPDF.Create(nil); try // Configure PDF generation settings HotPDF.AutoLaunch := true; // Automatically open PDF after creation HotPDF.FontEmbedding := true; // Embed fonts for proper display HotPDF.FileName := 'VerticalText.pdf'; // Set output filename // Begin PDF document creation HotPDF.BeginDoc; HotPDF.CurrentPage.Size := psA4; // Set page size to A4 // === HORIZONTAL TEXT DEMONSTRATION === HotPDF.CurrentPage.SetFont('Arial Unicode MS', [], 12, 0, False); // Set horizontal text mode // Output horizontal text in multiple languages HotPDF.CurrentPage.TextOut(80, 70, 0, 'Horizontal Text 가로텍스트 가로쓰기 横向きのテキスト 横書き 横向文本 横書'); // Add decorative separator line HotPDF.CurrentPage.TextOut(40, 110, 0, '※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※'); // === VERTICAL TEXT DEMONSTRATION === HotPDF.CurrentPage.SetFont('Arial Unicode MS', [], 12, 0, true); // Set vertical text mode // Mixed language vertical text (Korean, Japanese) HotPDF.CurrentPage.TextOut(530, 180, 0, '縦書 縦書き 세로쓰기 垂直テキスト 수직 텍스트'); // Chinese text - Declaration of Independence excerpt HotPDF.CurrentPage.SetFont('Arial Unicode MS', [], 12, 0, true); HotPDF.CurrentPage.TextOut(500, 180, 0, '『我等之见解为,下述真理不证自明:凡人生而平等,秉造物者之赐,'); HotPDF.CurrentPage.TextOut(470, 180, 0, '拥诸无可转让之权利,包含生命权、自由权、与追寻幸福之权。』'); // Japanese text - Traditional poetry HotPDF.CurrentPage.TextOut(430, 180, 0, '昨日またかくてありけり、今日もまたかくてありなむ'); HotPDF.CurrentPage.TextOut(400, 180, 0, 'この命にを齷齪、明日をのみ思ひわづらふ'); HotPDF.CurrentPage.TextOut(370, 180, 0, 'いくたびか栄枯の夢の、消え残る谷に下りて'); HotPDF.CurrentPage.TextOut(340, 180, 0, '河波のいざよふ見れば、砂まじり水巻き帰る'); HotPDF.CurrentPage.TextOut(310, 180, 0, '嗚呼古城なにをか語り、岸の波なにをか答ふ、過し世を静かに思へ'); // Chinese classical poetry - Li Bai's poem HotPDF.CurrentPage.TextOut(270, 180, 0, '棄我去者昨日之日不可留,亂我心者今日之日多煩憂。'); HotPDF.CurrentPage.TextOut(240, 180, 0, '長風萬里送秋鴈,對此可以酣高樓。蓬萊文章建安骨,中間小謝又清發'); HotPDF.CurrentPage.TextOut(210, 180, 0, '俱懷逸興壯思飛,欲上青天攬明月。抽刀斷水水更流,舉杯消愁愁更愁'); HotPDF.CurrentPage.TextOut(180, 180, 0, '人生在世不稱意。明朝散髮弄扁舟。'); // Korean text - Contemporary poetry // Note: Using Arial Unicode MS instead of Malgun Gothic for compatibility //HotPDF.CurrentPage.SetFont('Malgun Gothic', [], 12, 0, true); // Alternative Korean font HotPDF.CurrentPage.TextOut(140, 180, 0, '눈 맞으며 어둠 속을 떨며 가는 사람들을트、노래가 길이 되어 앞질러 가고'); HotPDF.CurrentPage.TextOut(110, 180, 0, '돌아올 길 없는 눈길 앞질러 가고'); HotPDF.CurrentPage.TextOut(80, 180, 0, '아름다움이 이 세상을 건질 때까지'); HotPDF.CurrentPage.TextOut(50, 180, 0, '절망에서 즐거움이 찾아올 때까지'); // === FOOTER DECORATION === HotPDF.CurrentPage.SetFont('Arial Unicode MS', [], 12, 0, False); // Switch back to horizontal text // Add decorative footer line HotPDF.CurrentPage.TextOut(40, 720, 0, '■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■'); // Finalize PDF document HotPDF.EndDoc; finally // Clean up resources HotPDF.Free; end; end; end. |
Praktische aandachtspunten
- Controleer invoerbestanden en foutpaden expliciet voordat u de routine in productie gebruikt.
- Houd paginalay-out, lettertypen en coördinaten reproduceerbaar, vooral bij server-side verwerking.
- Test het resultaat in meer dan één PDF-viewer wanneer rendering, annotaties of interactieve elementen belangrijk zijn.
- Laat componentlevensduur en bestandshandles altijd via try/finally-achtige patronen opruimen.