Sign UpSign Up   Sign InSign In Welcome Guest,
Live Chat Live Chat

How to Add image from URL to Slide?

Last post 07-10-2009, 10:43 AM by PittsburghSteelersFan. 13 replies.
Sort Posts: Previous Next
  •  05-09-2009, 2:26 PM 178827

    How to Add image from URL to Slide? .NET

    Hi, could you provide the steps required to add an image into a powerpoint, where the image resides at a url such http://www.<myurl>.com/test.jpg

    Is this possible?

    I know it's possible for your Aspose Words product, but i don't seem the same objects in slides.

     

     
  •  05-09-2009, 11:56 PM 178837 in reply to 178827

    Re: How to Add image from URL to Slide?

    Dear Michael,

     

    If I am not mistaken it is not possible in MS-PowerPoint and therefore also not possible in Aspose.Slides.


    Many Thanks and Kind Regards,

    Shakeel Faiz
    Support Developer
    Aspose Sialkot Team
    Contact Us
    Aspose - The .NET and Java Component Publisher

    Keep in touch! We're on Twitter and Facebook
     
  •  05-10-2009, 7:55 AM 178847 in reply to 178837

    Re: How to Add image from URL to Slide?

    You can add an image to Powerpoint with an external URL...it's very easy. Just open the powerpoint, and then choose to insert a picture. Then put in the URL, and choose "Insert as Link". It works fine.

    Maybe we'll need to use automation for this.
     
  •  05-11-2009, 8:35 AM 178976 in reply to 178847

    Re: How to Add image from URL to Slide?

    Attachment: Present (inaccessible)

    Dear Michael,

     

    Thanks for your help.

     

    There is a workaround to add a linked picture with external URL using Aspose.Slides feature namely Shape Serialization.

     

    The idea is to import a linked PictureFrame from a source presentation to a target presentation using serialization and change the link path.

     

    Please see the code below and also see the source.ppt and output.ppt generated by the code; which I have attached for your reference.

     

    When you will open the output.ppt, it will display the Aspose Logo retrieving it from internet as shown in code.

     

    C#

     

    //Source presentation to get the linked picture from

    Presentation srcPres = new Presentation("c:\\source.ppt");

     

    //Source slide with a single shape which is a linked pictureframe

    Slide srcSld = srcPres.GetSlideByPosition(1);

     

    //Serialize the pictureframe

    Shape shp = srcSld.Shapes[0];

    MemoryStream ms = new MemoryStream();

    shp.Serialize(ms);

     

    //Now once serialized, we can import into our target presentation

    //Create a target presentation

    Presentation target = new Presentation();

    Slide targetSld = target.GetSlideByPosition(1);

     

    //Import the serialized shape

    ms.Position = 0;

    targetSld.Shapes.Add(ms);

     

    //Access the shape as a pictureframe

    PictureFrame pf = targetSld.Shapes[0] as PictureFrame;

     

    //Change its link path

    pf.PictureFileName = "http://www.aspose.com/Images/aspose-logo.jpg";

     

    //Write the target presentation on disk.

    target.Write("c:\\output.ppt");

     


    Many Thanks and Kind Regards,

    Shakeel Faiz
    Support Developer
    Aspose Sialkot Team
    Contact Us
    Aspose - The .NET and Java Component Publisher

    Keep in touch! We're on Twitter and Facebook
     
  •  05-14-2009, 10:00 AM 179668 in reply to 178976

    Re: How to Add image from URL to Slide? .NET

    Thanks! This works great..however, the remaining issue is if the Target PPT is not a new powerpoint, but an existing one.

    so the target ppt is

    Presentation target = new Presentation(@"C:\temp\myown.ppt");

    When i try to run this, i get the following error

    Object reference not set to an instance of an object.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:

    Line 47:         pf.PictureFileName = "http://www.aspose.com/Images/aspose-logo.jpg";
    Line 49: 

    How can i fix this? thanks again for your help.

     
  •  05-14-2009, 10:05 AM 179670 in reply to 179668

    Re: How to Add image from URL to Slide?

    never mind...my stupid mistake...just needed to get the right indexer of the pictureframe.

    thanks again for your help.

     
  •  06-30-2009, 9:30 PM 186250 in reply to 179670

    Re: How to Add image from URL to Slide?

    Hi...could you provide this same code to add an image from a URL in VB? I tried several C-to-VB converters and they all kept coming up with errors. I tried to debug myself in VS2005, but couldn't get this to work...sorry, I'm sure it's something easy, but it's escaping me after a couple of hours...thanks VERY much...Have a great day! I REALLY appreciate it.

    Patrick.

     
  •  07-01-2009, 1:57 AM 186276 in reply to 186250

    Re: How to Add image from URL to Slide?

    Here is the code.

     

    VB.NET

    -----------------------------------

    'Source presentation to get the linked picture from

    Dim srcPres As Presentation = New Presentation("c:\test\source.ppt")

     

    'Source slide with a single shape which is a linked pictureframe

    Dim srcSld As Slide = srcPres.GetSlideByPosition(1)

     

    'Serialize the pictureframe

    Dim shp As Shape = srcSld.Shapes(0)

     

    Dim ms As MemoryStream = New MemoryStream()

    shp.Serialize(ms)

     

    'Now once serialized, we can import into our target presentation

    'Create a target presentation

    Dim target As Presentation = New Presentation()

    Dim targetSld As Slide = target.GetSlideByPosition(1)

     

    'Import the serialized shape

    ms.Position = 0

    targetSld.Shapes.Add(ms)

     

    'Access the shape as a pictureframe

    Dim pf As PictureFrame = CType(targetSld.Shapes(0), PictureFrame)

     

    'Change its link path

    pf.PictureFileName = "http:\\www.aspose.com/Images/aspose-logo.jpg"

     

    'Write the target presentation on disk.

    target.Write("c:\test\output.ppt")


    Many Thanks and Kind Regards,

    Shakeel Faiz
    Support Developer
    Aspose Sialkot Team
    Contact Us
    Aspose - The .NET and Java Component Publisher

    Keep in touch! We're on Twitter and Facebook
     
  •  07-01-2009, 3:57 AM 186296 in reply to 186276

    Re: How to Add image from URL to Slide?

    Can anyone please provide me the java code to add image to slide ?

     

    Thanks ,

    Sam

     
  •  07-08-2009, 1:07 PM 187588 in reply to 186276

    Re: How to Add image from URL to Slide?

    Attachment: Present (inaccessible)

    HELP...doesn't work no matter what I try...I finally cut and pasted your entire code into a brand new .aspx page...only changed filenames because no source.ppt was available...updated my aspose.slides.dll to 3.1.0...still no go...it throws NO error messages...here's my code and source.ppt that I used...Help...my boss needs this functionality by next Friday or I'm toast...thanks. P.

     

    Trace.IsEnabled = True

    Dim license As Aspose.Slides.License = New Aspose.Slides.License()

    'Set the license of Aspose.Slides to avoid the evaluation limitations

    license.SetLicense("aspose.total.lic")

    'Source presentation to get the linked picture from

    Dim srcPres As Presentation = New Presentation("C:\Inetpub\wwwroot\OSCARPub\OSCAR_PPT\source.ppt")

    'Source slide with a single shape which is a linked pictureframe

    Dim srcSld As Slide = srcPres.GetSlideByPosition(1)

    'Serialize the pictureframe

    Dim shp As Shape = srcSld.Shapes(0)

    Dim ms As System.IO.MemoryStream = New System.IO.MemoryStream()

    shp.Serialize(ms)

    'Now once serialized, we can import into our target presentation

    'Create a target presentation

    Dim target As Presentation = New Presentation()

    Dim targetSld As Slide = target.GetSlideByPosition(1)

    'Import the serialized shape

    ms.Position = 0

    targetSld.Shapes.Add(ms)

    'Access the shape as a pictureframe

    Dim pf As PictureFrame = CType(targetSld.Shapes(0), PictureFrame)

    'Change its link path

    pf.PictureFileName = "http:\\www.aspose.com\Images\aspose-logo.jpg"

    'Write the target presentation on disk.

    target.Write("C:\Inetpub\wwwroot\OSCARPub\OSCAR_PPT\output.ppt")

     

     

     
  •  07-08-2009, 9:29 PM 187631 in reply to 187588

    Re: How to Add image from URL to Slide?

    I forgot to mention that the output.ppt is the same as the source.ppt...

    I just can't get the PictureFileName to add either a local file (non memory stream), http: version, or stream...when I do a read of the PictureFileName it says that it is the same as the alternate_text

    I hope that helps...thanks for any help...P.

     
  •  07-09-2009, 2:46 PM 187820 in reply to 187631

    Re: How to Add image from URL to Slide?

    ANother update: I've tried manipulating the PictureFilePath at every point and nothing I do seems to make ANY difference to the output...and there are NO errors, but that property just doesn't seem to make ANY difference.

    Any thoughts or fixes? Thanks.

     
  •  07-09-2009, 9:46 PM 187859 in reply to 187820

    Re: How to Add image from URL to Slide?

    Hello,

     

    In my code, source & output ppt files are different,

     

    Does your source ppt file contains a linked image just like my source.ppt attached above at post id 178976?

     

    I think, not, your image might be embedded not linked. To test it try my source.ppt instead of yours.

     

    Also, I have retested the above code with Aspose.Slides 3.1.1.1


    Many Thanks and Kind Regards,

    Shakeel Faiz
    Support Developer
    Aspose Sialkot Team
    Contact Us
    Aspose - The .NET and Java Component Publisher

    Keep in touch! We're on Twitter and Facebook
     
  •  07-10-2009, 10:43 AM 188021 in reply to 187859

    Re: How to Add image from URL to Slide?

    Shakeel...thanks for your help...I figured out the problem...

    The slashing in your image URL were the wrong DIRECTION and that made all the difference in the world!

    Wow! P.

     
View as RSS news feed in XML