Parameter is not valid when creating PDF


#1

Please review the attached sample project with the exception. When calling the Save() method on the PDF object the exception is “Parameter is not valid”. The full stack trace is below. Aspose.PDF.dll version is 3.7.0.0

How do we fix this problem? Can we do so without turning our production website upside-down in the process? This was working in the past so I have no idea what happened to make it stop working.


=================
at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
at System.Drawing.Image.FromStream(Stream stream)
at Aspose.Pdf.Xml.ᑚ.ᑛ(Pdf Ә, Section ཥ, Table ख, Row ต, Cell ඟ, Image د, ര ്, ྗ ྅, Boolean Ᏺ)
at Aspose.Pdf.Xml.ᖹ.ᖼ(Pdf Ә, Section ཛ, ര ്)
at Aspose.Pdf.Xml.ܓ.໺(Pdf Ә)
at Aspose.Pdf.Xml.᥺.᥿(׸ Ԯ, Pdf Ә)
at Aspose.Pdf.Pdf.Save(Stream stream)
at WebApplication1._Default._createPdf_Click(Object sender, EventArgs e) in C:\MyFiles\Dev\Temp\WebApplication1\WebApplication1\Default.aspx.cs:line 50
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
========================


Convert Image to PDF Without Using Aspose.Pdf.Generator
#2

One more note:
I just noticed that the System.Drawing.Image class is in the stack trace. Presumably this is being used to create the PDF from within the Aspose code?

If so, Microsoft does not appear to support this within a web environment:

http://msdn.microsoft.com/en-us/library/system.drawing.aspx

From that link:
“Classes within the System.Drawing
namespace are not supported for use within a Windows or ASP.NET
service. Attempting to use these classes from within one of these
application types may produce unexpected problems, such as diminished
service performance and run-time exceptions.”


#3

Hello Bob,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Sorry for replying you late.

I have tested the issue and I’m able to reproduce the same problem. I've also tested it with windows application and the issue is also occurring in that case. For the sake of correction, I've logged it in our issue tracking system as PDFNET-11998. We will investigate this issue in detail and will keep you updated on the status of a correction.

We apologize for your inconvenience.


#4

Hello Bob,

Thanks for your patience.

We have investigated this issue in details and have found that the problem is occurring because an invalid image URL http://pathpedia.com/graphics/Logo.jpg was specified in source XML file. For the sake of testing, I have replaced it with http://www.aspose.com/Images/aspose-logo.jpg and the PDF document is properly being generated without any problem. Even the image does not display if you try to access the URL already present in XML file.

The resultant PDF that I have generated using Aspose.Pdf for .NET 4.6.0 (which can be downloaded from here) is in attachment, please take a look.

In case you still face any problem or you have any further query, please feel free to contact. We apologize for your inconvenience.


#5

Hi @codewarior , I m trying to convert image and doc byte array to pdf array , in ASP.NET,
But every time I save I get a parameter is not valid while doc.save .

Note: the same code works fine in MVC
Kindly help here is the code:-

        private byte[] ConvertImageToPdf(byte[] imageFile)
        {
            

            var pdfFile = new MemoryStream();
            Aspose.Pdf.Generator.Pdf pdfFilePdf = new Aspose.Pdf.Generator.Pdf();
            Aspose.Pdf.Generator.Section pdfSection = pdfFilePdf.Sections.Add();
            Aspose.Pdf.Generator.Image objImage = new Aspose.Pdf.Generator.Image(pdfSection);
            pdfSection.Paragraphs.Add(objImage);
            objImage.ImageInfo.ImageStream = new MemoryStream(imageFile);
            pdfFilePdf.Save(pdfFile);

            return pdfFile.ToArray();

        }

       

#6

@PatrickCook

Thank you for contacting support.

Please note that support is provided based on latest available version of the API so please upgrade to Aspose.PDF for .NET 19.6 and visit Add Image Stamp in PDF File for your kind reference. You may modify it as per your requirements and feel free to get back to us along with source image if you still face any issue.