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
                // )
                );

            byte[] create_response = docraptor.CreateDoc(doc);
            File.WriteAllBytes("/tmp/docraptor-csharp.pdf", create_response);
            Console.WriteLine("Wrote PDF to /tmp/docraptor-csharp.pdf");
        } catch (DocRaptor.Client.ApiException error) {
            Console.WriteLine(error);
        }
    }
    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
                // )
                );

            DocStatus statusResponse = docraptor.CreateHostedDoc(doc);
            Console.WriteLine("Hosted Async Download URL: " + statusResponse.DownloadUrl);
        } catch (DocRaptor.Client.ApiException error) {
            Console.WriteLine(error);
        }
    }
Beispiel #3
0
    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-async.pdf",
            test: true,
            documentContent: "<html><body>Hello from C#</body></html>",
            documentType: Doc.DocumentTypeEnum.Pdf
            );

        AsyncDoc response = docraptor.CreateAsyncDoc(doc);

        DocStatus statusResponse;

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

        docraptor.GetAsyncDoc(statusResponse.DownloadId);
    }
Beispiel #4
0
    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-sync.pdf",
            test: true,
            documentContent: "<html><body>Hello from C#</body></html>",
            documentType: Doc.DocumentTypeEnum.Pdf
            );

        DocStatus statusResponse = docraptor.CreateHostedDoc(doc);
        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);
        }
    }
Beispiel #5
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: 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);
    }
        protected void lnkPrintInvoice_Click(object sender, EventArgs e)
        {
            bool blnPrinted = false;

            try
            {
                Configuration.Default.Username = "******";
                DocApi docraptor = new DocApi();

                Doc doc = new Doc(
                    Test: true,
                    Name: "docraptor-csharp.pdf",
                    DocumentType: Doc.DocumentTypeEnum.Pdf,
                    DocumentContent: GetInvoiceContent()//,
                    //PrinceOptions: new PrinceOptions(Media: "screen")
                    );

                byte[] create_response = docraptor.CreateDoc(doc);
                File.WriteAllBytes(@"C:\temp\invoiceDownloads\invoice.pdf", create_response);
                blnPrinted = true;
            }
            catch (Exception ex) when(!blnPrinted)
            {
                AlertMessage(ex.Message, MessageType.Error);
            }
            finally
            {
                if (blnPrinted)
                {
                    lblPrintDetails.Text = "Your Invoice has been printed.";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), "TogglePrintResult();", true);
                }
            }
        }
        public async Task <ActionResult> Post([FromBody] PrintDetail print)
        {
            try
            {
                Configuration.Default.Username = "******";
                var docraptor = new DocApi();

                var princeOptions = new PrinceOptions
                {
                    Baseurl = print.BaseUrl
                };

                var doc = new Doc(
                    Test: print.Test,
                    DocumentContent: print.Content,
                    Name:  print.Name,
                    DocumentType: Doc.DocumentTypeEnum.Pdf
                    );
                doc.PrinceOptions = princeOptions;

                byte[] create_response = await docraptor.CreateDocAsync(doc);

                Response.Headers.Add("Access-Control-Allow-Origin", "*");
                Response.Headers.Add("Access-Control-Allow-Credentials", "true");

                return(File(create_response, "application/pdf"));
            }
            catch (Exception ex)
            {
                return(new ObjectResult(ex.Message));
            }
        }
Beispiel #8
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);
        }
    }
    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-xlsx.xlsx",
            Test: true,
            DocumentContent: "<html><body><table><tr><td>Hello from C#</td></tr></table></body></html>",
            DocumentType: Doc.DocumentTypeEnum.Xlsx
            );

        docraptor.CreateDoc(doc);
    }
Beispiel #10
0
    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-sync.pdf",
            test: true,
            documentContent: "<html><body>Hello from C#</body></html>",
            documentType: Doc.DocumentTypeEnum.Pdf
            );

        docraptor.CreateDoc(doc);
    }
Beispiel #11
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: new String('s', 201), // limit is 200 characters
            Test: true,
            DocumentContent: "<html><body>Hello from C#</body></html>",
            DocumentType: Doc.DocumentTypeEnum.Pdf
            );

        try {
            docraptor.CreateDoc(doc);
        } catch (DocRaptor.Client.ApiException) {
            Environment.Exit(0);
        }
        Console.WriteLine("Exception expected, but not raised");
        Environment.Exit(1);
    }