Welcome
Guest
•
Login
PDFsharp and MigraDoc Wiki
Navigation
¶
Main Page
Random Page
Create a new Page
All Pages
Categories
Navigation Paths
File Management
Create Account
Quick Search
»
Visit the new
Website for PDFsharp & MigraDoc Foundation 6.0 for .NET 6
and find information about the new version for Windows, Linux, and other platforms.
Back
PDFsharp Sample: Text Layout
Modified on 2015/09/14 10:20
by
Thomas Hövel
Categorized as
PDFsharp Samples
,
Samples
{s:navigationPrevUpNext|SplitDocument-sample|PDFsharpSamples|TwoPagesOnOne-sample} This sample shows how to layout text with the TextFormatter class. TextFormatter is new since PDFsharp 0.9 and was provided because it was one of the "most wanted" features. But it is better and easier to use MigraDoc to format paragraphs... ==PDF Output File== See the PDF file created by this sample: {s:PdfLink|TextLayout-sample%2fTextLayout_output.pdf|output.pdf} (5 kB) ==Screen Shots== Here is a sample screen shot showing left, right, and center aligned and justified text: {s:ImageThumbLink|Text Layout: left, right, or center aligned and justified|TextLayout-sample%2fTextLayoutth.png|TextLayout-sample%2fTextLayout.png} ==Source Code== This is the whole source code needed to create the PDF file: {s:beginCsharp} const string text = "Facin exeraessisit la consenim iureet dignibh eu facilluptat vercil dunt autpat. " + "Ecte magna faccum dolor sequisc iliquat, quat, quipiss equipit accummy niate magna " + "facil iure eraesequis am velit, quat atis dolore dolent luptat nulla adio odipissectet " + "lan venis do essequatio conulla facillandrem zzriusci bla ad minim inis nim velit eugait " + "aut aut lor at ilit ut nulla ate te eugait alit augiamet ad magnim iurem il eu feuissi.\n" + "Guer sequis duis eu feugait luptat lum adiamet, si tate dolore mod eu facidunt adignisl in " + "henim dolorem nulla faccum vel inis dolutpatum iusto od min ex euis adio exer sed del " + "dolor ing enit veniamcon vullutat praestrud molenis ciduisim doloborem ipit nulla consequisi.\n" + "Nos adit pratetu eriurem delestie del ut lumsandreet nis exerilisit wis nos alit venit praestrud " + "dolor sum volore facidui blaor erillaortis ad ea augue corem dunt nis iustinciduis euisi.\n" + "Ut ulputate volore min ut nulpute dolobor sequism olorperilit autatie modit wisl illuptat dolore " + "min ut in ute doloboreet ip ex et am dunt at."; PdfDocument document = new PdfDocument(); PdfPage page = document.AddPage(); XGraphics gfx = XGraphics.FromPdfPage(page); XFont font = new XFont("Times New Roman", 10, XFontStyle.Bold); XTextFormatter tf = new XTextFormatter(gfx); XRect rect = new XRect(40, 100, 250, 220); gfx.DrawRectangle(XBrushes.SeaShell, rect); //tf.Alignment = ParagraphAlignment.Left; tf.DrawString(text, font, XBrushes.Black, rect, XStringFormats.TopLeft); rect = new XRect(310, 100, 250, 220); gfx.DrawRectangle(XBrushes.SeaShell, rect); tf.Alignment = XParagraphAlignment.Right; tf.DrawString(text, font, XBrushes.Black, rect, XStringFormats.TopLeft); rect = new XRect(40, 400, 250, 220); gfx.DrawRectangle(XBrushes.SeaShell, rect); tf.Alignment = XParagraphAlignment.Center; tf.DrawString(text, font, XBrushes.Black, rect, XStringFormats.TopLeft); rect = new XRect(310, 400, 250, 220); gfx.DrawRectangle(XBrushes.SeaShell, rect); tf.Alignment = XParagraphAlignment.Justify; tf.DrawString(text, font, XBrushes.Black, rect, XStringFormats.TopLeft); {s:endCsharp} {s:sampleSourceCode}
Meta Keywords:
Meta Description:
Change Comment:
Visit the new
Website for PDFsharp & MigraDoc Foundation 6.0 for .NET 6
and find information about the new version for Windows, Linux, and other platforms.
Miscellaneous
Home
PDFsharp
FAQ
Samples
Articles
MigraDoc
FAQ
Samples
Articles
ScrewTurn Wiki version 3.0.5.600. Some of the icons created by
FamFamFam
.
Impressum - Privacy Policy, Data Protection Declaration, Legal Notice