|
| 1 | +using Syncfusion.Pdf; |
| 2 | +using Syncfusion.Pdf.Graphics; |
| 3 | +using Syncfusion.Drawing; |
| 4 | + |
| 5 | +// Create a new PDF document |
| 6 | +using (PdfDocument document = new PdfDocument()) |
| 7 | +{ |
| 8 | + // Add a page |
| 9 | + PdfPage page = document.Pages.Add(); |
| 10 | + |
| 11 | + // Initialize unit converter |
| 12 | + PdfUnitConverter converter = new PdfUnitConverter(); |
| 13 | + |
| 14 | + // Convert margins from inches to points |
| 15 | + float margin = converter.ConvertUnits(1f, PdfGraphicsUnit.Inch, PdfGraphicsUnit.Point); |
| 16 | + |
| 17 | + // Define text bounds to fill the page with margins |
| 18 | + RectangleF textBounds = new RectangleF( |
| 19 | + margin, |
| 20 | + margin, |
| 21 | + page.Graphics.ClientSize.Width - 2 * margin, |
| 22 | + page.Graphics.ClientSize.Height - 2 * margin |
| 23 | + ); |
| 24 | + |
| 25 | + // Define font and paragraph text |
| 26 | + PdfFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 14); |
| 27 | + |
| 28 | + string paragraphText = "Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Washington with 290 employees, several regional sales teams are located throughout their market base."; |
| 29 | + |
| 30 | + // Create text element and layout format |
| 31 | + PdfTextElement textElement = new PdfTextElement(paragraphText, font, PdfBrushes.Black); |
| 32 | + |
| 33 | + PdfLayoutFormat layoutFormat = new PdfLayoutFormat |
| 34 | + { |
| 35 | + Break = PdfLayoutBreakType.FitPage, |
| 36 | + Layout = PdfLayoutType.Paginate |
| 37 | + }; |
| 38 | + |
| 39 | + // Draw the paragraph text within the bounds |
| 40 | + textElement.Draw(page, textBounds, layoutFormat); |
| 41 | + |
| 42 | + //Save the document |
| 43 | + document.Save(Path.GetFullPath(@"Output/Output.pdf")); |
| 44 | +} |
0 commit comments