In Aspose.Pdf , Paragraph class provides ID property that is used to assign an ID to any specific Paragraph.
All you have to do is to assign some value to the ID property of any kind of a Paragraph object.
Code Snippet
[C#]
//Create a text paragraph with the reference of a section, sec1
Text text3 = new Text(sec1,"product 1 info ...");
//Add the text paragraph in the section
sec1.Paragraphs.Add(text3);
//Set the text paragraph to be the first paragraph among the other ones
text3.IsFirstParagraph = true;
//Assign and ID to the text paragraph
text3.ID = "product1";
[VB.NET]
'Create a text paragraph with the reference of a section, sec1
Dim text3 As Text = New Text(sec1, "product 1 info ...")
'Add the text paragraph in the section
sec1.Paragraphs.Add(text3)
'Set the text paragraph to be the first paragraph among the other ones
text3.IsFirstParagraph = True
'Assign and ID to the text paragraph
text3.ID = "product1"
[JAVA]
//Create a text paragraph with the reference of a section, sec1
Text text3 = new Text(sec1,"product 1 info ...");
//Add the text paragraph in the section
sec1.getParagraphs().add(text3);
//Set the text paragraph to be the first paragraph among the other ones
text3.setFirstParagraph(true);
//Assign and ID to the text paragraph
text3.setID("product1");
[XML]
<?xml version="1.0" encoding="utf-8" ?>
<Pdf xmlns="Aspose.Pdf">
<Section>
<Text IsFirstParagraph="true" ID="product1">
<Segment>
product 1 info ...
</Segment>
</Text>
</Section>
</Pdf>
This Paragraph ID can be used for different purposes and we have listed below few of them for your convenience:
Error Location
Paragraph ID can be used to locate errors in your source code. Sometimes, your application may throw an exception and you would like to know that which Paragraph is raising that exception. If you have set the Paragraph ID , the ID will be displayed in the exception message most of the times and you can track the error easily. This usage of Paragraph ID can help developers to debug their applications with a great ease.
Paragraph Identification
The second purpose to use Paragraph ID is to locate Paragraph in Paragraph collection. If we assign an ID to a Paragraph and then add in Paragraph collection then we can retrieve that particular Paragraph from the collection very easily by just passing its ID . This also shows the flexibility in Aspose.Pdf API for its users.
Linking Destination in Hyperlink
The third purpose is to set linking destination in Hyperlink . If we want to create a Hyperlink pointing towards a specific Paragraph in the same PDF document, we can achieve this by linking the ID of any specific Paragraph to the Hyperlink .