We help IT Professionals succeed at work.

c#, pdf

ITsolutionWizard
on
124 Views
Last Modified: 2019-01-28
I have below codes working fine.
but instead of drop the image into the fixed location (  image.SetAbsolutePosition(100, 100);)

Is it possible to do the look up e.g. if the text called 'signature' is shown on the pdf, then drop the image there on the right side of the 'signature' text?
Or if there is any textbox field called 'signature', drop the image next to it.

Is it possible?

0c8f5c99-4ff8-4863-bb62-3af10ad394a8.pdf
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;

class Program
{
    static void Main(string[] args)
    {
        using (Stream inputPdfStream = new FileStream("input.pdf", FileMode.Open, FileAccess.Read, FileShare.Read))
        using (Stream inputImageStream = new FileStream("some_image.jpg", FileMode.Open, FileAccess.Read, FileShare.Read))
        using (Stream outputPdfStream = new FileStream("result.pdf", FileMode.Create, FileAccess.Write, FileShare.None))
        {
            var reader = new PdfReader(inputPdfStream);
            var stamper = new PdfStamper(reader, outputPdfStream);
            var pdfContentByte = stamper.GetOverContent(1);

            Image image = Image.GetInstance(inputImageStream);
            image.SetAbsolutePosition(100, 100);
            pdfContentByte.AddImage(image);
            stamper.Close();
        }
    }
}

Open in new window

Comment
Watch Question

Author

Commented:
any helps?

Author

Commented:
any helps?

Author

Commented:
any helps?
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
i import pdf shape library, and run your codes. it is not working at al..
CERTIFIED EXPERT

Commented:
need more info as that function is from an active app.

is it returning 0,0,0,0  as rectangle, as that is the flag for not finding the formfield.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.