|
<< Click to Display Table of Contents >> Navigation: Gnostice Document Studio .NET > Going Deeper > Document Engines > Working with PDF > Creation > Create PDF with transparency |
In this section we present example code to create a new PDF document containing text, graphic shapes and images with transparency applied. Before proceeding further please make sure that the prerequisite steps as listed in the Document Engines parent topic are followed.
Given below is the sample code.
// Create a new PDF document
using (var pdfDoc = new PDF())
{
// Set the measurement unit to inches
pdfDoc.MeasurementUnit = MeasurementUnit.Inches;
var page = new PDFPage();
// Sets alpha value for brush color
page.Brush.Color = Color.FromARGB(30, Color.Blue);
// Writes translucent text
page.WriteText("This is transparent text", 1, 2.5f);
// Changes alpha value for brush color
page.Brush.Color = Color.FromARGB(40, Color.YellowGreen);
// Draws a translucent ellipse
var pen = new Pen(Color.Black);
page.DrawEllipse(pen, new SimpleRect(x: 1, y: 3.5f, width: 2, height: 1), isFill: true, isStroke: true);
// Changes alpha value of brush color again
page.Brush.Color = Color.FromARGB(10, Color.Empty);
// Draws a translucent image
page.DrawImage(@"logo.png", new SimpleRect(1, 4.5f, 2, 1));
// Add the page to the document
pdfDoc.AddPage(page);
// Save the document to file
pdfDoc.Save("sample_doc.pdf");
// Optional, since the using statement will automatically close the document
pdfDoc.CloseDocument();
}