How do you create an image in the PDF document, like a TextBox but just for images, and then through the API in .Net move/attach an image to it. I do not want to add an image element to the page, I want the image "element" to be defined in the PDF document already.
Programmatically attach an image to an PDF image object
Re: Programmatically attach an image to an PDF image object
Support · May 2, 2006The way that you could accomplish this would be to define a Text Field on the document before the merge (in the exact location that you want to add the image to the page). Then at runtime you can use the "PositionPageElement" method to place you Image PageElement at the location that you had previously defined (make sure that the MergeOptions.FormFields is set to "false" when doing the merge or append).
Keep in mind however that if you place any images on the PDF in the manner defined above, and you have other form fields to fill out, that you will need to use the "CreateLabel" to fill them out. In other words using the "PositionPageElement" method will also require the use of the "CreateLabel" method for any other form filling.
Thanks,
ceTe Software Support Team
Re: Programmatically attach an image to an PDF image object
Forum member · May 3, 2006Where can I find the "PositionPageElement" method; i.e. namespace, class?
Re: Programmatically attach an image to an PDF image object
Support · May 3, 2006Hello,
The PositionPageElement method exists in PdfFormField class which belongs to ceTe.DynamicPDF.Merger.Forms namespace.
Thanks,
ceTe Software Support Team
Re: Programmatically attach an image to an PDF image object
Forum member · May 3, 2006Please send me example code on how to cuse this class as it seems to be an abstract class that cannot be instantiated.
Re: Programmatically attach an image to an PDF image object
Support · May 3, 2006Sure, in our online Help Documentation is a section called "Replace Acro Form Fields with Text". It can be found here
. You will find both C# and VB code for using the "CreateLabel" method.
The "CreateLabel" method and the "PositionPageElement" method are used very similarly on the PdfFormField class.
Thanks,
ceTe Software Support Team
Re: Programmatically attach an image to an PDF image object
Forum member · May 4, 2006The "PositionPageElement" does not seem to work. I save an image to the C drive and then pick it up and place it on the textbox's coordinates (calculated with GetX and GetY), see my code:
ctMerger.MergeOptions mOptions = new ctMerger.MergeOptions(true);
ct.Merger.PdfDocument mPdfpagex = new ceTe.DynamicPDF.Merger.PdfDocument(Server.MapPath("Files\\HORCQE Data Form Page1.pdf"));
ct.Merger.PdfDocument mPdfpage2 = new ceTe.DynamicPDF.Merger.PdfDocument(Server.MapPath("Files\\HORCQE Data Form Page2.pdf"));
ct.Merger.PdfDocument mPdfpage3 = new ceTe.DynamicPDF.Merger.PdfDocument(Server.MapPath("Files\\HORCQE Data Form Page3.pdf"));
ct.Merger.PdfDocument mPdfpage4 = new ceTe.DynamicPDF.Merger.PdfDocument(Server.MapPath("Files\\HORCQE Data Form Page4.pdf"));
ct.Merger.PdfDocument mPdfpage5 = new ceTe.DynamicPDF.Merger.PdfDocument(Server.MapPath("Files\\HORCQE Data Form Page5.pdf"));
ct.Merger.PdfDocument mPdfpage6 = new ceTe.DynamicPDF.Merger.PdfDocument(Server.MapPath("Files\\HORCQE Data Form Page6.pdf"));
ceTe.DynamicPDF.Merger.MergeDocument mPdfdoc = new ceTe.DynamicPDF.Merger.MergeDocument(mPdfpagex,mOptions);
mPdfdoc.Append(mPdfpage2, mOptions);
mPdfdoc.Append(mPdfpage4, mOptions);
mPdfdoc.Append(mPdfpage6, mOptions);
mOptions.FormFields = false;
ceTe.DynamicPDF.Page pagex = mPdfdoc.Pages[0];
ceTe.DynamicPDF.Page page2 = mPdfdoc.Pages[1];
ceTe.DynamicPDF.Page page4 = mPdfdoc.Pages[2];
ceTe.DynamicPDF.Page page6 = mPdfdoc.Pages[3];
ceTe.DynamicPDF.Font myFont = ceTe.DynamicPDF.Font.Helvetica;
float fltX = mPdfpagex.Form.Fields["txtPostalBarcode"].GetX(pagex);
float fltY = mPdfpagex.Form.Fields["txtPostalBarcode"].GetY(pagex);
ct.PageElements.Image ctPostal = new ct.PageElements.Image(bcp.GetBarcodeImage(), fltX, fltY, 1);
mPdfpagex.Form.Fields["txtPostalBarcode"].PositionPageElement(ctPostal, pagex);
Re: Programmatically attach an image to an PDF image object
Forum member · May 4, 2006A slight deviation fro my ode I sent you in place of the bcp.GetBarcodeImage() method code line:
ct.PageElements.Image ctPostal = new ct.PageElements.Image(@"D:\DOTNET Applications\DynamicPdf\DynPDFTest\Files\Output\Test.jpg", 66, 197);
Re: Programmatically attach an image to an PDF image object
Support · May 4, 2006Hello,
The most likely reason you are not seeing the image is because you are not adding the image to the page. Try the modified code snippet below:
ct.PageElements.Image ctPostal = new ct.PageElements.Image(bcp.GetBarcodeImage(), 0, 0);
mPdfdoc.Pages[0].Elements.Add(ctPostal);
mPdfpagex.Form.Fields["txtPostalBarcode"].PositionPageElement(ctPostal, pagex);
Thanks,
ceTe Software Support Team
Re: Programmatically attach an image to an PDF image object
Forum member · May 4, 2006Thanks, this works now.