Assistance with converting picture to pdf

I am trying to convert a picture (jpg) to a pdf following the various examples on the site. My code snippet is given below. I am trying to save the new pdf to a memorystream which I will use later as part of the process, but when I try to save it a "Value cannot be null" error is raised. Can you see where I am going wrong? thanks

//myAttFile is a sharepoint file object
Stream myJPGStream = myAttFile.OpenBinaryStream(); //this stream is not empty
Aspose.Pdf.Pdf jpgPDF = new Aspose.Pdf.Pdf();
MemoryStream ms = new MemoryStream();
Aspose.Pdf.Section sec = new Aspose.Pdf.Section(jpgPDF);
jpgPDF.Sections.Add(sec);
Aspose.Pdf.Image pdfImage = new Aspose.Pdf.Image(sec);
sec.Paragraphs.Add(pdfImage);
pdfImage.ImageInfo.ImageFileType = Aspose.Pdf.ImageFileType.Jpeg;
pdfImage.ImageInfo.ImageStream = myJPGStream;
pdfImage.ImageScale = .5f;
jpgPDF.Save(ms);//this raises a "Value cannot be null" error

Hello Dan,

Thanks for using our products.

I have tested the scenario using Aspose.Pdf for .NET 5.2.0 with code snippet shared over How to convert MemoryStream Image to PDF and I am unable to notice any problem. As per your requirements, I have saved the final PDF into MemoryStream object and after saving it to MemoryStream object, I can get the Stream Length information and can perform further operations.

For the sake of testing, I have used a sample JPEG image. May be there is some issue while you are reading the source image or something specific to the source Image that you are using. Can you please take a look over the code snippet present over above specified link and in case the problem still persists, please share the source Image so that we can test the scenario at our end. We are really sorry for this inconvenience.

working with streams is not my strong point, but after looking at your example again I modified my code as below, which functioned correctly;

MemoryStream myStream = new MemoryStream();

byte[] bf = myAttFile.OpenBinary(); //myAttFile is a SPFile object from a sharepoint list

MemoryStream ms = new MemoryStream(bf);

Aspose.Pdf.Pdf jpgPDF = new Aspose.Pdf.Pdf();

Aspose.Pdf.Section sec = new Aspose.Pdf.Section(jpgPDF);

jpgPDF.Sections.Add(sec);

Aspose.Pdf.Image pdfImage = new Aspose.Pdf.Image(sec);

sec.Paragraphs.Add(pdfImage);

pdfImage.ImageInfo.ImageFileType = Aspose.Pdf.ImageFileType.Jpeg;

pdfImage.ImageInfo.ImageStream = ms;

pdfImage.ImageScale = .5f;

jpgPDF.Save(myStream);

Hello Dan,

I am glad to hear that your problem is resolved. In case you encounter any further problem, please feel free to contact. Thanks for contacting support.