This is an archived forum post. The information may be outdated. Contact us if you have any questions.

Detecting corrupted pdf returned

Ramins wrote on 2014-05-07:
Hi there,

Lately we have a new webpage that asks user for some identifying info then use your service to convert another webpage to pdf and emails the returned pdf. We did not prevent user from clicking the submit button multiple times and as a result in the series of clicks only the email from last click contains good pdf while the earlier emails have corrupted pdf.
It seems to us that pdfcrowd will abort current conversion shall it receives a new request from the same subscription? Say while it is converting url1 and request of converting url2 arrived from the same ip (subscription) then conversion of url1 will abort (results in corrupted pdf) and move on to converting url2.
Wondering if you agree with our observation? Kind of similar to the previous post of "Simultaneous API calls from a single IP are not allowed"? Is there anyway to tell if returned pdf is corrupted? In our environment, we can't guarantee that requests to pdfcrowd will be in an orderly fashion as there are multiple places that are capable to firing conversion requests to pdfcrowd.

Please kindly shed a light.

support wrote on 2014-05-07:
Hello Ramins,

The API should never return corrupted PDF. If your application sends multiple requests at at time, the first request that comes in is processed but the API returns an error for the following ones. How do you handle the errors returned from the API?
Ramins wrote on 2014-05-08:
I see... Previously we were just response.write the pdfcrowd error but at client size they stream it as pdf and the emails with proper pdf were indeed from the first clicks just that the conversion takes some time so they arrive last. Glad to have this sorted! You think the following is robust enough? Is there a better way to detect the err is 503 in .NET? a getCode() like in PHP?

(pdfcrowd api call abbreviated)
// send the generated PDF
catch (pdfcrowd.Error why)
var msg = why.ToString();
if (msg.IndexOf("503") == -1 || tries == 10)
// Added logging for Survey Engine null reference exception.
var message = new StringBuilder();
message.AppendLine("Exception occurred in UrlToPdf.ProcessRequest():");
message.AppendLine(String.Format("QueryString: {0}", Request.QueryString.ToString()));
message.AppendLine(String.Format("IP: {0}", Request.UserHostAddress));
message.AppendLine(String.Format("UserAgent: {0}", Request.UserAgent));
message.AppendLine(String.Format("Referrer: {0}", Request.UrlReferrer));
throw new Exception(message.ToString(), why);

Thank you,
support wrote on 2014-05-08:
Hello Ramins,

Your code looks fine to me. You are right that there is currently no proper way how to get the http code from an pdfcrowd.Error instance - we should add it.