Code Samples & Examples
Real-world examples showing how to build PDFs with TerraPDF. From simple reports to complex documents with tables, encryption, and advanced layouts.
01. Simple Report
BeginnerText formatting, bold/italic/strikethrough, justified paragraphs, horizontal rules, tables with alternating rows, and page numbers.
02. Styled Newsletter
IntermediateTwo-column layouts, colored banners, pull-quote blocks, statistics boxes with borders, and multi-page repeating footers.
03. Invoice
IntermediateMulti-page document with 30-row line-items table, repeating header on every page, bill-from/to sections, totals block, and payment terms.
04. Company Profile
IntermediateFull-width header banner images, team tables, key metrics, service cards, and multi-page layouts with footer logos.
05. Event Brochure
IntermediateConference agenda tables, speaker cards in two-column layout, sponsor logos grid, and call-to-action banners.
06. Product Catalogue
AdvancedComplex multi-page product grid with images, descriptions, pricing, availability status, and category filtering.
07. Product Catalog Cover
AdvancedProfessional cover page design with featured products, testimonials, and promotional content layout techniques.
08. Report with Bookmarks
AdvancedHierarchical bookmark structure with top-level sections, sub-sections, and page-positioned entries for easy PDF navigation.
09. Report with Table of Contents
AdvancedAutomatic table of contents generation with heading levels (H1-H6), clickable page numbers, and internal links between sections.
10. Vector Graphics Showcase
AdvancedDemonstrates drawing capabilities including shapes, lines, opacity, baseline-anchored text, and custom vector graphics for data visualization. For canvas images, dashes, arcs, and rotated text, see sample 18.
11. Unicode Showcase
AdvancedComprehensive Unicode and multi-language support, including RTL text, special characters, and various scripts and encodings.
12. Encryption & Security
AdvancedAES-256 password protection by default (with a legacy AES-128 mode) across five scenarios: open password, owner-only, print-only, fully restricted, and legacy compatibility.
13. Barcodes & QR Codes
AdvancedVector-rendered Code128 barcodes and ISO/IEC 18004 QR codes — captions, custom colours, error correction levels, and placement inside a table cell.
14. Custom Font Embedding
Advanced
Register a TrueType font with FontFamily.Register and render Cyrillic and Greek text side by side with standard Helvetica, which falls back to "?".
15. Child Nutrition India Report
AdvancedA full three-page Hindi-language report in Devanagari script — matra reordering, conjunct ligatures, reph, and post-base 'ra' forms, all in pure C#.
16. Table Spans & Pagination
AdvancedColumn and row spans, spanned cells growing the rows they cover, and tables splitting across pages without ever cutting a row span in half.
17. Font Subsetting Showcase
AdvancedCustom fonts now embed only the glyphs a document actually shows, with a composite-glyph closure pass so accented Latin letters and Devanagari conjuncts keep every component they depend on.
18. Canvas Media Showcase
AdvancedFour pages of canvas media: all five image fit modes from one wide banner, PNG soft-mask transparency, constant-alpha layering, dash patterns and phases, elliptical arcs, pie sectors, and text rotated around its baseline.
19. Canvas Extras Showcase
AdvancedTwo pages of canvas extras: dashed ellipses, rounded rectangles, pies, and paths, linear and radial gradient fills, clickable links and bookmarks placed from a canvas, and vector QR codes.
Getting the Sample Source Code
All samples are part of the TerraPDF repository and can be run locally.
git clone https://github.com/sahebansari/TerraPDF.git
cd TerraPDF/samples/TerraPDF.Sample
dotnet runThe samples will generate PDF files to your Desktop in a SamplePDF folder. Each sample demonstrates different TerraPDF features and can be modified to suit your needs.