[]
The following quick start sections help you in getting started with the GcPdf library:
This quick start covers how to create a simple PDF document having a single page and draw string on it in a specified font using a .NET Core or .NET Standard application. Follow the steps below to get started:
Create a new application (.NET Core Console App\Windows Forms App) and add the references.
Include the following namespaces
using GrapeCity.Documents.Pdf;
using GrapeCity.Documents.Text;
Create a new PDF document using an instance of GcPdfDocument and define a text format for drawing a string, through code.
// Create a new PDF document:
GcPdfDocument doc = new GcPdfDocument();
// Add a page, and get its Graphics object to draw on:
GcPdfGraphics g = doc.NewPage().Graphics;
// Create a text format for the "Hello World!" string:
TextFormat tf = new TextFormat();
// Use standard Times font
tf.Font = StandardFonts.Times;
// Pick a font size:
tf.FontSize = 14;
Add the following code that uses DrawString method of GcGraphics class to draw string.
// Draw the string at (1",1") from top/left of page
//(72 dpi is the default PDF graphics' resolution):
g.DrawString("Hello World!", tf, new PointF(72, 72));
Save the document using Save method of the GcPdfDocument class.
//Save PDF document
doc.Save("filename.pdf");
This quick start covers how to load an existing PDF document, modify and save it using a .NET Core or .NET Standard application. Follow the steps below to get started:
Create a new application (.NET Core Console App\Windows Forms App) and add the references.
Include the following namespace
using GrapeCity.Documents.Pdf;
Load an existing document using Load method of the GcPdfDocument class.
GcPdfDocument doc = new GcPdfDocument();
//Create an object of filestream
var fs = new FileStream(Path.Combine("DocAttachment.pdf"), FileMode.Open,
FileAccess.Read);
//Load the document
doc.Load(fs);
Add a new page to the document using NewPage method of the GcPdfDocument class.
//Add a new page in the document
GcPdfGraphics g = doc.NewPage().Graphics;
Add the following code that uses DrawString method of GcGraphics class to draw string.
//Add text on the new page
g.DrawString("This is a newly added page in the modified document.", new TextFormat()
{
Font = StandardFonts.Times,
FontSize = 12
}, new PointF(72, 72));
Save the document using Save method of the GcPdfDocument class.
//Save the document
doc.Save("ModifiedDocument.pdf");