Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Replace text in pdf file using itextshape in c#

Posted on 2016-07-26
7
Medium Priority
?
1,548 Views
Last Modified: 2016-07-28
Hi Experts,


Am using the below code for replace image and text on pdf, its is good working on the image replace part, but i dont know the how can write the text replace in same code.

private void AddAnImage()
    {
        string qrfile = qrcode();

        using (var inputPdfStream = new FileStream(Server.MapPath("PDF/input.pdf"), FileMode.Open))
        using (var inputImageStream = new FileStream(qrfile, FileMode.Open))
        using (var outputPdfStream = new FileStream(Server.MapPath("PDF/output.pdf"), FileMode.Create))
        {
            PdfReader reader = new PdfReader(inputPdfStream);
            PdfStamper stamper = new PdfStamper(reader, outputPdfStream);
            PdfContentByte pdfContentByte = stamper.GetOverContent(1);
            var image = iTextSharp.text.Image.GetInstance(inputImageStream);
            image.SetAbsolutePosition(50, 75);
            pdfContentByte.AddImage(image);
            PdfContentByte canvas = stamper.GetOverContent(2);
            ColumnText.ShowTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(DateTime.Now.ToShortDateString()), 0, 0, 0);
            stamper.Close();
        }

    }

Open in new window


Thanks in Advance Experts
0
Comment
Question by:karthik80c
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 7

Expert Comment

by:Jonathan Kelly
ID: 41729251
Hi,

I have worked with iText with vb previously and I used code similar to below to build up pdf files on the fly.

Dim doc As Document = New Document
Dim txt_JourneyLabel As New Chunk()

txt_JourneyLabel = New Chunk("SOME TEXT HERE", font_courier)
doc.Add(New Paragraph(txt_JourneyLabel))

This may not be the most efficient piece of code ever written but it does work.

Rgds,
Jonathan
0
 

Author Comment

by:karthik80c
ID: 41729285
Hi Jonathan

i dont think the code posted is to search and replace the Text . Can u please post again for this criteria to match a string and replace them in pdf
0
 
LVL 7

Expert Comment

by:Jonathan Kelly
ID: 41729297
You want to execute a text search and replace on the pdf  ?
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

Author Comment

by:karthik80c
ID: 41729401
yes
0
 
LVL 7

Accepted Solution

by:
Jonathan Kelly earned 2000 total points
ID: 41729803
After a fair bit of googling I found this

http://www.vbforums.com/showthread.php?681178-RESOLVED-quot-replace-quot-Words-in-PDF-file-using-iTextSharp

The idea (I think) is to
1. Read the pdf file text.
2. Locate the search word x,y coordinates
3. Create a solid block with same color as background and place at the above coordinates
4. Create new text at the coordinates and save as new pdf file.
0
 

Author Comment

by:karthik80c
ID: 41730642
thank you for your suggestion.i will try this.
0
 

Author Closing Comment

by:karthik80c
ID: 41732459
Thanks Exactly what we want . Thanks Jonathan
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PaperPort is a popular document imaging/management product from Nuance Communications (http://www.nuance.com/). It is in widespread use by both individuals (http://www.nuance.com/for-individuals/by-product/paperport/index.htm) and businesses (http:/…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question