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
»
Back
MigraDoc Sample: Hello World
Modified on 2015/09/14 10:17
by
Thomas Hövel
Categorized as
MigraDoc Samples
,
Samples
{s:navigationUpNext|MigraDocSamples|HelloMigraDoc-sample} This sample is the obligatory Hello World program for MigraDoc documents. == PDF Output File == See the PDF file created by this sample: {s:PdfLink|MigraDocHelloWorld-sample%2fHelloWorld_output.pdf|output.pdf} (9 kB) == Source Code Listing == The Main method: {s:beginCsharp} static void Main(string[] args) { // Create a MigraDoc document Document document = CreateDocument(); document.UseCmykColor = true; // ===== Unicode encoding and font program embedding in MigraDoc is demonstrated here ===== // A flag indicating whether to create a Unicode PDF or a WinAnsi PDF file. // This setting applies to all fonts used in the PDF document. // This setting has no effect on the RTF renderer. const bool unicode = false; // An enum indicating whether to embed fonts or not. // This setting applies to all font programs used in the document. // This setting has no effect on the RTF renderer. // (The term 'font program' is used by Adobe for a file containing a font. Technically a 'font file' // is a collection of small programs and each program renders the glyph of a character when executed. // Using a font in PDFsharp may lead to the embedding of one or more font programms, because each outline // (regular, bold, italic, bold+italic, ...) has its own fontprogram) const PdfFontEmbedding embedding = PdfFontEmbedding.Always; // ======================================================================================== // Create a renderer for the MigraDoc document. PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(unicode, embedding); // Associate the MigraDoc document with a renderer pdfRenderer.Document = document; // Layout and render document to PDF pdfRenderer.RenderDocument(); // Save the document... const string filename = "HelloWorld.pdf"; pdfRenderer.PdfDocument.Save(filename); // ...and start a viewer. Process.Start(filename); } {s:endCsharp} The CreateDocument method: {s:beginCsharp} /// <summary> /// Creates an absolutely minimalistic document. /// </summary> static Document CreateDocument() { // Create a new MigraDoc document Document document = new Document(); // Add a section to the document Section section = document.AddSection(); // Add a paragraph to the section Paragraph paragraph = section.AddParagraph(); paragraph.Format.Font.Color = Color.FromCmyk(100, 30, 20, 50); // Add some text to the paragraph paragraph.AddFormattedText("Hello, World!", TextFormat.Bold); return document; } {s:endCsharp} {s:sampleSourceCode}
Meta Keywords:
Meta Description:
Change Comment:
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