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
Rahul Khanna
NA
236
0
Find and Replace specific word in pdf.
Apr 5 2014 12:48 AM
Hi all,
I have written a C# console program to replace a specific word with new word in pdf.My program doing this but my new pdf does does not look like orginal pdf. My basic purpose to replace some words without changing the look and feel of the orginal pdf.Can u pls help me out regard this, your help is heartily appreciated.Here is my code:
static void Main(string[] args)
{
var editedText = ExtractTextFromPdf("@"C:\temp\MyPdf_Orginal.pdf"");
using (var fileStream = new FileStream(@"C:\temp\MyPdf_New.pdf", FileMode.Create, FileAccess.Write)
{
Document document = new Document(PageSize.A4, 25, 25, 30, 30);
PdfWriter writer = PdfWriter.GetInstance(document, fileStream);
document.Open();
document.Open();
document.Add(new Paragraph(editedText));
Close the document
document.Close();
writer.Close();
fileStream .Close();
}
}
public static string ExtractTextFromPdf(string path)
{
using (PdfReader reader = new PdfReader(path))
{
StringBuilder text = new StringBuilder();
for (int i = 1; i <= reader.NumberOfPages; i++)
{
text.Append(PdfTextExtractor.GetTextFromPage(reader, i));
text.Replace("Delhi", "Mumbai");
}
return text.ToString();
}
}
}
Any new approach is most welcome.
Reply
Answers (
0
)
how to print original duplicate triplicate in crystal report
Payment Gateway in mvc4