CreateAsyncDoc() public method

Creates a document asynchronously. You must use a callback url or the the returned status id and the status api to find out when it completes. Then use the download api to get the document.
Thrown when fails to make API call
public CreateAsyncDoc ( Doc doc ) : AsyncDoc
doc Doc The document to be created.
return AsyncDoc
    static void Main(string[] args)
    {
        Configuration.Default.Username = "******";
        // Configuration.Default.Debug = true; // Not supported in Csharp
        DocApi docraptor = new DocApi();

        Doc doc = new Doc(
          Name: new String('s', 201), // limit is 200 characters
          Test: true,
          DocumentContent: "<html><body>Hello from C#</body></html>",
          DocumentType: Doc.DocumentTypeEnum.Pdf
        );

        AsyncDoc response = docraptor.CreateAsyncDoc(doc);

        AsyncDocStatus status_response;
        for(int i=0; i<30; i++) {
          status_response = docraptor.GetAsyncDocStatus(response.StatusId);
          if (status_response.Status == "failed") {
        Environment.Exit(0);
          }
          Thread.Sleep(1000);
        }
        Console.WriteLine("Did not receive failed validation within 30 seconds.");
        Environment.Exit(1);
    }
Example #2
0
    static void Main(string[] args)
    {
        Configuration.Default.Username = "******";
        // Configuration.Default.Debug = true; // Not supported in Csharp
        DocApi docraptor = new DocApi();

        Doc doc = new Doc(
          Name: "csharp-async.pdf",
          Test: true,
          DocumentContent: "<html><body>Hello from C#</body></html>",
          DocumentType: Doc.DocumentTypeEnum.Pdf
        );

        AsyncDoc response = docraptor.CreateAsyncDoc(doc);

        AsyncDocStatus status_response;
        while(true) {
          status_response = docraptor.GetAsyncDocStatus(response.StatusId);
          if (status_response.Status == "completed") {
        break;
          }
          Thread.Sleep(1000);
        }

        docraptor.GetAsyncDoc(status_response.DownloadId);
    }
Example #3
0
    static void Main(string[] args)
    {
        try {
          Configuration.Default.Username = "******"; // this key works for test documents
          DocApi docraptor = new DocApi();

          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.CreateAsyncDoc(doc);

          AsyncDocStatus status_response;
          Boolean done = false;
          while(!done) {
        status_response = docraptor.GetAsyncDocStatus(response.StatusId);
        Console.WriteLine("doc status: " + status_response.Status);
        switch(status_response.Status) {
          case "completed":
            done = true;
            byte[] doc_response = docraptor.GetAsyncDoc(status_response.DownloadId);
            File.WriteAllBytes("/tmp/docraptor-csharp.pdf", doc_response);
            Console.WriteLine("Wrote PDF to /tmp/docraptor-csharp.pdf");
            break;
          case "failed":
            done = true;
            Console.WriteLine("FAILED");
            Console.WriteLine(status_response);
            break;
          default:
            Thread.Sleep(1000);
            break;
        }
          }
        } catch (DocRaptor.Client.ApiException error) {
          Console.WriteLine(error);
        }
    }