|
| 1 | +# MigraDocCore |
| 2 | + |
| 3 | +MigraDocCore is a document generator. |
| 4 | +It supports almost anything you find in any good word processor. |
| 5 | +You just add paragraphs, tables, charts, arrange all this in sections, use bookmarks to create links, tables of contents, indexes, etc. |
| 6 | +MigraDocCore will do the layout creating page breaks as needed. |
| 7 | +MigraDocCore will create PDF documents. |
| 8 | + |
| 9 | +* [Features](#features) |
| 10 | +* [First steps](#first-steps) |
| 11 | +* [Samples](samples/index.md) |
| 12 | +* [FAQ](faq.md) |
| 13 | + |
| 14 | + |
| 15 | +## Features |
| 16 | + |
| 17 | +* Create perfect documents “on the fly” |
| 18 | +* Import data from various sources via XML files or direct interfaces (any data source that can be used with .NET) |
| 19 | +* Integrates easily with existing applications and systems |
| 20 | +* Various options for page layout, text formatting, and document design |
| 21 | +* Dynamic tables and business charts |
| 22 | +* Re-usable building blocks consisting of text and / or code |
| 23 | +* Documents with navigation (hyperlinks and / or bookmarks) |
| 24 | + |
| 25 | + |
| 26 | +## First steps |
| 27 | + |
| 28 | +Both PDFsharpCore and MigraDocCore provide a lot of `AddXxx` functions. |
| 29 | +Typically these functions return the newly created objects. Once you’ve learned the basic principles it’s quite easy to work with. |
| 30 | +Intellisense helps a lot then. |
| 31 | + |
| 32 | +We’ll discuss a few lines of the [Hello World](samples/HelloWorld.md) sample here. |
| 33 | + |
| 34 | +```cs |
| 35 | +// We start with a new document: |
| 36 | +Document document = new Document(); |
| 37 | + |
| 38 | +// With MigraDocCore, we don’t add pages, we add sections (at least one): |
| 39 | +Section section = document.AddSection(); |
| 40 | + |
| 41 | +// Adding text is simple: |
| 42 | +section.AddParagraph("Hello, World!"); |
| 43 | + |
| 44 | +// Adding empty paragraphs is even simpler: |
| 45 | +section.AddParagraph(); |
| 46 | + |
| 47 | +// Store the newly created object for modification: |
| 48 | +Paragraph paragraph = section.AddParagraph(); |
| 49 | +paragraph.Format.Font.Color = Color.FromCmyk(100, 30, 20, 50); |
| 50 | +paragraph.AddFormattedText("Hello, World!", TextFormat.Underline); |
| 51 | + |
| 52 | +// AddFormattedText also returns an object: |
| 53 | +FormattedText ft = paragraph.AddFormattedText("Small text", TextFormat.Bold); |
| 54 | +ft.Font.Size = 6; |
| 55 | + |
| 56 | +// And there’s much more that can be added: AddTable, AddImage, AddHyperlink, AddBookmark, AddPageField, AddPageBreak, ... |
| 57 | +
|
| 58 | +// With MigraDocCore you can create PDF or RTF. Just select the appropriate renderer: |
| 59 | +PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(false, |
| 60 | +PdfFontEmbedding.Always); |
| 61 | + |
| 62 | +// Pass the document to the renderer: |
| 63 | +pdfRenderer.Document = document; |
| 64 | + |
| 65 | +// Let the renderer do its job: |
| 66 | +pdfRenderer.RenderDocument(); |
| 67 | + |
| 68 | +// Save the PDF to a file: |
| 69 | +string filename = "HelloWorld.pdf"; |
| 70 | +pdfRenderer.PdfDocument.Save(filename); |
| 71 | +``` |
0 commit comments