We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Problem converting images to PDF

Hello,

I am experiencing a problem converting posted images to PDF. My code works perfectly for any image type except for jpg ones. When I send a jpg, an exception occurs when calling Save method of Pdf object:

"Value of 'null' is not valid for 'stream'"

I attach a sample of code that reproduces the error.

I am doing anything wrong?

Thank's in advance,

Miguel.

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. I can’t see that you are using Aspose.Wortds in your code. It seems you have posted in wrong forum. I will move this thread into Aspose.Pdf forum. My colleagues will answer you shortly.

Best regards.

Hi,

I have tried running the attached code sample and can see the same problem at my end.

I'm looking into the issue and will let you know as I find some resolution.

Regards,

Shahzad

Hi Miguel,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

I have tested the code snippet with Aspose.Pdf 3.9.0.0 and I am unable to reproduce the problem. I have little modified the code and in my case I have passed File as String instead of HttpPostedFile to Convert() method. The resultant file that I’ve generated is in attachment. Please take a look.

Hi Miguel,

I'm sorry for the delayed response.

Actually, Aspose.Pdf currently supports FileStream and ImageStream only. it doesn't support System.Web.HttpInputStream. This issue has been logged as PDFNET-6989; Neverthless, you can use memory stream as a work around. That is, you can convert input stream into memory stream before using it with Aspose.Pdf.

Here is the sample to give you an idea:

//declare a base stream instance

Stream stream;

//create a byte array

byte[] bytearr = new byte[FileUpload1.PostedFile.ContentLength];

//initialize base stream to be read

stream = FileUpload1.FileContent;

//read stream data into byte array

stream.Read(bytearr,0,FileUpload1.PostedFile.ContentLength);

//create a MemoryStream object and fill write data from byte array

MemoryStream inputStream = new MemoryStream(bytearr);

//assign this inputStream to the ImageStream of Aspose.Pdf

img.ImageInfo.ImageStream = inputStream;

//Now, save to the destination stream

MemoryStream destStream = new MemoryStream();

pdfDoc.Save(destStream);

Above code sample worked for all types of image files.

If you find any issue I would be happy to help you out.

Regards.