Hi, I am trying to convert a BMP image stored in database in byte array format to PDF, then the resultant PDF seems totally distorted and unreadable. Here’s my approach of doing the conversion with C#. I attached the source and the output file here for your reference. Please assist, thank you. Your prompt response is greatly appreciated.
Hi ShiJien,
string outFile = myDir + “ImagetoPDFDOM.pdf”;<o:p></o:p>
string inFile = myDir + "testimage (2).bmp";
FileStream fs = new FileStream(inFile, FileMode.Open, FileAccess.Read);
byte[] tmpBytes = new byte[fs.Length];
fs.Read(tmpBytes, 0, Convert.ToInt32(fs.Length));
MemoryStream mystream = new MemoryStream(tmpBytes);
Document doc = new Document();
Page page = doc.Pages.Add();
// Set margins so image will fit, etc.
page.PageInfo.Margin.Bottom = 0;
page.PageInfo.Margin.Top = 0;
page.PageInfo.Margin.Left = 0;
page.PageInfo.Margin.Right = 0;
page.PageInfo.Height = Aspose.Pdf.PageSize.A4.Height;
page.PageInfo.Width = Aspose.Pdf.PageSize.A4.Width;
//Create an image object
Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();
//Add the image into paragraphs collection of the section
page.Paragraphs.Add(image1);
//Set the ImageStream to a MemoryStream object
image1.ImageStream = mystream;
doc.Save(outFile);
Please feel free to contact us for any further assistance.
Best Regards,
Hi,
Hi ShiJien,
We are glad to hear that your problem is resolved. Please note that we cannot guarantee and 100% support for all type of BMP (raster images) to PDF conversion without any issue, but sometimes due to structure of any particular file, the conversion encounters some issue.