static void Main(string[] args) { try { DocApi docraptor = new DocApi(); docraptor.Configuration.Username = "******"; Doc doc = new Doc( test: true, // test documents are free but watermarked documentContent: "<html><body>Hello World</body></html>", // supply content directly // documentUrl: "http://docraptor.com/examples/invoice.html", // or use a url name: "docraptor-csharp.pdf", // help you find a document later documentType: Doc.DocumentTypeEnum.Pdf // pdf or xls or xlsx // javascript: true, // enable JavaScript processing // princeOptions: new PrinceOptions( // media: "screen", // use screen styles instead of print styles // baseurl: "http://hello.com" // pretend URL when using document_content // ) ); AsyncDoc response = docraptor.CreateHostedAsyncDoc(doc); DocStatus statusResponse; Boolean done = false; while (!done) { statusResponse = docraptor.GetAsyncDocStatus(response.StatusId); Console.WriteLine("doc status: " + statusResponse.Status); switch (statusResponse.Status) { case "completed": done = true; Console.WriteLine("Hosted Async Download URL: " + statusResponse.DownloadUrl); break; case "failed": done = true; Console.WriteLine("FAILED"); Console.WriteLine(statusResponse); break; default: Thread.Sleep(1000); break; } } } catch (DocRaptor.Client.ApiException error) { Console.WriteLine(error); } }
static void Main(string[] args) { DocApi docraptor = new DocApi(); docraptor.Configuration.Username = "******"; // docraptor.Configuration.Debug = true; // Not supported in Csharp Doc doc = new Doc( name: "csharp-hosted-async.pdf", test: true, documentContent: "<html><body>Hello from C#</body></html>", documentType: Doc.DocumentTypeEnum.Pdf ); AsyncDoc response = docraptor.CreateHostedAsyncDoc(doc); DocStatus statusResponse; while (true) { statusResponse = docraptor.GetAsyncDocStatus(response.StatusId); if (statusResponse.Status == "completed") { break; } else if (statusResponse.Status == "failed") { Console.WriteLine("Failed creating hosted async document"); Environment.Exit(1); } Thread.Sleep(1000); } WebClient webClient = new WebClient(); webClient.DownloadFile(statusResponse.DownloadUrl, @"/tmp/the-file-name.pdf"); string line = File.ReadLines("/tmp/the-file-name.pdf").First(); if (!line.Contains("%PDF-1.5")) { Console.WriteLine("unexpected file header: " + line); Environment.Exit(1); } }