by Aspose (4 Submissions)
Category: Files/File Controls/Input/Output
Compatability: VB.NET
Difficulty: Unknown Difficulty
Originally Published: Thu 30th June 2011
Date Added: Mon 8th February 2021
Rating: (1 Votes)
This technical tip shows how Aspose.Pdf for .NET can be used to generate MultiLayer PDF documents.
API Declarations
By default all the contents inside section are added in Top-Left order, where every consecutive object is added in Top-Left to Right-Bottom approach. For the time being, we can think of a paragraph as a layer and objects inside a paragraph can be assumed as placed over some layer. We are going to create a MultiLayer PDF document using the approach of Adding a text object, add an image inside FloatingBox and place the Floating box over the text object. Please take a look over the following code snippet for this approach.
More about Aspose.Pdf for .NET
- Homepage of Aspose.Pdf for .NET: http://www.aspose.com/categories/.net-components/aspose.pdf-for-.net/default.aspx
- Read More Technical Tips by Aspose.Pdf for .NET at: http://www.aspose.com/documentation/.net-components/aspose.pdf-for-.net/technical-articles.html
- Download Aspose.Pdf for .NET at: http://www.aspose.com/community/files/51/.net-components/aspose.pdf-for-.net/default.aspx
[C#]
// Create a PDF object
Pdf pdf = new Pdf();
Aspose.Pdf.Section sec1 = pdf.Sections.Add();
// Create a text object
Text t1 = new Aspose.Pdf.Text(sec1);
// add the text object to Paragraphs collection of section
sec1.Paragraphs.Add(t1);
Segment seg1 = new Segment(t1);
// add the contents for Segment1
seg1.Content = "paragraph 3 segment 1";
// Specify the Font fore color for segement1
seg1.TextInfo.Color = new Aspose.Pdf.Color("red");
// specify the font size information for segment1
seg1.TextInfo.FontSize = 12;
// Specify the value for Opacity of text. Default is 1.0. Use it for multilayer effect
t1.Opacity = 0F;
// add the segment to segments collection of Text1
t1.Segments.Add(seg1);
//Tiff image cover the underlayer text
Aspose.Pdf.Image image1 = new Aspose.Pdf.Image(sec1);
image1.ImageInfo.File = @"d:/pdftest/top.tif";
image1.ImageInfo.ImageFileType = ImageFileType.Tiff;
// Create a Floating Box object that will hold image file
FloatingBox box1 = new FloatingBox(117,21);
// add Floating box to paragraphs collection of Section1
sec1.Paragraphs.Add(box1);
// Specify the left margin of FloatingBox1
box1.Left = -4;
// Specify the Top margin of FloatingBox1
box1.Top = -4;
// add the image file to paragraphs collection of FloatingBox
box1.Paragraphs.Add(image1);
// Save the reusltant PDF document
pdf.Save(@"d:/pdftest/multilayer.pdf");
[VB.NET]
' Create a PDF object
Dim pdf As Pdf = New Pdf()
Dim sec1 As Aspose.Pdf.Section = pdf.Sections.Add()
' Create a text object
Dim t1 As Text = New Aspose.Pdf.Text(sec1)
' add the text object to Paragraphs collection of section
sec1.Paragraphs.Add(t1)
Dim seg1 As Segment = New Segment(t1)
' add the contents for Segment1
seg1.Content = "paragraph 3 segment 1"
' Specify the Font fore color for segement1
seg1.TextInfo.Color = New Aspose.Pdf.Color("red")
' specify the font size information for segment1
seg1.TextInfo.FontSize = 12
' Specify the value for Opacity of text. Default is 1.0. Use it for multilayer effect
t1.Opacity = 0.0F
' add the segment to segments collection of Text1
t1.Segments.Add(seg1)
'Tiff image cover the underlayer text
Dim image1 As Aspose.Pdf.Image = New Aspose.Pdf.Image(sec1)
image1.ImageInfo.File = "d:/pdftest/top.tif"
image1.ImageInfo.ImageFileType = ImageFileType.Tiff
' Create a Floating Box object that will hold image file
Dim box1 As FloatingBox = New FloatingBox(117, 21)
' add Floating box to paragraphs collection of Section1
sec1.Paragraphs.Add(box1)
' Specify the left margin of FloatingBox1
box1.Left = -4
' Specify the Top margin of FloatingBox1
box1.Top = -4
' add the image file to paragraphs collection of FloatingBox
box1.Paragraphs.Add(image1)
' Save the reusltant PDF document
pdf.Save("d:/pdftest/multilayer.pdf")
[XML]
<?xml version="1.0" encoding="UTF-8"?>
<Pdf xml:space="preserve" xmlns="Aspose.Pdf">
<Section >
<Text Opacity="0">
<Segment Color="red" FontSize="12">paragraph 3 segment 1</Segment>
</Text>
<FloatingBox Width="117" Height="21" Left="-4" Top="-4" >
<Image File="d:/pdftest/top.tif" Type="Tiff" IsImageNotFoundErrorIgnored="true" />
</FloatingBox>
</Section>
</Pdf>
No comments have been posted about This technical tip shows how Aspose.Pdf for .NET can be used to generate MultiLayer PDF documents.. Why not be the first to post a comment about This technical tip shows how Aspose.Pdf for .NET can be used to generate MultiLayer PDF documents..