article

How to Add Text with Transparent Color in PDF File using .NET

Email
Submitted on: 3/30/2016 7:21:33 AM
By: Sherazam  
Level: Intermediate
User Rating: Unrated
Compatibility: C#, VB.NET
Views: 5117
 
     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.

 
				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.
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")

More about Aspose.Pdf for .NET


Other 44 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.