TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ikram Shams
NA
82
0
TextFragmentCollection of Aspose.Pdf is taking too much time
Feb 4 2020 1:07 PM
I am using Aspose.Pdf to find and replace text in a Pdf File. If a Pdf File has 10 words to find and replace then it is taking 2 to 3 minute. But if a Pdf File has 80 words(10 words are repeating 8 times on the File) then it is taking 20 to 25 minutes in Finding and replacing text on a Pdf File. I am using the below code. Please suggest me what the changes i will make in my code that it will take minimum time.
private
void
PrintPdfDocument(
object
FileNameSource, DataTable dt)
{
object
fileNameSource = FileNameSource;
object
fileName = System.IO.Path.GetDirectoryName(System.IO.Path.GetTempPath()) +
"\\" + DateTime.Now.Ticks.ToString() + "
.pdf";
File.Copy(fileNameSource.ToString(), fileName.ToString(),
false
);
pdfDocument =
new
Document(FileNameSource.ToString());
try
{
TextFragmentAbsorber textFragmentAbsorber =
new
TextFragmentAbsorber(
"@color_arabic"
);
pdfDocument.Pages.Accept(textFragmentAbsorber);
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
foreach
(TextFragment textFragment
in
textFragmentCollection)
{
textFragment.Text = txtColorArabic.Text.ToString().Trim();
}
textFragmentAbsorber =
new
TextFragmentAbsorber(
"@color_english"
);
pdfDocument.Pages.Accept(textFragmentAbsorber);
textFragmentCollection = textFragmentAbsorber.TextFragments;
foreach
(TextFragment textFragment
in
textFragmentCollection)
{
textFragment.Text = txtColorEnglish.Text.Trim();
}
textFragmentAbsorber =
new
TextFragmentAbsorber(
"@unit_arabic"
);
pdfDocument.Pages.Accept(textFragmentAbsorber);
textFragmentCollection = textFragmentAbsorber.TextFragments;
foreach
(TextFragment textFragment
in
textFragmentCollection)
{
textFragment.Text = ConvertNumeralsToArabic(txt_ArabicUnit.Text.ToString());
}
textFragmentAbsorber =
new
TextFragmentAbsorber(
"@unit_english"
);
pdfDocument.Pages.Accept(textFragmentAbsorber);
textFragmentCollection = textFragmentAbsorber.TextFragments;
foreach
(TextFragment textFragment
in
textFragmentCollection)
{
textFragment.Text = txtUnitEnglish.Text.ToString().Trim();
}
textFragmentAbsorber =
new
TextFragmentAbsorber(
"@mfg_arabic"
);
pdfDocument.Pages.Accept(textFragmentAbsorber);
textFragmentCollection = textFragmentAbsorber.TextFragments;
foreach
(TextFragment textFragment
in
textFragmentCollection)
{
textFragment.Text = ConvertNumeralsToArabic(dt.Rows[0][
"ProdDate"
].ToString());
}
textFragmentAbsorber =
new
TextFragmentAbsorber(
"@mfg_english"
);
pdfDocument.Pages.Accept(textFragmentAbsorber);
textFragmentCollection = textFragmentAbsorber.TextFragments;
foreach
(TextFragment textFragment
in
textFragmentCollection)
{
textFragment.Text = dt.Rows[0][
"ProdDate"
].ToString().Trim();
}
textFragmentAbsorber =
new
TextFragmentAbsorber(
"@exp_arabic"
);
pdfDocument.Pages.Accept(textFragmentAbsorber);
textFragmentCollection = textFragmentAbsorber.TextFragments;
string
expArabic = dt.Rows[0][
"ExpDate"
].ToString();
foreach
(TextFragment textFragment
in
textFragmentCollection)
{
textFragment.Text = ConvertNumeralsToArabic(dt.Rows[0][
"ExpDate"
].ToString());
}
textFragmentAbsorber =
new
TextFragmentAbsorber(
"@exp_english"
);
pdfDocument.Pages.Accept(textFragmentAbsorber);
textFragmentCollection = textFragmentAbsorber.TextFragments;
foreach
(TextFragment textFragment
in
textFragmentCollection)
{
textFragment.Text = dt.Rows[0][
"ExpDate"
].ToString().Trim();
}
if
((dt.Rows[0][
"InventBatchId"
].ToString().Trim().Contains(
"B"
)) &&
(dt.Rows[0][
"InventBatchId"
].ToString().Trim().Substring(0, 1) ==
"B"
))
{
textFragmentAbsorber =
new
TextFragmentAbsorber(
"@bch_arabic"
);
pdfDocument.Pages.Accept(textFragmentAbsorber);
textFragmentCollection = textFragmentAbsorber.TextFragments;
foreach
(TextFragment textFragment
in
textFragmentCollection)
{
textFragment.Text = ConvertNumeralsToArabic(dt.Rows[0][
"InventBatchId"
].ToString().Trim().Substring(1).Replace(
"-"
,
""
));
}
textFragmentAbsorber =
new
TextFragmentAbsorber(
"@bch_english"
);
pdfDocument.Pages.Accept(textFragmentAbsorber);
textFragmentCollection = textFragmentAbsorber.TextFragments;
foreach
(TextFragment textFragment
in
textFragmentCollection)
{
textFragment.Text = dt.Rows[0][
"InventBatchId"
].ToString().Trim().Substring(1).Replace(
"-"
,
""
);
}
}
else
{
textFragmentAbsorber =
new
TextFragmentAbsorber(
"@bch_arabic"
);
pdfDocument.Pages.Accept(textFragmentAbsorber);
textFragmentCollection = textFragmentAbsorber.TextFragments;
foreach
(TextFragment textFragment
in
textFragmentCollection)
{
textFragment.Text = ConvertNumeralsToArabic(dt.Rows[0][
"InventBatchId"
].ToString().Trim());
}
textFragmentAbsorber =
new
TextFragmentAbsorber(
"@bch_english"
);
pdfDocument.Pages.Accept(textFragmentAbsorber);
textFragmentCollection = textFragmentAbsorber.TextFragments;
foreach
(TextFragment textFragment
in
textFragmentCollection)
{
textFragment.Text = dt.Rows[0][
"InventBatchId"
].ToString().Trim();
}
}
pdfDocument.Save(@fileName.ToString());
}
Reply
Answers (
2
)
Can ImageMagick edit PDF
Passing ID and Name of Selected Item from Combo Box