SyntaxSolutions.PdfBuilder
1.0.0-rc
This is a prerelease version of SyntaxSolutions.PdfBuilder.
dotnet add package SyntaxSolutions.PdfBuilder --version 1.0.0-rc
NuGet\Install-Package SyntaxSolutions.PdfBuilder -Version 1.0.0-rc
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SyntaxSolutions.PdfBuilder" Version="1.0.0-rc" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SyntaxSolutions.PdfBuilder --version 1.0.0-rc
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SyntaxSolutions.PdfBuilder, 1.0.0-rc"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SyntaxSolutions.PdfBuilder as a Cake Addin
#addin nuget:?package=SyntaxSolutions.PdfBuilder&version=1.0.0-rc&prerelease
// Install SyntaxSolutions.PdfBuilder as a Cake Tool
#tool nuget:?package=SyntaxSolutions.PdfBuilder&version=1.0.0-rc&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
PDF Builder .Net
A simple .Net library used to create portable document format (PDF) documents.
Features
- Two built in fonts 'Arial' and 'Times New Roman'
- Methods to easily add a page title, heading, text, paragraph, table, line and image to a document
- Event driven page header and footer rendering
- Support for all standard page sizes and orientations
- Page coorindates and sizes specified in millimetres (mm)
Installation
PM> Install-Package SyntaxSolutions.PdfBuilder
Example
using SyntaxSolutions.PdfBuilder;
private void PageHeader(PdfBuilder builder, PageHeaderEventArgs e)
{
builder.AddText("...PAGE HEADER...");
builder.NewLine();
}
private void PageFooter(PdfBuilder builder, PageFooterEventArgs e)
{
var postionY = builder.PagePositionY;
builder.PagePositionY = 10;
builder.AddText(String.Format("...PAGE FOOTER... | Page: {0}", builder.PageCount.ToString()));
builder.PagePositionY = postionY;
}
var documentOptions = new DocumentOptions()
{
PageSize = PageSize.A4,
PageOrientation = PageOrientation.Portrait,
DefaultFontFamily = TextFontFamily.TimesNewRoman,
};
var builder = new PdfBuilder(documentOptions);
builder.PageHeader += new PageHeaderEventHandler(this.PageHeader);
builder.PageFooter += new PageFooterEventHandler(this.PageFooter);
builder.Open();
//
// Fonts
//
builder.NewPage();
builder.NewLine();
builder.AddTitle("Fonts");
builder.NewLine();
builder.AddHeading("Styles");
builder.AddText("Times New Roman - Normal");
builder.NewLine();
builder.AddText("Times New Roman - Bold", TextOptions.Set(FontWeight: TextFontWeight.Bold));
builder.NewLine();
builder.AddText("Times New Roman - Italic", TextOptions.Set(FontStyle: TextFontStyle.Italic));
builder.NewLine();
builder.AddText("Times New Roman - Italic Bold", TextOptions.Set(FontStyle: TextFontStyle.Italic, FontWeight: TextFontWeight.Bold));
builder.NewLine();
builder.AddText("Arial - Normal", TextOptions.Set(FontFamily: TextFontFamily.Arial));
builder.NewLine();
builder.AddText("Arial - Bold", TextOptions.Set(FontFamily: TextFontFamily.Arial, FontWeight: TextFontWeight.Bold));
builder.NewLine();
builder.AddText("Arial - Italic", TextOptions.Set(FontFamily: TextFontFamily.Arial, FontStyle: TextFontStyle.Italic));
builder.NewLine();
builder.AddText("Arial - Italic Bold", TextOptions.Set(FontFamily: TextFontFamily.Arial, FontStyle: TextFontStyle.Italic, FontWeight: TextFontWeight.Bold));
builder.NewLine();
builder.NewLine();
builder.AddHeading("Colors");
builder.AddText("Red", TextOptions.Set(FontColor: Color.Red));
builder.NewLine();
builder.AddText("Green", TextOptions.Set(FontColor: Color.Green));
builder.NewLine();
builder.AddText("Blue", TextOptions.Set(FontColor: Color.Blue));
builder.NewLine();
//
// Paragraphs
//
builder.NewPage();
builder.NewLine();
builder.AddTitle("Paragraphs");
builder.NewLine();
builder.AddHeading("Left Aligned");
builder.AddParagraph("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
builder.NewLine();
builder.AddHeading("Center Aligned");
builder.AddParagraph("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", ParagraphOptions.Set(TextAlignment: TextAlignment.Center));
builder.NewLine();
builder.AddHeading("Right Aligned");
builder.AddParagraph("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", ParagraphOptions.Set(TextAlignment: TextAlignment.Right));
builder.NewLine();
builder.AddHeading("Justified Aligned");
builder.AddParagraph("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", ParagraphOptions.Set(TextAlignment: TextAlignment.Justify));
builder.NewLine();
//
// Images
//
builder.NewPage();
builder.NewLine();
builder.AddTitle("Images");
builder.NewLine();
string imagepath = @"Sunset.jpg";
builder.AddImage(imagepath, 50);
builder.NewLine();
builder.AddImage(imagepath, 100);
builder.NewLine();
builder.AddImage(imagepath, 150);
builder.NewLine();
//
// Tables
//
builder.NewPage();
builder.NewLine();
builder.AddTitle("Tables");
builder.NewLine();
var tableOptions = TableOptions.Set(
DefaultFontFamily: TextFontFamily.TimesNewRoman,
BorderHeaderWidth: 1.0,
BorderTopWidth: 0.0,
BorderBottomWidth: 1.0,
BorderHorizontalWidth: 0.8,
BorderVerticalWidth: 0.6,
BorderVerticalColor: Color.DarkGray,
ColumnWidths: new List<double>(new double[] { 1.0, 2.0, 1.0 })
);
var table = new Table(tableOptions);
var headerCellOptions = new TableCellOptions()
{
FontOptions = table.Options.HeaderFontOptions,
TextAlignment = TextAlignment.Center,
BackgroundColor = Color.LightGray
};
// change font family from the default
headerCellOptions.FontOptions.FontFamily = TextFontFamily.Arial;
var headerRowOptions = TableRowOptions.Set(TableCellOptions: headerCellOptions);
var headers = new TableRow(headerRowOptions);
headers.AddCell("Header 1");
headers.AddCell("Header 2");
headers.AddCell("Header 3");
table.AddHeaders(headers);
// default options for a table cell
var defaultTableCellOptions = new TableCellOptions()
{
FontOptions = table.Options.CellFontOptions,
};
// change the font color
defaultTableCellOptions.FontOptions.FontColor = Color.DarkGray;
// specific cell options
var descriptionTableCellOptions = TableCellOptions.Set(FontColor: Color.Red, FontFamily: table.Options.DefaultFontFamily);
var amountTableCellOptions = TableCellOptions.Set(TextAlignment: TextAlignment.Right, BackgroundColor: Color.LightGreen, FontFamily: TextFontFamily.Arial);
// default options for a table row
var defaultTableRowOptions = TableRowOptions.Set(TableCellOptions: defaultTableCellOptions);
var row1 = new TableRow(defaultTableRowOptions);
row1.AddCell("Row 1");
row1.AddCell("Item 1", descriptionTableCellOptions);
row1.AddCell("123.00", amountTableCellOptions);
table.AddRow(row1);
var row2 = new TableRow(defaultTableRowOptions);
row2.AddCell("Row 2");
row2.AddCell("Item 2", descriptionTableCellOptions);
row2.AddCell("123.00", amountTableCellOptions);
table.AddRow(row2);
var row3 = new TableRow(defaultTableRowOptions);
row2.AddCell("Row 3");
row2.AddCell("Item 3", descriptionTableCellOptions);
row2.AddCell("123.00", amountTableCellOptions);
table.AddRow(row2);
builder.AddTable(table);
//
// Lines
//
builder.NewPage();
builder.NewLine();
builder.AddTitle("Lines");
builder.NewLine();
var lineOptions = new LineOptions()
{
LineColor = Color.Blue,
LineWidth = 1.0
};
builder.AddLine(80, LineOptions.Set(LineColor: Color.Blue));
builder.NewLine();
builder.AddLine(140, LineOptions.Set(LineColor: Color.Green));
builder.NewLine();
builder.AddLine(190, LineOptions.Set(LineColor: Color.Red));
//
// save file
//
using (var fileStream = new FileStream("Test.pdf", FileMode.Create, FileAccess.Write))
{
byte[] data = builder.GetBytes();
fileStream.Write(data, 0, data.Length);
}
builder.Close();
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net452 is compatible. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETFramework 4.5.2
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0-rc | 164 | 8/11/2021 |
1.0.0-beta | 166 | 1/27/2021 |
A simple .Net library used to generate PDF files