Hi Felix,
string outFile =
myDir + “ImagetoPDF.pdf”;
string inFile = myDir + ("TestImage.bmp");
Document doc = new Document();
Page page = doc.Pages.Add();
FileStream fs = new FileStream(inFile, FileMode.Open, FileAccess.Read);
// 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 = fs;
//Set desired image scale
//doc.Convert(new MemoryStream(), PdfFormat.PDF_A_1B, ConvertErrorAction.Delete);
doc.Save(outFile);
Please feel free to contact us for any further assistance.
Best Regards,
Hi,
thank you for your response.
It works perfect if I use a FileStream of my saved Bitmap file.
But it still doesn’t work if I save the bitmap into a MemoryStream and take this stream as ImageStream (the image is still black). With the solution of taking the FileStream I always have to save the Bitmap into a file before converting it to pdf.
Do you have any idea how to solve my problem without saving the bitmap into a file before conversion?
Thanks,
Felix
Hi Felix,
Thanks for sharing your findings.We have managed to reproduce the reported issue and logged it in our bug tracking system as PDFNEWNET-36933 for further investigation and resolution. We will notify you via this thread as soon as it is resolved.
Please feel free to contact us for any further assistance.
Best Regards,
Hi Felix,
System.Drawing.Image img = System.Drawing.Image.FromFile(inFile);<o:p></o:p>
MemoryStream imgms = new MemoryStream();
img.Save(imgms, ImageFormat.Bmp);
img = new System.Drawing.Bitmap(imgms);
img.Save(outFile);
In case you still face the same problem or you have any further query, please feel free to contact.
Hi,
but I don’t have an input file here, I only have a Bitmap-Object which I myself create before executing the code (which I posted above).
So how can this Bitmap-Object have PNG format?
Thanks,
Felix
Hi again,
you were right, I’ve just done it!
I simply had to call bmp.Save(…) with PNG as image format (“bmp.Save(ms, ImageFormat.Png);” instead of “bmp.Save(ms, ImageFormat.Bmp);”), then it worked.
Thanks a lot, the problem is solved!
Felix
Hi Felix,