Free Support Forum -

Exception while converting doc to PDF "Parameter is not valid." using Aspose words


We are using version of ASPOSE words, This is most frequently occuring after download of 20 to 30 PDFs. Below mentioned is the exception details. While i was browsing the forum i came across WORDSNET-6709 . is this the same source of issue as what i mentioned below. Please help resolve it.

I sense this as a issue in the contorol something related to memory outage.

Level : 0 System.ArgumentException: Parameter is not valid.
at System.Drawing.Bitmap..ctor(Stream stream)
at xf9a9481c3f63a419.x3cd5d648729cd9b6..ctor(Byte[] imageBytes)
at x011d489fb9df7027.x8e500baeffc6e539.set_xcc18177a965e0313(Byte[] xbcea506a33cf9111)

at Aspose.Words.DocumentBuilder.InsertImage(Byte[] imageBytes, RelativeHorizontalPosition horzPos,
Double left, RelativeVerticalPosition vertPos, Double top, Double width, Double height, WrapType wrapType)
at Aspose.Words.DocumentBuilder.InsertImage(Byte[] imageBytes)



Thanks for your inquiry. Could you please attach your input/output documents (.doc/.pdf files) along with the source code here for testing? I will investigate the issue on my side and provide you more information.

Best regards,

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

Due to some policy issues I may not be able to provide you the entire code or formats of documents. But I can provide you a detailed explanation of what we are doing. We are building a string by replacing values with placeholders for a html template , this string is used to build PDF. During this process we are getting a exception

While inserting image (logo) at header of PDF. See code snippet below.

This exception occurs only after few hours of business day, Not always .

AsposeDoc = new Aspose.Words.Document();

AsposeBuilder = new DocumentBuilder(AsposeDoc);

AsposeBuilder.CellFormat.WrapText = true;

AsposeBuilder.RowFormat.AllowAutoFit = true;

Aspose.Words.Section currentSection = AsposeBuilder.CurrentSection;

Aspose.Words.PageSetup pageSetup = currentSection.PageSetup;

//pageSetup.Orientation = Aspose.Words.Orientation.Landscape;

pageSetup.LeftMargin = 30;

pageSetup.RightMargin = 30;

//Creating the Header Section

//string strImgPath = "C:\\Images\\Logo.png";

string strImgPath = string.Empty;

if (HttpContext.Current != null && HttpContext.Current.Session != null && HttpContext.Current.Session["AttachmentPath"] != null)

strImgPath = HttpContext.Current.Session["AttachmentPath"].ToString() + poSqlDao.Client + "\\Images\\" + poSqlDao.Client + "_logo.gif";

if (File.Exists(strImgPath))


FileStream fs = null;

fs = File.OpenRead(strImgPath);

int fileSize = (int)fs.Length;

byte[] _BufImage = new byte[fileSize];

fs.Read(_BufImage, 0, fileSize);



pageSetup.DifferentFirstPageHeaderFooter = false;


pageSetup.HeaderDistance = 2;


double tableWidth1 = pageSetup.PageWidth - pageSetup.LeftMargin - pageSetup.RightMargin;


AsposeBuilder.Font.Underline = Underline.None;

AsposeBuilder.CellFormat.Width = tableWidth1 * 2 / 3;

AsposeBuilder.CurrentParagraph.ParagraphFormat.Alignment = ParagraphAlignment.Left;





//End Header Logo

// Create a Footer Section to show Page Number


pageSetup.FooterDistance = 10;


double tableWidth = pageSetup.PageWidth - pageSetup.LeftMargin - pageSetup.RightMargin;


AsposeBuilder.Font.Name = "Arial";

AsposeBuilder.Font.Size = 10;

//AsposeBuilder.CellFormat.Width = tableWidth;

AsposeBuilder.CellFormat.Width = tableWidth;

AsposeBuilder.InsertField("PAGE", "");

AsposeBuilder.Write(" of ");

AsposeBuilder.InsertField("NUMPAGES", "");

AsposeBuilder.CurrentParagraph.ParagraphFormat.Alignment = ParagraphAlignment.Right;




pageSetup.PaperSize = PaperSize.A4;

pageSetup.TopMargin = 30;

pageSetup.BottomMargin = 10;


NodeCollection paragraphs = AsposeDoc.GetChildNodes(NodeType.Paragraph, true);

foreach (Aspose.Words.Paragraph paragraph in paragraphs)


paragraph.ParagraphFormat.SpaceAfterAuto = false;

paragraph.ParagraphFormat.SpaceAfter = 0;


AsposeDoc.Save(strDocumentPath, Aspose.Words.SaveFormat.Pdf);




Thanks for your inquiry. Could you please try using the latest version of Aspose.Words on your side and let us know of your findings? You can download Aspose.Words for .NET version 11.10.0 from the following link:

I hope, this will help.

Moreover, instead of giving us your original documents, could you please attach here any simplified documents and logo image which will allow us to reproduce the problem on our side? So you can simply remove sensitive information from your documents or replace it with dummy data.

Best Regards,

Hi Thank you for your reply. I have attached the template along with some dummy logo.

Can you please try to replicat this. it occurs very randomly if he heavily download PDFs.

Please consider our previous discussions. Appreciate your timely responses.



Hi Arun,

Thanks for the additional information. In order to completely check your scenario on my side, I would be requiring the following resources:

  1. Your input Word document you’re inserting html into.
  2. Your Logo.png image file.
  3. The Html mark-up string your’re passing to DocumentBuilder.InsertHtml method.

Best regards,