Technical Article

HotPDF Component Vertical Text Sample Project

· PDF Programming

HotPDF Delphi Component: Creating Vertical Text Layouts in PDF Documents

This comprehensive guide demonstrates how the HotPDF component enables developers to generate Unicode vertical text in PDF documents with ease.

Understanding Vertical Typesetting (縦書き/세로쓰기/竖排)

Vertical typesetting, also known as vertical writing, 縱書 in Chinese or tategaki (縦書き) in Japanese, is a traditional text layout method that originated in ancient China over 2,000 years ago. This writing system flows from top to bottom and right to left, creating a distinctive visual appearance that carries deep cultural significance.

Historical and Cultural Context

Vertical writing systems have played a crucial role in East Asian literature and documentation:

  • China: Traditional Chinese texts, classical poetry, and calligraphy predominantly used vertical layouts. Modern simplified Chinese primarily uses horizontal writing, though vertical text remains common in artistic and ceremonial contexts.
  • Japan: Japanese maintains both vertical (縦書き/tategaki) and horizontal (横書き/yokogaki) writing systems. Vertical text is still widely used in novels, manga, newspapers, and traditional documents.
  • Korea: Historically used vertical writing (세로쓰기), but modern Korean (한글) predominantly uses horizontal layouts. Vertical text appears in traditional contexts and artistic applications.
  • Vietnam: Traditional Vietnamese texts used vertical layouts when written in Chinese characters (Chữ Hán), though this practice has largely disappeared with the adoption of the Latin alphabet.

Modern Applications of Vertical Text

Despite the global trend toward horizontal writing, vertical text layouts remain relevant in several contexts:

  • Publishing: Traditional novels, poetry collections, and literary works in Taiwan, Japan, and Hong Kong
  • Design: Logos, signage, and artistic layouts that require visual impact
  • Digital Media: E-books, mobile applications, and web content targeting traditional reading preferences
  • Documentation: Legal documents, certificates, and formal communications in traditional formats

HotPDF Component: Professional Vertical Text Support

The HotPDF Delphi component provides comprehensive support for vertical text layout in PDF documents, making it an ideal solution for developers working with multilingual applications or traditional document formats.

Key Features for Vertical Typography

  • Unicode Support: Full compatibility with CJK (Chinese, Japanese, Korean) character sets
  • Font Embedding: Ensures consistent display across different systems
  • Mixed Layouts: Combine horizontal and vertical text in the same document
  • Precise Positioning: Pixel-perfect control over text placement
  • Multi-language Support: Handle complex scripts and character combinations
HotPDF Component generating vertical text in PDF - showing Chinese, Japanese, and Korean characters in traditional vertical layout
Figure 1: PDF document with vertical text layout generated by HotPDF Component, demonstrating multi-language support for Chinese (中文), Japanese (日本語), and Korean (한국어) vertical typography.

Implementation Guide: Delphi Code Example

The following comprehensive Delphi code example demonstrates how to implement vertical text rendering using the HotPDF component. This example showcases both horizontal and vertical text layouts with multiple languages.

Code Features Highlighted

  • Font Configuration: Proper setup of Unicode fonts for multi-language support
  • Text Positioning: Precise control over text placement in vertical layouts
  • Language Mixing: Combining different scripts (Latin, CJK) in the same document
  • Resource Management: Proper initialization and cleanup of PDF resources

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.

Technical Implementation Details

Font Selection and Unicode Support

When working with vertical text in PDFs, proper font selection is crucial for ensuring correct character display across different languages:

  • Arial Unicode MS: Comprehensive Unicode font supporting most CJK characters
  • Font Embedding: Always enable FontEmbedding := true to ensure consistent display
  • Character Encoding: Use UTF-8 encoding for proper Unicode character handling

Text Positioning Best Practices

Vertical text positioning requires careful consideration of reading flow and character spacing:

  1. Right-to-Left Column Flow: Start from the rightmost position and move left for subsequent columns
  2. Top-to-Bottom Character Flow: Characters within each column flow from top to bottom
  3. Consistent Spacing: Maintain uniform column spacing for professional appearance
  4. Mixed Script Handling: Consider different character widths when mixing Latin and CJK scripts

Advanced Features and Customization

Performance Optimization Tips

  • 🚀 Batch Text Operations: Group multiple text outputs to minimize PDF operations
  • 🚀 Font Caching: Reuse font objects when possible to improve performance
  • 🚀 Memory Management: Properly dispose of HotPDF instances to prevent memory leaks
  • 🚀 Stream Processing: Use memory streams for large documents to improve processing speed

Troubleshooting Common Issues

⚠️ Common Problems and Solutions

  • Missing Characters: Ensure the selected font supports all required Unicode ranges
  • Incorrect Positioning: Verify coordinate system understanding (HotPDF uses top-left origin)
  • Font Rendering Issues: Enable font embedding and use Suitable Unicode fonts
  • Performance Problems: Optimize text output calls and consider document structure

Related Resources and Further Reading

Documentation and Support

Related Topics

  • 🔗 PDF Text Rendering: Advanced typography techniques in PDF documents
  • 🔗 Multilingual PDF Generation: Handling complex scripts and right-to-left languages
  • 🔗 Delphi Unicode Programming: Best practices for Unicode handling in Delphi applications
  • 🔗 Asian Typography: Traditional and modern approaches to CJK text layout

Conclusion

The HotPDF Delphi component provides robust support for vertical text layouts, making it an excellent choice for developers working with traditional Asian typography or modern design applications requiring vertical text orientation. With proper implementation of Unicode fonts, careful positioning, and attention to cultural typography conventions, you can create professional PDF documents that respect traditional reading patterns while maintaining modern technical standards.

Whether you’re developing applications for publishing, document management, or creative design, the vertical text capabilities of HotPDF enable you to create culturally appropriate and visually appealing PDF documents that serve diverse global audiences.