Hello,
we want to copy (recognized OCR) text from one PDF to another.
This example source code works but is very very slow (the textBuilder.AppendText function takes about 3 minutes for one page of text)
Why is the method so slow? Are there any faster methods to copy text from one PDF to another?
public void CopyOCRx(string file_ocr, string file_non_ocr)
{
using (Aspose.Pdf.Document asposeDocTarget = new Aspose.Pdf.Document(file_non_ocr))
{
Aspose.Pdf.Page page_new = asposeDocTarget.Pages[1];
using (Aspose.Pdf.Document asposeDoc = new Aspose.Pdf.Document(file_ocr))
{
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"[\S]+");
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(regex);
Aspose.Pdf.Page page = asposeDoc.Pages[1];
page.Accept(textFragmentAbsorber);
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
TextBuilder textBuilder = new TextBuilder(page_new);
List<TextFragment> list = new List<TextFragment>();
foreach (TextFragment textFragment in textFragmentCollection)
{
list.Add(textFragment);
}
textBuilder.AppendText(list);
}
asposeDocTarget.Save("file_ocr_new");
}