Thanks for your feedback.
In order to copy text fragments with their styles, you need to use
TextFragmentAbsorber instead of
TextFragmentAbsorber will extract text along with their styles and stores it in its
TextFragments Collection. You can then add text in new PDF document while iterating through that collection. Please check following code snippet, where we have created a new PDF document where one of the source PDFs, had text in bold style.
Document doc1 = new Document(dataDir + "Firstdoc.pdf");
Document doc2 = new Document(dataDir + "SecondDoc.pdf");
TextFragmentAbsorber textAbsorber = new TextFragmentAbsorber();
List<TextFragment> textFragments = new List<TextFragment>();
foreach(TextFragment tf in textAbsorber.TextFragments)
TextAbsorber textAbsorber2 = new TextAbsorber();
Document newDoc = new Document();
Page page = newDoc.Pages.Add();
foreach (TextFragment tf in textFragments)
newDoc.Save(dataDir + "ThirdDocument.pdf");
For your kind reference, input/output documents are also attached:
ThirdDocument.pdf (2.3 KB)
Firstdoc.pdf (1.9 KB)
SecondDoc.pdf (32.6 KB)
However, please note that TextFragmentAbsorber extracts text from source PDF, in same way which was used to add text inside it. In case of any further assistance, please feel free to let us know.