I am receiveing a "Object reference not set to an instance of an object." error when calling the Close() method on the PDF object. Here is my code...
public void InsertImageOnPDF(FileInfo pdfFileInfo, Bitmap barcodeImage)
{
FileStream fs = new FileStream(pdfFileInfo.FullName,FileMode.Open, FileAccess.ReadWrite );
//Instantiate a Pdf object
Pdf pdf1 = new Pdf(fs);
//Create a new section in the Pdf document
Aspose.Pdf.Section sec1 = new Aspose.Pdf.Section(pdf1);
//Add the section in the sections collection of the Pdf document
pdf1.Sections.Add(sec1);
//Create an image object
Aspose.Pdf.Image image1 = Aspose.Pdf.Image.FromSystemImage(barcodeImage);
//Add the image into paragraphs collection of the section
sec1.Paragraphs.Add(image1);
image1.ImageInfo.ImageFileType = ImageFileType.Bmp;
//Set desired the image scale
image1.ImageScale = 0.5F;
pdf1.Close();
}
I am passing in a valid reference to an exsiting PDF file and a Bitmap image generated using the following code that leverages Aspose.Barcode.
public Bitmap GenerateBarcodeImage()
{
//Instantiate BarCodeBuilder object
BarCodeBuilder bb = new BarCodeBuilder();
//Set the Code text for the barcode
bb.CodeText = "1234567";
//Set the symbology type to Code39Standard
bb.SymbologyType = Symbology.DataMatrix;
//Save the image to your system and set its image format to Jpeg
//bb.Save(m_DestDir + "barcode.jpg", ImageFormat.Jpeg);
return bb.BarCodeImage;
}
Can you please tell me know what I am doing wrong here?