Adding BMP to a PDF through Aspose.Pdf.Generator

I’ve been struggling with my prototype for PDF creation.


This time my issue is with adding a bitmap (logo) to the pdf. I’ve gone through several different iterations of the code, and I ended up with this basic test to illustrate what does not seem to be working. All I get is a blank PDF (except for the aspose evaluation waterwarking, of course).

private void imagetest()
{

Pdf pdf = new Pdf();
Aspose.Pdf.Generator.Section sec1 = new Aspose.Pdf.Generator.Section(pdf);
Aspose.Pdf.Generator.Image image1 = new Aspose.Pdf.Generator.Image(sec1);
string filename = “c:\test.bmp”;
if (!System.IO.File.Exists(filename)) Console.WriteLine(“No file!”);

image1.ImageInfo.File = filename; ;
image1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Bmp;

image1.ImageInfo.Title = “BMP image”;
sec1.Paragraphs.Add(image1);

pdf.Save(“C:\test.pdf”);
System.Diagnostics.Process.Start(“c:\test.pdf”);
}


What is it I’m doing wrong?

UPDATE
******************************************************************

I modified the above code to look like this (to make sure that the objects were being added)

private void imagetest()
{
Pdf pdf = new Pdf();
Aspose.Pdf.Generator.Section sec1 = new Aspose.Pdf.Generator.Section(pdf);
pdf.Sections.Add(sec1);
Aspose.Pdf.Generator.Image image1 = new Aspose.Pdf.Generator.Image(sec1);
sec1.Paragraphs.Add(image1);
string filename = “c:\test.bmp”;
if (!System.IO.File.Exists(filename)) Console.WriteLine(“No file!”);

image1.ImageInfo.File = filename; ;
image1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Bmp;

image1.ImageInfo.Title = “BMP image”;

pdf.Save(“C:\test.pdf”);
System.Diagnostics.Process.Start(“c:\test.pdf”);
}

And now I get an error when it opens (Insufficcient data for an image.).

Hi Mac,

Thanks for your inquiry. While using Aspose.Pdf for .net 7.7, I’ve tested the scenario but I’m unable to reproduce the issue, output document is attached here for the reference. Can you please share your sample image here? So we will test it at our side and will provide your more information accordingly.

Moreover, you can request a 30 days temporary license to evaluate our product without evaluation version limitations.

Please feel free to contact us for any further assistance.

Best Regards,

I’m attaching the image now. I had to zip it since I got a message saying it was not a valid attachment type.

Hi Mac,

Thanks for providing additional information. I’ve managed to reproduce the issue at my end with provided BMP image and logged it as PDFNEWNET-34891 in our bug tracking system for further investigation and resolution. You will be notified via this thread as soon as it is resolved.

Sorry for the inconvenience faced.

Best Regards,

Thanks.


And just as follow-up information, I converted the BMP I sent you to a JPG, and was able to successfully create the PDF. I have not found a way to recreate the BMP in a way that would allow me to use it. For example, I took the JPG I created from the BMP, and converted that back to a BMP. Now the new BMP appears, but is distorted beyond recognition.

Hi Mac,


Thanks for your feedback. I will share your findings with our development team.

We will keep you updated regarding issue progress via this forum thread.

Best Regards,

Hi,

Thanks for your patience.

We have further investigated the problem reported earlier and in order to resolve the problem, please try using the new DOM (Document Object Model) approach of the Aspose.Pdf namespace. Please try using the following code snippet to add the image to the PDF file.

[C#]

Aspose.Pdf.Document doc = new Aspose.Pdf.Document();

Aspose.Pdf.Page page = doc.Pages.Add();

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

// Set the path of image file
image1.File = @"c:/pdftest/testlogo.bmp";

page.Paragraphs.Add(image1);

doc.Save(@"c:/pdftest/testlogo_testbmp.pdf");

The issues you have reported earlier (filed as PDFNEWNET-34891) have been fixed in Aspose.Pdf for .NET 8.4.0.


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