![insert text on image insert text on image](https://static.javatpoint.com/ms/powerpoint/images/how-to-insert-a-text-box1.png)
![insert text on image insert text on image](https://i.ytimg.com/vi/tMNr2pb7T4U/maxresdefault.jpg)
#INSERT TEXT ON IMAGE PDF#
I manage to create a PDF from a template and add some text on top of it before I try to add the image in.ġ // we create a reader for a certain document, Certificate.pdf serves as the template 2 PdfReader readerCertificate = new PdfReader( "Certificate.pdf") ģ 4 // we retrieve the size of the first page 5 psize = readerCertificate.GetPageSize(1) Ĩ 9 // step 1: creation of a document-object 10 Document document = new Document(psize, 50, 50, 50, 50) ġ1 // step 2: we create a writer that listens to the document 12 PdfWriter writer = PdfWriter.GetInstance(document, new FileStream( "PublishedCertificate.pdf", FileMode.Create)) ġ3 // step 3: we open the document 14 document.Open() ġ5 // step 4: we add content=I add the template in the New document 16 PdfContentByte cb = writer.DirectContent ġ8 PdfImportedPage page1 = writer.GetImportedPage(readerCertificate, 1) Ģ0 21 //add content above the template= I add some text on the new PDF 22 bf = .CreateFont(.COURIER, .CP1252, .NOT_EMBEDDED) cb.BeginText() Ģ4 25 AddTextInPDF(cb, 5.1, 8, SpecMaxRsd.ToString()) Ģ6 AddTextInPDF(cb, 6, 8.6, SpecMaxDev.ToString()) ģ0 31 //add chart=here comes the troubles 32 33 PdfReader reader = new PdfReader( "PublishedCertificate.pdf") ģ4 PdfStamper stamper = new PdfStamper(reader, new FileStream( "withchart.pdf", FileMode.Create)) ģ5 AcroFields fields = stamper.AcroFields ģ6 //set images 37 string chartLoc = string.Empty ģ8 chartImg = ( "zedgraph.png") Ĥ0 41 PdfContentByte cB = new PdfContentByte(stamper.Writer) I am trying to add a chart from a png image file which I know exists and put it in an existing PDF, all in the same folder. Hey Guys I am going to give more details about the issue: This is the same error message I would get before.Īll the examples I found were creating a new document but none from a template. Kept on giving me the error "object not set to a reference" on the addImage. I need to insert the image into the document that is created from the template.ĬhartLoc = Server.MapPath( "reports/" + chartNames.ToString() +īut I couldn't get it to work either. I haven't a table as this isn't a new document but a template that I use. That would work if I was creating a table into a new document. Do you mean that you get no errors when you create the document and the problem occurs when you have to write on a completed doc? what type of error do you get? logo = (Server.MapPath("/img/logo1.jpg")) The images are all created before the PDF is so they will be referenced by name. Create)) AcroFields fields = stamper.AcroFields PdfReader reader = new PdfReader (fileNameFrom) PdfStamper stamper = new PdfStamper (reader,įileMode. Can I use any of the below code to add it?
#INSERT TEXT ON IMAGE HOW TO#
The problem is that I can't find how to insert the image without it having to be a new document. I need to insert an image into the PDF file at a specific point. Now I have an additional thing I need to do.
#INSERT TEXT ON IMAGE CODE#
I have a PDF template file that I open and fill from code behind. Found many different examples but nothing that has lead me in the right direction. I've been browsing the net for almost 3 hrs now without a clue.