Error: Cannot Read Properties of Undefined (Reading ‘readBytesFromStream’)

@arun08,
It looks like you have two issues.

Please share the following files:

  • sample presentation file
  • input image file
  • output presentation file

Then we will check the problem and help you.

I am working on the question and will get back to you soon.

TemplateFile.zip (406.0 KB)

I have added the sample image file, the requirement is to add base64 image data into the slides “imageplaceholder” , have added the base64image data along with this folder.
Kindly let me know for more details

@arun08,
Thank you for the details. I will get back to you soon.

@arun08,
The dimensions of the image (base64 data) and the dimensions of the “imageplaceholder” are different. Could you please specify the expected result?

@andrey.potapov , I apologies for that, The template image would just be a placeholder we can relpace it with any other shape if it works, I can also be a empty shape and want to place the image in that placeholder.

@arun08,
Thank you for the clarification. I am working on the issue and will get back to you soon.

1 Like

@arun08,
I was unable to replace the image in the picture frame with the image from the base64 string.

We have opened the following new ticket(s) in our internal issue tracking system and will investigate the issue according to the terms mentioned in Free Support Policies.

Issue ID(s): SLIDESNODEJS-64

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@andrey.potapov , We have license acquired for the apps. will it make any change ?

also we don’t want to add the image it to the picture frame, we can also add it to the rectange shape as well, will be accomodative of it. thanks in advance.

@arun08,

Unfortunately, this does not affect the solution of the problem. More details: Policies - Purchase - aspose.com

Could you please share a sample presentation with the expected result? We will do our best to help you.

TemplateFile.zip (559.6 KB)

have attached the sample output template, I have added the image within the rectangle shape manually, I would like the same to be done using base64 data with code.

Thanks. @andrey.potapov

@arun08,
Thank you for the sample file. Please try using the following code example:

var aspose = aspose || {};

const java = require("java");
const fs = require("fs");
const asposeSlides = require("aspose.slides.via.java");

const { Readable } = require("stream");
const { Console } = require("console");

const base64Image = "data:image/jpeg;base64,..."; // use valid data here

const [, encodedData] = base64Image.split(',');
const imageBytes = Buffer.from(encodedData, "base64");
const imageStream = new Readable();
imageStream.push(imageBytes);
imageStream.push(null);

asposeSlides.readBytesFromStream(imageStream, function (imageData) {
  presentation = new asposeSlides.Presentation("sample.pptx");
  slide = presentation.getSlides().get_Item(0);

  image = presentation.getImages().addImage(imageData);

  slide.getShapes().addPictureFrame(
    asposeSlides.ShapeType.Rectangle, 20, 20, 300, 400, image);

  presentation.save("output.pptx", asposeSlides.SaveFormat.Pptx);
  presentation.dispose();  
});

wil this work for the template approach as well ? Kindly advice. I have a template with rectangle shape in slide and i want this picture frame to be added in the rectangle.

@arun08,
An image can be added to the rectangle as a background, but I think it will be distorted or not fully displayed.

is there any other way we can do it for dynamic image without saving it to the drive ? like multi part form data ? Need a solution other than saving the file to the local.

@arun08,
I apologize for the delay. Could you please clarify why the solution above does not work for you?

Hi @andrey.potapov ,
I was not using
presentation.save(“output.pptx”, asposeSlides.SaveFormat.Pptx); after adding the image to the shape.

I was using the presentation.save at the end after all the other additions where done. It wasn’t working. Now i have modified it and it seems to work.

is this the correct way or is it a hack ?

@arun08,
You cannot use the Presentation.save method without parameters. You can only save presentations to a file or memory.

yes I understand, but I had other template or placeholders to fill, So was doing save at the end of it, but that wasn’t working, I had to do save after adding the image everytime. So that was a missing piece for me. @andrey.potapov

@arun08,
Please let us know if you have any questions.

Sure Thanks.