How to Add Text with Transparent Color in PDF File using .NET
This technical tip shows how .NET developers can add transparent Text in PDF files using Aspose.Pdf for .NET. A PDF file contains Image, Text, Graph, attachment, Annotations objects and while creating TextFragment, you can set foreground, background color information as well as text formatting. Aspose.Pdf for .NET supports the feature to add text with Alpha color channel.
//your code here...The following code snippet shows how to add text with transparent color.
//C# Code Sample
// create Document instance
Document doc = new Document();
// create page to pages collection of PDF file
Aspose.Pdf.Page page = doc.Pages.Add();
// create Graph object
Aspose.Pdf.Drawing.Graph canvas = new Aspose.Pdf.Drawing.Graph(100, 400);
// create rectangle instance with certain dimensions
Aspose.Pdf.Drawing.Rectangle rect = new Aspose.Pdf.Drawing.Rectangle(100, 100, 400, 400);
// create color object from Alpha color channel
rect.GraphInfo.FillColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.FromArgb(128, System.Drawing.Color.FromArgb(12957183)));
// add rectanlge to shapes collection of Graph object
canvas.Shapes.Add(rect);
// add graph object to paragraphs collection of page object
page.Paragraphs.Add(canvas);
// set value to not change position for graph object
canvas.IsChangePosition = false;
// create TextFragment instance with sample value
TextFragment text = new TextFragment("transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text ");
// create color object from Alpha channel
Aspose.Pdf.Color color = Aspose.Pdf.Color.FromArgb(30, 0, 255, 0);
// set color information for text instance
text.TextState.ForegroundColor = color;
// add text to paragraphs collection of page instance
page.Paragraphs.Add(text);
// save PDF file
doc.Save("c:/Transparent_Text.pdf");
//VB.NET Code Sample
' create Document instance
Dim doc As Document = New Document()
' create page to pages collection of PDF file
Dim page As Aspose.Pdf.Page = doc.Pages.Add()
' create Graph object
Dim canvas As Aspose.Pdf.Drawing.Graph = New Aspose.Pdf.Drawing.Graph(100, 400)
' create rectangle instance with certain dimensions
Dim rect As Aspose.Pdf.Drawing.Rectangle = New Aspose.Pdf.Drawing.Rectangle(100, 100, 400, 400)
' create color object from Alpha color channel
rect.GraphInfo.FillColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.FromArgb(128, System.Drawing.Color.FromArgb(12957183)))
' add rectanlge to shapes collection of Graph object
canvas.Shapes.Add(rect)
' add graph object to paragraphs collection of page object
page.Paragraphs.Add(canvas)
' set value to not change position for graph object
canvas.IsChangePosition = False
' create TextFragment instance with sample value
Dim text As Aspose.Pdf.Text.TextFragment = New TextFragment("transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text ")
' create color object from Alpha channel
Dim color As Aspose.Pdf.Color = Aspose.Pdf.Color.FromArgb(30, 0, 255, 0)
' set color information for text instance
Text.TextState.ForegroundColor = color
' add text to paragraphs collection of page instance
page.Paragraphs.Add(Text)
' save PDF file
doc.Save("c:/Transparent_Text.pdf")
Url: http://www.aspose.com/.net/pdf-component.aspx
Language: C# | User: Sheraz Khan | Created: Mar 30, 2016 | Tags: add transparent Text in PDF background color information add text with Alpha color channel create page to pages collection of PDF file save PDF file in .NET .NET PDF component