Hi,
I'm currently evaluating the use of Aspose.Pdf for converting a Bitmap, which is generated in my code, into a pdf file.
But it doesn't work, the output pdf file is always completely black.
This is the code I use:
private void SaveBitmapAsPdf(Bitmap bmp)
{
// Save Bitmap to file -> for comparison with the resulting pdf file
bmp.Save(@"C:\temp\TestImage.bmp");
using (MemoryStream ms = new MemoryStream())
{
// Save Bitmap to MemoryStream
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
//Instantiate a Pdf object
Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();
// Reset margins
pdf1.PageSetup.Margin.Bottom = 0;
pdf1.PageSetup.Margin.Left = 0;
pdf1.PageSetup.Margin.Top = 0;
pdf1.PageSetup.Margin.Right = 0;
//Create a new section in the Pdf document
Aspose.Pdf.Generator.Section sec1 = new Aspose.Pdf.Generator.Section(pdf1);
//Add the section in the sections collection of the Pdf document
pdf1.Sections.Add(sec1);
//Create an image object
Aspose.Pdf.Generator.Image image1 = new Aspose.Pdf.Generator.Image(sec1);
//Add the image into paragraphs collection of the section
sec1.Paragraphs.Add(image1);
image1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Bmp;
//Set the ImageStream to the MemoryStream object
image1.ImageInfo.ImageStream = ms;
//Save the Pdf
pdf1.Save(@"C:\temp\TestPdf.pdf");
}
}
The code has two resulting files (see attached zip file):
TestImage.bmp and TestPdf.pdf
The goal is that both files look completely the same, but as you can see the pdf file is black.
Can you show me, what I'm doing wrong?
Thanks,
Felix