Skip to content

Commit 0a0e526

Browse files
committed
Examples Added
1 parent e4c8f68 commit 0a0e526

File tree

3 files changed

+79
-58
lines changed

3 files changed

+79
-58
lines changed

Examples.xml

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@
580580
<Example>
581581
<Title>Replace Text in All Pages of PDF</Title>
582582
<Description>In order to replace text in all the pages of a PDF document, you first need to use TextFragmentAbsorber to find the particular phrase you want to replace. After that, you need to go through all the TextFragments to replace the text and change any other attributes. Once you have done that, you only need to save the output PDF using Save method of the Document object. The example elaborates this in detail to replace text in a PDF document.</Description>
583-
<FolderName>replacetextinallpages</FolderName>
583+
<FolderName>replacetextallpages</FolderName>
584584
<Order>1</Order>
585585
<DocLink>
586586
<DisplayName>Replace Text in All Pages of a PDF Document</DisplayName>
@@ -622,7 +622,7 @@
622622
<Example>
623623
<Title>Extract Text from an Individual Page of the PDF Document</Title>
624624
<Description>TextAbsorber class allows you to extract text from a particular page of a PDF document. This class returns the extracted text in Text property. The Accept method of an individual page is called to extract the text. Create objects of Document and TextAbsorber classes. Call Accept method on the individual page, as PageIndex , of Document object. The Index is the particular page number from where text needs to be extracted. You can get text from the Text property of the TextAbsorber class.</Description>
625-
<FolderName>extracttxtfrompageofpdfdoc</FolderName>
625+
<FolderName>extracttextfromindividualpageofpdf</FolderName>
626626
<Order>3</Order>
627627
<DocLink>
628628
<DisplayName>Extract Text from an Individual Page of the PDF Document</DisplayName>
@@ -643,7 +643,7 @@
643643
<Example>
644644
<Title>Search and Get Text from All the Pages of PDF Document</Title>
645645
<Description>TextFragmentAbsorber allows you to find text, matching a particular phrase, from all the pages of a PDF document. In order to search text from the whole document, you need to call the Accept method of Pages collection. The Accept method takes TextFragmentAbsorber object as parameter, which returns a collection of TextFragment objects. You can loop through all the fragments and get their properties like Text , Position ( XIndent , YIndent ), FontName , FontSize , IsAccessible , IsEmbedded , IsSubset , ForegroundColor ** etc.</Description>
646-
<FolderName>searchandgettextfrompagesofpdf</FolderName>
646+
<FolderName>searchandgettextfromallpagesofpdf</FolderName>
647647
<Order>4</Order>
648648
<DocLink>
649649
<DisplayName>Search and Get Text from All the Pages of PDF Document</DisplayName>
@@ -659,7 +659,7 @@
659659
<Example>
660660
<Title>Search and Get Text from a Single Page of a PDF Document</Title>
661661
<Description>TextFragmentAbsorber allows you to find text, matching a particular phrase, from a particular page of a PDF document. In order to search text from an individual page, you need to call the Accept method of that particular as Page Index . The Index represents a particular page number. The Accept method takes TextFragmentAbsorber object as parameter, which returns a collection of TextFragment objects. You can loop through all the fragments and get their properties like Text , Position ( XIndent , YIndent ), FontName , FontSize , IsAccessible , IsEmbedded , IsSubset , ForegroundColor ** etc.</Description>
662-
<FolderName>searchandgettextfrompageofpdfdoc</FolderName>
662+
<FolderName>searchandgettextfromsinglepageofpdf</FolderName>
663663
<Order>5</Order>
664664
<DocLink>
665665
<DisplayName>Search and Get Text from a Single Page of a PDF Document</DisplayName>
@@ -675,7 +675,7 @@
675675
<Example>
676676
<Title>Search and Get Text Segments from All Pages of PDF Document</Title>
677677
<Description>In order to search text segments from all the pages, you first need to get the TextFragment objects from the document . TextFragmentAbsorber allows you to find text, matching a particular phrase, from all the pages of a PDF document. In order to search text from the whole document, you need to call the Accept method of Pages collection. The Accept method takes TextFragmentAbsorber object as parameter, which returns a collection of TextFragment objects.</Description>
678-
<FolderName>searchandgettextsegmentsfrompagesofpdf</FolderName>
678+
<FolderName>searchandgettextsegmentsfromallpagesofpdf</FolderName>
679679
<Order>6</Order>
680680
<DocLink>
681681
<DisplayName>Search and Get Text Segments from All Pages of PDF Document</DisplayName>
@@ -691,7 +691,7 @@
691691
<Example>
692692
<Title>Search and Get Text Segments From an Individual Page of PDF Document</Title>
693693
<Description>In order to search text segments from a single page, you first need to get the TextFragment objects from the document . TextFragmentAbsorber allows you to find text, matching a particular phrase, from an individual page of a PDF document. In order to search text from a particular page, you need to call the Accept method of that particular page as Pages Index . Index represents the page number from where text needs to be extracted. The Accept method takes TextFragmentAbsorber object as parameter, which returns a collection of TextFragment objects.</Description>
694-
<FolderName>searchandgettextsegmentsfromanindividualpageofpdfdocument</FolderName>
694+
<FolderName>searchandgettextsegmentsfromindividualpageofpdf</FolderName>
695695
<Order>7</Order>
696696
<DocLink>
697697
<DisplayName>Search and Get Text Segments From an Individual Page of PDF Document</DisplayName>
@@ -723,7 +723,7 @@
723723
<Example>
724724
<Title>Search and Get Text from a Single Page Using Regular Expression</Title>
725725
<Description>TextFragmentAbsorber helps you search and retrieve text, from a single page, based on regular expression. First you need to pass a regular expression to TextFragmentAbsorber constructor as the phrase. After that you have to set the TextSearchOptions property of the TextFragmentAbsorber object. This property requires TextSearchOptions object and you need to pass true as parameter to its constructor while creating new object. As you want to retrieve matching text from a particular page, you need to call Accept method of that individual page as Pages Index. Index represents the page number. TextFragmentAbsorber returns a TextFragmentCollection containing all the fragments matching the criteria specified by the regular expression</Description>
726-
<FolderName>searchandgettextfromasinglepageusingregularexpression</FolderName>
726+
<FolderName>searchandgettextfromsinglepageusingregularexpression</FolderName>
727727
<Order>9</Order>
728728
<DocLink>
729729
<DisplayName>Search and Get Text from a Single Page Using Regular Expression</DisplayName>
@@ -736,6 +736,27 @@
736736
</InputFiles>
737737
<Type>Console</Type>
738738
</Example>
739+
<Example>
740+
<Title>Replace Text in a Single Page of a PDF Document</Title>
741+
<Description>N order to replace text in a single page, you need to get TextFragments of that particular page. For that matter, you first need to create TextFragmentAbsorber with the phrase you want to replace. Once you get all the TextFragments , you can loop though them and replace the text and other attributes. After that, you need to save the updated PDF using Save method of Document object.</Description>
742+
<FolderName>replacetextinsinglepageofpdf</FolderName>
743+
<Order>10</Order>
744+
<DocLink>
745+
<DisplayName>Replace Text in a Single Page of a PDF Document</DisplayName>
746+
<Url>Replace+Text+in+a+Single+Page+of+a+PDF+Document</Url>
747+
</DocLink>
748+
<InputFiles>
749+
<DataFile>
750+
<Path>..\data\input.pdf</Path>
751+
</DataFile>
752+
</InputFiles>
753+
<OutputFiles>
754+
<DataFile>
755+
<Path>..\data\output.pdf</Path>
756+
</DataFile>
757+
</OutputFiles>
758+
<Type>Console</Type>
759+
</Example>
739760
</Examples>
740761
</Folder>
741762
<Folder>
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,51 @@
1-
/*
2-
* Copyright 2001-2013 Aspose Pty Ltd. All Rights Reserved.
3-
*
4-
* This file is part of Aspose.Pdf. The source code in this file
5-
* is only intended as a supplement to the documentation, and is provided
6-
* "as is", without warranty of any kind, either expressed or implied.
7-
*/
8-
9-
package programmersguide.workingwithasposepdf.workingwithtext.replacetextinallpages.java;
10-
11-
import com.aspose.pdf.*;
12-
13-
14-
public class ReplaceTextInAllPages
15-
{
16-
public static void main(String[] args) throws Exception
17-
{
18-
// The path to the documents directory.
19-
String dataDir = "src/programmersguide/workingwithasposepdf/workingwithtext/replacetextinallpages/data/";
20-
21-
// Open document
22-
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(dataDir+ "input.pdf");
23-
24-
// Create TextAbsorber object to find all instances of the input search phrase
25-
com.aspose.pdf.TextFragmentAbsorber textFragmentAbsorber = new com.aspose.pdf.TextFragmentAbsorber("sample");
26-
27-
// Accept the absorber for first page of document
28-
pdfDocument.getPages().accept(textFragmentAbsorber);
29-
30-
// Get the extracted text fragments into collection
31-
com.aspose.pdf.TextFragmentCollection textFragmentCollection = textFragmentAbsorber.getTextFragments();
32-
33-
// Loop through the fragments
34-
for(com.aspose.pdf.TextFragment textFragment : (Iterable<com.aspose.pdf.TextFragment>)textFragmentCollection)
35-
{
36-
// Update text and other properties
37-
textFragment.setText("New Pharase");
38-
textFragment.getTextState().setFont(com.aspose.pdf.FontRepository.findFont("Verdana"));
39-
textFragment.getTextState().setFontSize(22);
40-
textFragment.getTextState().setForegroundColor(com.aspose.pdf.Color.getBlue());
41-
textFragment.getTextState().setBackgroundColor(com.aspose.pdf.Color.getGray());
42-
}
43-
// Save the updated PDF file
44-
pdfDocument.save(dataDir+ "output.pdf");
45-
46-
}
47-
}
48-
49-
50-
51-
1+
/*
2+
* Copyright 2001-2013 Aspose Pty Ltd. All Rights Reserved.
3+
*
4+
* This file is part of Aspose.Pdf. The source code in this file
5+
* is only intended as a supplement to the documentation, and is provided
6+
* "as is", without warranty of any kind, either expressed or implied.
7+
*/
8+
9+
package programmersguide.workingwithasposepdf.workingwithtext.replacetextallpages.java;
10+
11+
import com.aspose.pdf.*;
12+
13+
14+
public class ReplaceTextAllPages
15+
{
16+
public static void main(String[] args) throws Exception
17+
{
18+
// The path to the documents directory.
19+
String dataDir = "src/programmersguide/workingwithasposepdf/workingwithtext/replacetextallpages/data/";
20+
21+
// Open document
22+
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(dataDir+ "input.pdf");
23+
24+
// Create TextAbsorber object to find all instances of the input search phrase
25+
com.aspose.pdf.TextFragmentAbsorber textFragmentAbsorber = new com.aspose.pdf.TextFragmentAbsorber("sample");
26+
27+
// Accept the absorber for first page of document
28+
pdfDocument.getPages().accept(textFragmentAbsorber);
29+
30+
// Get the extracted text fragments into collection
31+
com.aspose.pdf.TextFragmentCollection textFragmentCollection = textFragmentAbsorber.getTextFragments();
32+
33+
// Loop through the fragments
34+
for(com.aspose.pdf.TextFragment textFragment : (Iterable<com.aspose.pdf.TextFragment>)textFragmentCollection)
35+
{
36+
// Update text and other properties
37+
textFragment.setText("New Phrase");
38+
textFragment.getTextState().setFont(com.aspose.pdf.FontRepository.findFont("Verdana"));
39+
textFragment.getTextState().setFontSize(22);
40+
textFragment.getTextState().setForegroundColor(com.aspose.pdf.Color.getBlue());
41+
textFragment.getTextState().setBackgroundColor(com.aspose.pdf.Color.getGray());
42+
}
43+
// Save the updated PDF file
44+
pdfDocument.save(dataDir+ "output.pdf");
45+
46+
}
47+
}
48+
49+
50+
51+

0 commit comments

Comments
 (0)