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.