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.

Thu Jul 01, 2021 1:16 pm

Hello!

I'm having some trouble setting the image of an XfaImageField.

What I have so far is:
Code: Select all
                               
                        if (xfaField is XfaImageField){
                            XfaImageField xf = xfaField as XfaImageField;
                            if (xf.Name=="topmostSubform[0].Page1[0].ImgSignatur[0]"){
                            Image MyImage = Image.FromFile(@"C:\ASPdotNET_logo.jpg");
                            var msy = new MemoryStream();
                            MyImage.Save(msy, System.Drawing.Imaging.ImageFormat.Jpeg);
                            msy.Position = 0;
                            xf.Image = msy;
                       
                            }
                        }


I also found this (de url:ized but from here):
/forum/changing-the-image-on-a-button-t5794.html
which seems very similar, but somehow I keep getting "method not found" on the row where I try to set the image:
xf.Image = msy;

Any ideas on what I'm doing wrong?

Cheers!

/Eskil

eskillundgren
 
Posts: 3
Joined: Thu Jul 01, 2021 1:08 pm

Fri Jul 02, 2021 6:55 am

Hello Eskil,

Thanks for your inquiry.
Please note that only when you use the .NETStandard dlls, the type of the property "XfaImageField.Image" is Stream, otherwise the type should be Image.
If you are using our .NET Framework dlls or .NETCore dlls, please use the following code instead.
Code: Select all
                if (xfaField is XfaImageField)
                {
                    XfaImageField xf = xfaField as XfaImageField;
                    if (xf.Name == "topmostSubform[0].Page1[0].ImgSignatur[0]")
                    {
                        System.Drawing.Image MyImage = Image.FromFile(@"C:\ASPdotNET_logo.jpg");
                        xf.Image = MyImage;
                    }
                }


Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Fri Jul 02, 2021 8:07 am

Hello and thank you for your response!

The reason I'm using stream is that the xg.Image wants a stream, hard to know for which framework I'm on :-)

So if I do as per your suggestion I get an error in Visual Studio, the one where you get the squiggly red text and:
"Cannot implicitly convert type 'Syste.Drawing.Image' to 'System.IO.Stream'"

I use you NuGet Spire.PDF (7.6.15) and one solution might be to change that, since I don't have to use the NuGet package. Or?

Cheers!

/Eskil

eskillundgren
 
Posts: 3
Joined: Thu Jul 01, 2021 1:08 pm

Fri Jul 02, 2021 10:09 am

Hello Eskil,

Thanks for your feedback.
To help us investigate your issue more quickly and accurately, please provide your project which can reproduce your issue. You could send it to us ([email protected]) via email. Thanks in advance for your assistance.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Mon Jul 05, 2021 10:04 am

Hello Eskil,

Thanks for providing your project via email.
I provided you with my test project via email, please test it on your side to see if the issue occurs.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Mon Jul 05, 2021 2:00 pm

Hello again!

After reviewing the code, when simplified and not referencing other projects, everything worked as expected.

Following simplified code should do the job for anyone wishing to use a stream:

Code: Select all
                                     
if (xfaField is XfaImageField){
XfaImageField xf = xfaField as XfaImageField;
     if (xf.Name=="topmostSubform[0].Page1[0].ImgSignatur[0]"){
          Image MyImage = Image.FromFile(@"C:\ASPdotNET_logo.jpg");
          var msy = new MemoryStream();
          MyImage.Save(msy, System.Drawing.Imaging.ImageFormat.Jpeg);         
          msy.Position = 0;
          xf.Image = msy;
     }
}     


Cheers and thanks!

eskillundgren
 
Posts: 3
Joined: Thu Jul 01, 2021 1:08 pm

Tue Jul 06, 2021 1:22 am

Hello,

Thanks for your feedback and your sharing.
If you encounter any issues related to our products in the future, please feel free to contact us.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Return to Spire.PDF

cron