Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Fri Jan 15, 2016 5:54 pm

I have a fillable PDF created in lifecycle designer with a few image fields on it. when I run the code the image is picked up as a PdfButtonWidgetFieldWidget, which is fine, but I can't set the image on it... I looked through the object hierarchy but could not see where to set the image on the button...

Also, I cannot use the replaceimage() method because it doesn't seem to work???

a PdfSignatureFieldWidget would work as well but again I can't set an image to that either.

I have the pdf attached.

I don't have a license yet but will in a few days if that makes any difference...

*** here's the part of the code where I get the image field object.



If TypeOf field Is Spire.Pdf.Widget.PdfButtonWidgetFieldWidget Then
' get the button/imageField
Dim button As Spire.Pdf.Widget.PdfButtonWidgetFieldWidget = CType (field,Spire.Pdf.Widget.PdfButtonWidgetFieldWidget)

If (button.Name = "TimeSheet[0].#subform[0].imgEmp[0]") Then

' get the button styles
Dim styled As Spire.Pdf.Widget.PdfStyledFieldWidget = CType(field, Spire.Pdf.Widget.PdfStyledFieldWidget)

'the buttons image dementions
Dim imgDimensions As System.Drawing.RectangleF = styled.Bounds

'employeeSignature from the database
Dim sig As Byte() = Convert.FromBase64String(result.employeeSignature)


' *** the work around - this doesn't set the image to the button, just draw it on the page where it should be.

Dim image As Spire.Pdf.Graphics.PdfImage
Try
image = Spire.Pdf.Graphics.PdfImage.FromImage(byteArrayToImage(sig))
Catch ex As Exception
End Try


Dim pageBase As Spire.Pdf.PdfPageBase = doc.Pages(0)

If Not image Is Nothing Then
pageBase.Canvas.DrawImage(image, imgDimensions)
End If


End If
End If



Private Function byteArrayToImage(ByVal imageBytes As Byte()) As System.Drawing.Image
Dim image As Bitmap = Nothing
Try
Using imageStream As MemoryStream = New MemoryStream(imageBytes, False)
image = New Bitmap(imageStream)
End Using
Catch ex As Exception

End Try

Return image

End Function

justinroberts
 
Posts: 2
Joined: Thu Jan 14, 2016 8:26 pm

Mon Jan 18, 2016 6:39 am

Hi,

Thanks for your posting and using our Spire.Pdf.
Please try the following solution.
Code: Select all
   PdfDocument doc = new PdfDocument();
            doc.LoadFromFile("..\\..\\Input\\FillablePDF.pdf");
            PdfFormWidget formWidget = doc.Form as PdfFormWidget;
            List<XfaField> fields = formWidget.XFAForm.XfaFields;
            foreach (XfaField field in fields)
            {
                if (field.FieldType == "imageEdit")
                {
                    XfaImageField imageField = field as XfaImageField;
                    if (field.Name == "TimeSheet[0].ImageField1[1]")
                    {
                        imageField.Image = Image.FromFile("test.png");
                    }
               }
           }
           doc.SaveToFile("result.pdf");


Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3043
Joined: Wed Jun 27, 2012 8:50 am

Mon Jan 18, 2016 7:21 pm

awesome, that worked... my free test version didn't come with the latest libraries but I was able to download them off the spire site.

Thanks Amy,
Justin

justinroberts
 
Posts: 2
Joined: Thu Jan 14, 2016 8:26 pm

Tue Jan 19, 2016 1:27 am

Hi Justin,

Thanks for your feedback.
I am glad that your issue has been resolved.
Welcome to write to us again for further problems.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3043
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.PDF

cron