|
| 1 | +# Create PDF Document |
| 2 | + |
| 3 | +The Syncfusion<sup>®</sup> [.NET PDF library](https://www.syncfusion.com/document-processing/pdf-framework/net/pdf-library) used to create PDF document from scratch and saving it to disk or stream. This library also offers functionality to merge, split, stamp, forms, and secure PDF files. |
| 4 | + |
| 5 | +## Steps to create PDF document |
| 6 | + |
| 7 | +Follow these steps to crating a PDF using the Syncfusion<sup>®</sup> library: |
| 8 | + |
| 9 | +Step 1: **Create a new project**: Start by creating a new C# Console Application project. |
| 10 | + |
| 11 | +Step 2: **Install the NuGet package**: Reference the [Syncfusion.Pdf.NET](https://www.nuget.org/packages/Syncfusion.Pdf.Net) package in your project from [NuGet.org](https://www.nuget.org/). |
| 12 | + |
| 13 | +Step 3: **Include required namespaces**: Add the following namespace in your `Program.cs` file: |
| 14 | + |
| 15 | +```csharp |
| 16 | + using Syncfusion.Pdf; |
| 17 | + using Syncfusion.Pdf.Graphics; |
| 18 | +``` |
| 19 | + |
| 20 | +Step 4: **Create PDF document**: Use the following code snippet in `Program.cs` to merge PDF files: |
| 21 | + |
| 22 | +```csharp |
| 23 | +//Create a new PDF document. |
| 24 | +PdfDocument document = new PdfDocument(); |
| 25 | +//Add a page to the document. |
| 26 | +PdfPage page = document.Pages.Add(); |
| 27 | +//Create PDF graphics for the page. |
| 28 | +PdfGraphics graphics = page.Graphics; |
| 29 | +//Set the standard font. |
| 30 | +PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); |
| 31 | +//Draw the text. |
| 32 | +graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 0)); |
| 33 | + |
| 34 | +//Create file stream. |
| 35 | +using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) |
| 36 | +{ |
| 37 | + //Save the PDF document to file stream. |
| 38 | + document.Save(outputFileStream); |
| 39 | +} |
| 40 | +//Close the document. |
| 41 | +document.Close(true); |
| 42 | +``` |
| 43 | + |
| 44 | +You can download a complete working sample from the [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Getting%20Started/.NET/Create_PDF_NET). |
| 45 | + |
| 46 | +More information about the merge PDF can be found in this [documentation](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/create-pdf-file-in-c-sharp-vb-net) section. |
0 commit comments