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

Free Support Forum - aspose.com

Insufficient data for an image (.bmp)

I am evaluating and using trial Aspose.Pdf version 8.9.0.0. I have a .bmp file I am converting into a pdf. When I open the pdf document, I get error: "Insufficient data for an image." Here is the sample code. I have tried uploading the .bmp file but your upload window does not support uploading this file type.

public int SaveImageToPDF(MemoryStream stream, string fileName)
{
//Instantiate a Pdf object by calling its empty constructor
Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();

//Create a section in the Pdf object
Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();

//Create an image object in the section
Aspose.Pdf.Generator.Image image1 = new Aspose.Pdf.Generator.Image(sec1);

stream.Position = 0;

using (Bitmap myimage = new Bitmap(stream))
{
// check if the image is landscape
if (myimage.Width > myimage.Height)
{
// if the Image width is greater than page width, then set the page orientation to Landscape
sec1.IsLandscape = true;
// set the image width equal to page width
image1.ImageInfo.FixWidth = sec1.PageInfo.PageWidth - sec1.PageInfo.Margin.Left -
sec1.PageInfo.Margin.Right;
// set the image Height equal to page Height
image1.ImageInfo.FixHeight = sec1.PageInfo.PageHeight - sec1.PageInfo.Margin.Top -
sec1.PageInfo.Margin.Bottom;
}
else
// if the Image width is less than page width, then set the page orientation to Portrait
sec1.IsLandscape = false;
}

//Add image object into the Paragraphs collection of the section
sec1.Paragraphs.Add(image1);

//Set the path of image file
image1.ImageInfo.ImageStream = stream;

//Set the type of image using ImageFileType enumeration
image1.ImageInfo.ImageFileType = ImageFileType.Bmp;

//Save the Pdf
pdf1.Save(fileName);


return pdf1.PageCount;

}

Thanks.

Hi Kathleen,


Thanks for using our API.

Please archive the source/input BMP file to .zip format and again try uploading the file so that we can test the scenario at our end. In case you still encounter the issue, please directly send us the document by following the instructions specified over How to send a license?

We are sorry for your inconvenience

I have uploaded the input and output file. Thanks.

Hi Kathleen,


Thanks for sharing the resource files.

I
have tested the scenario and I am able to notice the same problem. For the sake
of correction, I have logged this problem as PDFNEWNET-36651 in
our issue tracking system. We will further look into the details of this
problem and will keep you updated on the status of correction. Please be
patient and spare us little time. We are sorry for this inconvenience.<o:p></o:p>

The issues you have found earlier (filed as PDFNEWNET-36651) have been fixed in Aspose.Pdf for .NET 9.2.0.

The blog post for this release is created over this link


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

I have tried with Aspose.Pdf for.NET 9.2.0.0 and 9.2.1.0 and I still experience the same problem.

Hi Louis,


Thanks for contacting support. The earlier reported issue was fixed against the source image shared by Kathleen and it was fixed in Aspose.Pdf for .NET 9.2.0. However if you are facing any issue, please share the resource image file so that we can further look into this matter. We are sorry for your inconvenience.


Hi Louis,


In addition to Nayyer reply, Please consider new DOM approach to convert Image to PDF. It is more reliable and efficent approach than old Generator (Aspose.Pdf.Genertaor). Please check new generator code.


string outFile = “36651.pdf”;<o:p></o:p>

string inFile = "36651.bmp";

Document doc = new Document();

Page page = doc.Pages.Add();

//Create an image object in the section

Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();

FileStream stream = new FileStream(inFile, FileMode.Open);

// if the Image width is greater than page width, then set the page orientation to Landscape

page.PageInfo.IsLandscape = true;

// set the image width equal to page width

image1.FixWidth = page.PageInfo.Width - page.PageInfo.Margin.Left -

page.PageInfo.Margin.Right;

// set the image Height equal to page Height

image1.FixHeight = page.PageInfo.Height - page.PageInfo.Margin.Top -

page.PageInfo.Margin.Bottom;

//Add image object into the Paragraphs collection of the section

page.Paragraphs.Add(image1);

//Set the path of image file

image1.ImageStream = stream;

doc.Save(outFile);

stream.Close();

Please feel free to contact us for any further assistance.


Best Regards,