Posted by a ceTe Software moderator
Hello,
We looked into your requirements further. You can place a hidden form field (TextField) in the PDF and then dynamically access this using full name and can get its X, Y, width and height values using our DynamicPDF Merger API. You can refer to the documentation on acroform fields
here. You can set these retrieved values of the hidden form field to the image page element and add it to PDF page.
You will need to use the PdfDocument class members to get the positions and dimensions of the hidden form field in the existing PDF. Please refer to the documentation on PdfDocument class members
here. Please note that it is not possible to replace the existing image with other using our DynamicPDF API. Below is the sample code to add hidden form field and save the PDF to disk then open it using Merger product API features to add the image in the position of hidden field.
Sample code to create PDF by adding hidden field.
Document document = new Document();
Page page = new Page();
document.Pages.Add(page);
ceTe.DynamicPDF.PageElements.Forms.TextField textFieldObj = new ceTe.DynamicPDF.PageElements.Forms.TextField("txt_name", 100, 100, 200, 200);
textFieldObj.Visible = false;
page.Elements.Add(textFieldObj);
//Save the document.
document.Draw(@"C:\Temp\MyDocument.pdf");
Sample code for opening the PDF to add image in the position of hidden field.
PdfDocument pdf = new PdfDocument(@"C:\Temp\MyDocument.pdf");
MergeDocument mergeDocument = new MergeDocument(pdf);
//Get the positions and dimensions of the existing form fied by accessing it using full name.
int pagenumber = pdf.Form.Fields["txt_name"].GetOriginalPageNumber();
float x = pdf.Form.Fields["txt_name"].GetX(mergeDocument.Pages[pagenumber-1]);
float y = pdf.Form.Fields["txt_name"].GetY(mergeDocument.Pages[pagenumber - 1]);
float width = pdf.Form.Fields["txt_name"].Width;
float height = pdf.Form.Fields["txt_name"].Height;
//Get the image data
ImageData imageData = ImageData.GetImage(@"Path for the image");
//Create Image object using imageData and setting the positions and dimensions.
Image image = new Image(imageData, x, y);
image.Width = width;
image.Height = height;
mergeDocument.Pages[pagenumber - 1].Elements.Add(image);
mergeDocument.Draw(@"C:\Temp\MyNewDocument.pdf");
Thanks,
ceTe Software Support Team.