none
"There was an error while reading a stream" when trying to add images to .pdf programmatically RRS feed

  • Question

  • I'm using a NuGet package called Report.NET to make an ASP.NET web page with the capability to generate .pdf reports. The code behind the .pdf printing functionality is all done in C#. Generating text works fine, but I need to also be able to include images. My current code to add an image to a .pdf is this:

    Report report = new Report(new PdfFormatter());

                FontDef fd = new FontDef(report, "Helvetica");

                FontProp fp = new FontPropMM(fd, 25);

                Page page = new Page(report);

                page.AddMM(20, 25, new RepImageMM

    (@"C:\Users\public\pictures\sample pictures\Carconvert.png", 40, Double.NaN));

                page.AddCB_MM(80, new RepString(fp, "Hello World!"));

                RT.ViewPDF(report, "HelloWorld.pdf");


    This returns the error in the title line when I generate the .pdf through the web page, but no other exceptions are thrown and the .pdf proceeds to generate, just without a picture. The required parameters for RepImageMM are (<filepath>,<size>,Double.NaN). I have done some experimenting to see if ANY image will get through, and I've seen that the Windows Sample Pictures will in fact print(which is why my above code goes to the Sample Pictures folder, to deduce whether the containing folder is the problem somehow.) running the above code for Desert.Jpg instead of CarConvert.png works perfectly fine.

    • Moved by CoolDadTx Tuesday, October 24, 2017 5:44 PM Third party product
    Tuesday, October 24, 2017 2:11 PM

All replies

  • We do not provide support for third party libraries in the MSDN forums. Please post your question related to third party products in their forums or at their NuGet's project page.

    Michael Taylor http://www.michaeltaylorp3.net

    Tuesday, October 24, 2017 5:43 PM