Free Support Forum -

Error in PDF Generation


We are facing issue in groupdocs pdf generation code while making a callback call on handler.
The method on which we are getting the error is ‘service.DownloadFile’ and getting following error -System.ArgumentNullExceptionValue cannot be null. Parameter name: fileId



We are sorry that you have this issue. From your request we can assume that you use GroupDocs .NET SDK. Basically this error means that one of argument from that used in this method is Null or empty. Could you please double check that all parameters required by this method are not empty or Null. Also it will be helpful if you provide example of your code and data which you use that our developers can reproduce your issue.

Also If you have any additional questions please feel free to get back in touch.


I initially have an ajax hit on the handler and below is the handler code ---------------

JavaScriptSerializer serializer = new JavaScriptSerializer();
GroupdocsService myService = null;
string url = ReadConfig.SiteUrl + string.Format(“SubmissionDownload.aspx?ID={0}&role={1}&userid={2}&date={3}”, this[“Id”], this[“role”], this[“userid”], DateTime.Now.ToString());
Submission submission = (new SubmissionComponent()).GetSubmission(Convert.ToInt64(this[“Id”]));
//CommonFunctions.SetResponseHeader(submission.SubmissionID + “-” + submission.Name + “.pdf”);
//CommonFunctions.ExportToPdf(Context.Response.OutputStream, url);
string fileName = submission.SubmissionID + “-” + submission.Name + “.pdf”;
myService = new GroupdocsService(ReadConfig.BaseAddress, ReadConfig.UserID, ReadConfig.PrivateKey);
string callbackUrl = ReadConfig.SiteUrl + “Handler/AnnotationMessage.ashx/DownloadGroupdocsPDF?name=” + fileName;

string name = myService.UploadUrl(url);
decimal jobId = myService.ConvertFile(name, “pdf”, “”, false, false, callbackUrl);

string callback = jobId > 0 ? fileName : string.Empty;

string value = serializer.Serialize(new
Result = callback
HttpContext.Current.Response.ContentType = “application/json”;


In this we have the callback url which calls another handler and code of that is as follow-

public bool DownloadGroupdocsPDF()
if (HttpContext.Current.Request.HttpMethod == “POST”)
string Name = this[“name”];
System.IO.StreamReader reader = new System.IO.StreamReader(HttpContext.Current.Request.InputStream);
String jsonString = reader.ReadToEnd();

var data = System.Web.Helpers.Json.Decode(jsonString);

String jobId = data.SourceId;
jobId = jobId.Replace(" ", “”);
String fileId = “”;
// Create service for Groupdocs account
GroupdocsService service = new GroupdocsService(ReadConfig.BaseAddress, ReadConfig.UserID, ReadConfig.PrivateKey);
//Make request to api for get document info by job id
Groupdocs.Api.Contract.GetJobDocumentsResult job = service.GetJobDocuments(jobId);
String name = “”;
if (job.Inputs[0].Outputs[0].Guid != “”)
//Return file guid to the template
fileId = job.Inputs[0].Outputs[0].Guid;
name = Name;//job.Inputs[0].Outputs[0].Name;

// Definition of folder where to download file
String downloadFolder = AppDomain.CurrentDomain.BaseDirectory + “downloads/”;

if (!Directory.Exists(downloadFolder))
DirectoryInfo di = Directory.CreateDirectory(downloadFolder);

//### Make a request to Storage Api for dowloading file
// Download file
bool file = service.DownloadFile(fileId, downloadFolder + name);
return file;
return false;


We are getting error in callback in this code ‘service.DownloadFile’



Thank you for additional info. After checking your code we can assume that reason of your issue is a “url” variable in the ajax handler. Your “url” variable contains something like “http://your site base url/ SubmissionDownload.aspx?your GET parameters”. In the method myService.UploadUrl(url); you should use direct URL to the file which should be uploaded.

If this will not help, please share with us what you get in the

var data = System.Web.Helpers.Json.Decode(jsonString);

so we can check it out.

Also you can check our sample for file conversion and downloading converted file by Callback here -

If it possible you can send to us example of your project and we will check and fix it for you.


This code is to create pdf from html. In url, we provide the link of the page from which pdf has to be generated.



Thanks for getting in touch. Sorry but GroupDocs.Convertion for Cloud API can’t convert a web page to the PDF directly. To goal this you should first off all save mentioned page as HTML file and just then convert this file with GroupDocs.Convertion for Cloud API.

Please check our live sample for this feature here -

If you have any additional questions please feel free to get back in touch.


service.DownloadFile does download the file in download folder but after that we receive the null error.



Thank you for getting back to us. In our previous response, we recommend you to save your web page as HTML file and then upload it to the GroupDocs, did you try such way?

From your last message it is not clear which parameter is null: could you please debug your project and share with us the content of all the variables which you have at the moment when you call the “DownloadFile” method? This information will be very helpful to investigate what’s wrong with your code.

If you have any additional questions, please feel free to get back in touch.



In Upload method I only pass the url of the web page. Following are the details -

Ajax method parameters :
url for upload - 2:15:52 AM
name returned after myService.UploadUrl method - f0ae94cdedadcbfcd72aa4caf2a9a9e5558dcd6ce59f0180181bde5e5a18907a
callbackUrl - new test.pdf

Following are the paramets in callback :
jobId - 16eb2e0522d9c20b4f9e6f498b320c1c8bd798d763b1c0826c90324992523bb3
fileId - e1ab08d2cd9601c6205964ed0d8624c42a3d3bb603962f675f222a20d37cce3b
downloadFolder + name - C:\Websites\\downloads\16072-ML new test.pdf

File is created successfully. Don’t know why DownloadFile method after that returns null. Please also check in your code as i believe this code must be to download the file in the mentioned folder.



Thank you for providing additional information. We checked DownloadFile method with your data and all works fine for us. Method returns “true” and file successfully downloaded. This method can’t return null since type of data which this method return is “bool”. According on that in the response can be only “true” or “false”. Could you please provide screenshot of the issue. Please make a screenshot on which will be seen variables value after passing code line with DownloadMethod.