Is is possible to add images programmatically (not to a specific x,y position but to a specific repository container field i.e an imagefield).
Adding Images
Re: Adding Images
Support · Jun 5, 2006Hello,
There is no way to place an actual image inside of a form field. Form fields can only contain text. However you can place any page element (including images) at the exact location of any form field that exists on the page using our “PositionPageElement” method off the PdfFormField class which belongs to ceTe.DynamicPDF.Merger.Forms namespace. There is some code snippet using this method on our Support Forums
.
So essentially you would use the form field as a container where your image will go.
Thanks,
ceTe Software Support Team
Re: Adding Images
Forum member · Jun 5, 2006A little confused as to how to do this. Do you have a simple example using VB.NET?
Re: Adding Images
Support · Jun 5, 2006Hello,
Following is the sample code snippet in VB.NET showing use of PositionPageElement method:
Dim MyPdfDocument As PdfDocument = New PdfDocument("C:\Temp\Test.pdf")
Dim MyDocument As MergeDocument = New MergeDocument(MyPdfDocument, New MergeOptions(True))
Dim MyPage As ceTe.DynamicPDF.Page = MyDocument.Pages(0)
Dim img As Image = New Image(MyImageFile, 0, 0)
MyPage.Elements.Add(img)
MyPdfDocument.Form.Fields("imageField").PositionPageElement(img, MyPage)
MyDocument.DrawToWeb("MergePDFs.pdf")
Thanks,
ceTe Software Support Team
Re: Adding Images
Forum member · Jun 6, 2006Thats great thank you. Can you modify this to take the x,y coordinates from a text box.
Re: Adding Images
Support · Jun 6, 2006Hello,
In order to take the X and Y co-ordinates from the textbox you can use the GetX() and GetY() methods off the PdfFormField class. Following is the sample coed block:
Dim fltX As Single = MyPdfDocument.Form.Fields("imageField").GetX(MyPage)
Dim fltY As Single = MyPdfDocument.Form.Fields("imageField").GetY(MyPage)
Dim img As Image = New Image(MyImageFile, fltX, fltY)
Thanks,
ceTe Software Support Team
Re: Adding Images
Forum member · Jun 7, 2006I am merging a pdf using MergeDocument as Follows:-
Dim mdTemplate As MergeDocument = New MergeDocument(strTemplatePDFFile, New MergeOptions(True))
For Each field As ceTe.DynamicPDF.Forms.TextField In mdTemplate.Form.GetTextFields
select case Field.MappingName
case "ImageField"
' This is text field in the template
end select
Next
How can your code be used in this example - TYVM.
Re: Adding Images
Support · Jun 7, 2006Hello,
In order to place the image on top of the text field, you will have to merge the PDF using the PdfDocument class and then use the overloaded MergeDocument constructor that takes PdfDocument object. Then you will have to get the X and Y co-ordinates of the field using the GetX() and GetY() methods off the PdfFormField class which belongs to ceTe.DynamicPDF.Merger.Forms namespace.
You can place any page element (in your case image) at the exact location of any form field that exists on the page using our “PositionPageElement” method off the PdfFormField class which belongs to ceTe.DynamicPDF.Merger.Forms namespace.
Thanks,
ceTe Software Support Team
Re: Adding Images
Forum member · Jun 7, 2006Please excuse my ignorance but could you be more specific with a
vb.net example. kindest regards.
Re: Adding Images
Support · Jun 7, 2006Hello,
The VB.NET code was posted few threads before. I have combined the two code blocks above into one example as below:
Dim MyPdfDocument As PdfDocument = New PdfDocument("C:\Temp\Test.pdf")
Dim MyDocument As MergeDocument = New MergeDocument(MyPdfDocument)
Dim MyPage As ceTe.DynamicPDF.Page = MyDocument.Pages(0)
Dim fltX As Single = MyPdfDocument.Form.Fields("imageField").GetX(MyPage)
Dim fltY As Single = MyPdfDocument.Form.Fields("imageField").GetY(MyPage)
Dim img As Image = New Image(MyImageFile, fltX, fltY)
MyPage.Elements.Add(img)
MyDocument.DrawToWeb("MergePDFs.pdf")
Thanks,
ceTe Software Support Team
Re: Adding Images
Forum member · Jun 7, 2006The line
Dim fltX As Single = MyPdfDocument.Form.Fields("ImageField").GetX(MyPage) gives me an error. I have a text field defined in my pdf called ImageField.
I have emailed the pdf to support@cete.com
kindest regards as always.
Re: Adding Images
Forum member · Jun 7, 2006Here is the code aswell (I think we are almost there after this issue).
Thanks as always.
Dim MyPdfDocument As PdfDocument = New PdfDocument ("C:\Test\Test.pdf")
Dim mOption As MergeOptions = New MergeOptions(True)
Dim mdTemplate As MergeDocument = New MergeDocument(MyPdfDocument, mOption)
mOption.FormFields = False
For Each field As ceTe.DynamicPDF.Forms.TextField In mdTemplate.Form.GetTextFields
if field.mappingname = "ImageField" then
' Inserted and amended your code example as follows
Dim MyPage As ceTe.DynamicPDF.Page = mdTemplate.Pages(0)
' This line errors with a System.NullReferenceException
Dim fltX As Single = MyPdfDocument.Form.Fields("ImageField").GetX(MyPage)
Dim fltY As Single = MyPdfDocument.Form.Fields("ImageField").GetY(MyPage)
Dim img As Image = New Image("c:\test\Maxim.gif", fltX, fltY)
MyPage.Elements.Add(img)
end if
Next
Re: Adding Images
Support · Jun 7, 2006Hello,
The reason you are getting an error is because you are not using the FullName of the form field.
Please refer to the FormFieldReader example that is included with the product download and use your PDF as template to find the full names of the fields.
In your case "DataSet1[0].P1[0].ImageField[0]" is the full name of the field you are trying to fill with image and not "ImageField".
Dim fltX As Single =
MyPdfDocument.Form.Fields("DataSet1[0].P1[0].ImageField[0]").GetX(MyPage)
A form field's name could be the concatenation of its parents name like Parent2.Parent1.FormFieldName" instead of "FormFieldName" as might be expected. When you are referencing a form field make sure that you have provided the entire name for that form field.
Thanks,
ceTe Software Support Team
Re: Adding Images
Forum member · Jun 7, 2006Using fullname works great. Thank you very much.