The following quick start sections help you in getting started with the DsPdf 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:
C# |
Copy 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.
C# |
Copy Code
|
---|---|
// 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.
C# |
Copy Code
|
---|---|
//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:
C# |
Copy Code
|
---|---|
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); |
C# |
Copy Code
|
---|---|
//Add a new page in the document
GcPdfGraphics g = doc.NewPage().Graphics;
|
C# |
Copy Code
|
---|---|
//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.
C# |
Copy Code
|
---|---|
//Save the document doc.Save("ModifiedDocument.pdf"); |