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: First Steps
Modified on 2013/09/10 17:32
by
Thomas Hövel
Categorized as
Articles
,
MigraDoc Articles
Both PDFsharp and MigraDoc provide a lot of AddXxx functions. Typically these functions return the newly created objects. Once you’ve learned the basic principles it’s quite easy to work with. Intellisense helps a lot then. And the new help system that integrates with the Visual Studio online help will provide information about any class in PDFsharp and MigraDoc – simply by hitting F1. ==MigraDoc - Getting Started== A good place to start is the Samples folder that comes with the source code. This wiki also shows the [MigraDocSamples|MigraDoc Samples]. We’ll discuss a few lines of the Hello World sample here. We start with a new document: {s:beginCsharp} Document document = new Document(); {s:endCsharp} With MigraDoc, we don’t add pages, we add sections (at least one): {s:beginCsharp} Section section = document.AddSection(); {s:endCsharp} Adding text is simple: {s:beginCsharp} section.AddParagraph("Hello, World!"); {s:endCsharp} Adding empty paragraphs is even simpler: {s:beginCsharp} section.AddParagraph(); {s:endCsharp} Store the newly created object for modification: {s:beginCsharp} Paragraph paragraph = section.AddParagraph(); paragraph.Format.Font.Color = Color.FromCmyk(100, 30, 20, 50); paragraph.AddFormattedText("Hello, World!", TextFormat.Underline); {s:endCsharp} AddFormattedText also returns an object: {s:beginCsharp} FormattedText ft = paragraph.AddFormattedText("Small text", TextFormat.Bold); ft.Font.Size = 6; {s:endCsharp} And there’s much more that can be added: AddTable, AddImage, AddHyperlink, AddBookmark, AddPageField, AddPageBreak, ... With MigraDoc you can create PDF or RTF. Just select the appropriate renderer: {s:beginCsharp} PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(false, PdfFontEmbedding.Always); {s:endCsharp} Pass the document to the renderer: {s:beginCsharp} pdfRenderer.Document = document; {s:endCsharp} Let the renderer do its job: {s:beginCsharp} pdfRenderer.RenderDocument(); {s:endCsharp} Save the PDF to a file: {s:beginCsharp} string filename = "HelloWorld.pdf"; pdfRenderer.PdfDocument.Save(filename); {s:endCsharp} A PC application might show the file: {s:beginCsharp} Process.Start(filename); {s:endCsharp}
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