diff --git a/DotNET/Complex Flow Examples/decrypt-add-reencrypt.cs b/DotNET/Complex Flow Examples/decrypt-add-reencrypt.cs index 98ddc72..aaca601 100644 --- a/DotNET/Complex Flow Examples/decrypt-add-reencrypt.cs +++ b/DotNET/Complex Flow Examples/decrypt-add-reencrypt.cs @@ -14,87 +14,86 @@ using (var httpClient = new HttpClient { BaseAddress = new Uri("https://api.pdfrest.com") }) { - using (var decryptRequest = new HttpRequestMessage(HttpMethod.Post, "decrypted-pdf")) - { - decryptRequest.Headers.TryAddWithoutValidation("Api-Key", apiKey); - decryptRequest.Headers.Accept.Add(new("application/json")); - var decryptMultipartContent = new MultipartFormDataContent(); + // Begin decryption + var decryptRequest = new HttpRequestMessage(HttpMethod.Post, "decrypted-pdf"); - var byteArray = File.ReadAllBytes("/path/to/file.pdf"); - var byteAryContent = new ByteArrayContent(byteArray); - decryptMultipartContent.Add(byteAryContent, "file", "file.pdf"); - byteAryContent.Headers.TryAddWithoutValidation("Content-Type", "application/pdf"); + decryptRequest.Headers.TryAddWithoutValidation("Api-Key", apiKey); + decryptRequest.Headers.Accept.Add(new("application/json")); + var decryptMultipartContent = new MultipartFormDataContent(); - var byteArrayOption = new ByteArrayContent(Encoding.UTF8.GetBytes("password")); - decryptMultipartContent.Add(byteArrayOption, "current_open_password"); + var byteArray = File.ReadAllBytes("/path/to/file.pdf"); + var byteAryContent = new ByteArrayContent(byteArray); + decryptMultipartContent.Add(byteAryContent, "file", "file.pdf"); + byteAryContent.Headers.TryAddWithoutValidation("Content-Type", "application/pdf"); + var byteArrayOption = new ByteArrayContent(Encoding.UTF8.GetBytes("password")); + decryptMultipartContent.Add(byteArrayOption, "current_open_password"); - decryptRequest.Content = decryptMultipartContent; - var decryptResponse = await httpClient.SendAsync(decryptRequest); - var decryptResult = await decryptResponse.Content.ReadAsStringAsync(); + decryptRequest.Content = decryptMultipartContent; + var decryptResponse = await httpClient.SendAsync(decryptRequest); - Console.WriteLine("Decrypt response received."); - Console.WriteLine(decryptResult); + var decryptResult = await decryptResponse.Content.ReadAsStringAsync(); - dynamic decryptJson = JObject.Parse(decryptResult); - string decryptID = decryptJson.outputId; + Console.WriteLine("Decrypt response received."); + Console.WriteLine(decryptResult); + dynamic decryptJson = JObject.Parse(decryptResult); + string decryptID = decryptJson.outputId; - using (var addImageRequest = new HttpRequestMessage(HttpMethod.Post, "pdf-with-added-image")) - { - addImageRequest.Headers.TryAddWithoutValidation("Api-Key", apiKey); - addImageRequest.Headers.Accept.Add(new("application/json")); - var addImageMultipartContent = new MultipartFormDataContent(); + // Begin add image + var addImageRequest = new HttpRequestMessage(HttpMethod.Post, "pdf-with-added-image"); - var addImageId = new ByteArrayContent(Encoding.UTF8.GetBytes(decryptID)); - addImageMultipartContent.Add(addImageId, "id"); + addImageRequest.Headers.TryAddWithoutValidation("Api-Key", apiKey); + addImageRequest.Headers.Accept.Add(new("application/json")); + var addImageMultipartContent = new MultipartFormDataContent(); - var addImageImage = File.ReadAllBytes("/path/to/file.png"); - var imageContent = new ByteArrayContent(addImageImage); - addImageMultipartContent.Add(imageContent, "image_file", "file_name.png"); - imageContent.Headers.TryAddWithoutValidation("Content-Type", "image/png"); + var addImageId = new ByteArrayContent(Encoding.UTF8.GetBytes(decryptID)); + addImageMultipartContent.Add(addImageId, "id"); - var addImagePage = new ByteArrayContent(Encoding.UTF8.GetBytes("1")); - addImageMultipartContent.Add(addImagePage, "page"); + var addImageImage = File.ReadAllBytes("/path/to/file.png"); + var imageContent = new ByteArrayContent(addImageImage); + addImageMultipartContent.Add(imageContent, "image_file", "file_name.png"); + imageContent.Headers.TryAddWithoutValidation("Content-Type", "image/png"); - var addImageX = new ByteArrayContent(Encoding.UTF8.GetBytes("0")); - addImageMultipartContent.Add(addImageX, "x"); - var addImageY = new ByteArrayContent(Encoding.UTF8.GetBytes("0")); - addImageMultipartContent.Add(addImageY, "y"); + var addImagePage = new ByteArrayContent(Encoding.UTF8.GetBytes("1")); + addImageMultipartContent.Add(addImagePage, "page"); - addImageRequest.Content = addImageMultipartContent; - var addImageResponse = await httpClient.SendAsync(addImageRequest); + var addImageX = new ByteArrayContent(Encoding.UTF8.GetBytes("0")); + addImageMultipartContent.Add(addImageX, "x"); + var addImageY = new ByteArrayContent(Encoding.UTF8.GetBytes("0")); + addImageMultipartContent.Add(addImageY, "y"); - var addImageResult = await addImageResponse.Content.ReadAsStringAsync(); + addImageRequest.Content = addImageMultipartContent; + var addImageResponse = await httpClient.SendAsync(addImageRequest); - Console.WriteLine("Add image response received."); - Console.WriteLine(addImageResult); + var addImageResult = await addImageResponse.Content.ReadAsStringAsync(); - dynamic addImageJson = JObject.Parse(addImageResult); - string addImageID = addImageJson.outputId; + Console.WriteLine("Add image response received."); + Console.WriteLine(addImageResult); - using (var encryptRequest = new HttpRequestMessage(HttpMethod.Post, "encrypted-pdf")) - { - encryptRequest.Headers.TryAddWithoutValidation("Api-Key", apiKey); - encryptRequest.Headers.Accept.Add(new("application/json")); - var multipartContent = new MultipartFormDataContent(); + dynamic addImageJson = JObject.Parse(addImageResult); + string addImageID = addImageJson.outputId; - var encryptID = new ByteArrayContent(Encoding.UTF8.GetBytes(addImageID)); - multipartContent.Add(encryptID, "id"); + // Begin re-encryption + var encryptRequest = new HttpRequestMessage(HttpMethod.Post, "encrypted-pdf"); - var encryptPassword = new ByteArrayContent(Encoding.UTF8.GetBytes("password")); - multipartContent.Add(encryptPassword, "new_open_password"); + encryptRequest.Headers.TryAddWithoutValidation("Api-Key", apiKey); + encryptRequest.Headers.Accept.Add(new("application/json")); + var multipartContent = new MultipartFormDataContent(); + var encryptID = new ByteArrayContent(Encoding.UTF8.GetBytes(addImageID)); + multipartContent.Add(encryptID, "id"); - encryptRequest.Content = multipartContent; - var response = await httpClient.SendAsync(encryptRequest); + var encryptPassword = new ByteArrayContent(Encoding.UTF8.GetBytes("password")); + multipartContent.Add(encryptPassword, "new_open_password"); - var apiResult = await response.Content.ReadAsStringAsync(); - Console.WriteLine("Encrypt response received."); - Console.WriteLine(apiResult); - } - } - } + encryptRequest.Content = multipartContent; + var response = await httpClient.SendAsync(encryptRequest); + + var apiResult = await response.Content.ReadAsStringAsync(); + + Console.WriteLine("Encrypt response received."); + Console.WriteLine(apiResult); } diff --git a/DotNET/Complex Flow Examples/merge-different-file-types.cs b/DotNET/Complex Flow Examples/merge-different-file-types.cs index f229659..3b101cd 100644 --- a/DotNET/Complex Flow Examples/merge-different-file-types.cs +++ b/DotNET/Complex Flow Examples/merge-different-file-types.cs @@ -17,82 +17,80 @@ using (var httpClient = new HttpClient { BaseAddress = new Uri("https://api.pdfrest.com") }) { - using (var imageRequest = new HttpRequestMessage(HttpMethod.Post, "pdf")) - { - imageRequest.Headers.TryAddWithoutValidation("Api-Key", apiKey); - imageRequest.Headers.Accept.Add(new("application/json")); - var imageMultipartContent = new MultipartFormDataContent(); + // Begin first PDF conversion + var imageRequest = new HttpRequestMessage(HttpMethod.Post, "pdf"); - var imageByteArray = File.ReadAllBytes("/path/to/file.png"); - var imageByteAryContent = new ByteArrayContent(imageByteArray); - imageMultipartContent.Add(imageByteAryContent, "file", "file.png"); - imageByteAryContent.Headers.TryAddWithoutValidation("Content-Type", "image/x-png"); + imageRequest.Headers.TryAddWithoutValidation("Api-Key", apiKey); + imageRequest.Headers.Accept.Add(new("application/json")); + var imageMultipartContent = new MultipartFormDataContent(); - imageRequest.Content = imageMultipartContent; - var imageResponse = await httpClient.SendAsync(imageRequest); + var imageByteArray = File.ReadAllBytes("/path/to/file.png"); + var imageByteAryContent = new ByteArrayContent(imageByteArray); + imageMultipartContent.Add(imageByteAryContent, "file", "file.png"); + imageByteAryContent.Headers.TryAddWithoutValidation("Content-Type", "image/x-png"); - var imageResult = await imageResponse.Content.ReadAsStringAsync(); - Console.WriteLine("Image to PDF response received."); - Console.WriteLine(imageResult); + imageRequest.Content = imageMultipartContent; + var imageResponse = await httpClient.SendAsync(imageRequest); - dynamic imageResponseData = JObject.Parse(imageResult); - string imageID = imageResponseData.outputId; + var imageResult = await imageResponse.Content.ReadAsStringAsync(); + Console.WriteLine("Image to PDF response received."); + Console.WriteLine(imageResult); - using (var powerpointRequest = new HttpRequestMessage(HttpMethod.Post, "pdf")) - { - powerpointRequest.Headers.TryAddWithoutValidation("Api-Key", apiKey); - powerpointRequest.Headers.Accept.Add(new("application/json")); - var powerpointMultipartContent = new MultipartFormDataContent(); + dynamic imageResponseData = JObject.Parse(imageResult); + string imageID = imageResponseData.outputId; - var powerpointByteArray = File.ReadAllBytes("/path/to/file.ppt"); - var powerpointByteAryContent = new ByteArrayContent(powerpointByteArray); - powerpointMultipartContent.Add(powerpointByteAryContent, "file", "file.ppt"); - powerpointByteAryContent.Headers.TryAddWithoutValidation("Content-Type", "application/vnd.ms-powerpoint"); + // Begin second PDF conversion + var powerpointRequest = new HttpRequestMessage(HttpMethod.Post, "pdf"); - powerpointRequest.Content = powerpointMultipartContent; - var powerpointResponse = await httpClient.SendAsync(powerpointRequest); + powerpointRequest.Headers.TryAddWithoutValidation("Api-Key", apiKey); + powerpointRequest.Headers.Accept.Add(new("application/json")); + var powerpointMultipartContent = new MultipartFormDataContent(); - var powerpointResult = await powerpointResponse.Content.ReadAsStringAsync(); - Console.WriteLine("powerpoint to PDF response received."); - Console.WriteLine(powerpointResult); + var powerpointByteArray = File.ReadAllBytes("/path/to/file.ppt"); + var powerpointByteAryContent = new ByteArrayContent(powerpointByteArray); + powerpointMultipartContent.Add(powerpointByteAryContent, "file", "file.ppt"); + powerpointByteAryContent.Headers.TryAddWithoutValidation("Content-Type", "application/vnd.ms-powerpoint"); - dynamic powerpointResponseData = JObject.Parse(powerpointResult); - string powerpointID = powerpointResponseData.outputId; + powerpointRequest.Content = powerpointMultipartContent; + var powerpointResponse = await httpClient.SendAsync(powerpointRequest); - using (var request = new HttpRequestMessage(HttpMethod.Post, "merged-pdf")) - { - request.Headers.TryAddWithoutValidation("Api-Key", apiKey); - request.Headers.Accept.Add(new("application/json")); - var multipartContent = new MultipartFormDataContent(); + var powerpointResult = await powerpointResponse.Content.ReadAsStringAsync(); + Console.WriteLine("powerpoint to PDF response received."); + Console.WriteLine(powerpointResult); + dynamic powerpointResponseData = JObject.Parse(powerpointResult); + string powerpointID = powerpointResponseData.outputId; - var imageByteArrayID = new ByteArrayContent(Encoding.UTF8.GetBytes(imageID)); - multipartContent.Add(imageByteArrayID, "id[]"); + // Begin file merge + var request = new HttpRequestMessage(HttpMethod.Post, "merged-pdf"); - var byteArrayOption = new ByteArrayContent(Encoding.UTF8.GetBytes("id")); - multipartContent.Add(byteArrayOption, "type[]"); - var byteArrayOption2 = new ByteArrayContent(Encoding.UTF8.GetBytes("all")); - multipartContent.Add(byteArrayOption2, "pages[]"); + request.Headers.TryAddWithoutValidation("Api-Key", apiKey); + request.Headers.Accept.Add(new("application/json")); + var multipartContent = new MultipartFormDataContent(); - var powerpointByteArrayID = new ByteArrayContent(Encoding.UTF8.GetBytes(powerpointID)); - multipartContent.Add(powerpointByteArrayID, "id[]"); + var imageByteArrayID = new ByteArrayContent(Encoding.UTF8.GetBytes(imageID)); + multipartContent.Add(imageByteArrayID, "id[]"); - var byteArrayOption3 = new ByteArrayContent(Encoding.UTF8.GetBytes("id")); - multipartContent.Add(byteArrayOption3, "type[]"); - var byteArrayOption4 = new ByteArrayContent(Encoding.UTF8.GetBytes("all")); - multipartContent.Add(byteArrayOption4, "pages[]"); + var byteArrayOption = new ByteArrayContent(Encoding.UTF8.GetBytes("id")); + multipartContent.Add(byteArrayOption, "type[]"); + var byteArrayOption2 = new ByteArrayContent(Encoding.UTF8.GetBytes("all")); + multipartContent.Add(byteArrayOption2, "pages[]"); - request.Content = multipartContent; - var response = await httpClient.SendAsync(request); - var apiResult = await response.Content.ReadAsStringAsync(); + var powerpointByteArrayID = new ByteArrayContent(Encoding.UTF8.GetBytes(powerpointID)); + multipartContent.Add(powerpointByteArrayID, "id[]"); - Console.WriteLine("Merge response received."); - Console.WriteLine(apiResult); - } + var byteArrayOption3 = new ByteArrayContent(Encoding.UTF8.GetBytes("id")); + multipartContent.Add(byteArrayOption3, "type[]"); + var byteArrayOption4 = new ByteArrayContent(Encoding.UTF8.GetBytes("all")); + multipartContent.Add(byteArrayOption4, "pages[]"); + request.Content = multipartContent; + var response = await httpClient.SendAsync(request); - } - } + var apiResult = await response.Content.ReadAsStringAsync(); + + Console.WriteLine("Merge response received."); + Console.WriteLine(apiResult); } diff --git a/DotNET/Complex Flow Examples/pdfa-3b-with-attachment.cs b/DotNET/Complex Flow Examples/pdfa-3b-with-attachment.cs index 5f0be31..88e25b9 100644 --- a/DotNET/Complex Flow Examples/pdfa-3b-with-attachment.cs +++ b/DotNET/Complex Flow Examples/pdfa-3b-with-attachment.cs @@ -15,53 +15,53 @@ using (var httpClient = new HttpClient { BaseAddress = new Uri("https://api.pdfrest.com") }) { - using (var attachRequest = new HttpRequestMessage(HttpMethod.Post, "pdf-with-added-attachment")) - { - attachRequest.Headers.TryAddWithoutValidation("Api-Key", apiKey); - attachRequest.Headers.Accept.Add(new("application/json")); - var attachMultipartContent = new MultipartFormDataContent(); + // Begin file attachment + var attachRequest = new HttpRequestMessage(HttpMethod.Post, "pdf-with-added-attachment"); - var byteArray = File.ReadAllBytes("/path/to/file.pdf"); - var byteAryContent = new ByteArrayContent(byteArray); - attachMultipartContent.Add(byteAryContent, "file", "file_name.pdf"); - byteAryContent.Headers.TryAddWithoutValidation("Content-Type", "application/pdf"); + attachRequest.Headers.TryAddWithoutValidation("Api-Key", apiKey); + attachRequest.Headers.Accept.Add(new("application/json")); + var attachMultipartContent = new MultipartFormDataContent(); - var byteArray2 = File.ReadAllBytes("/path/to/file.xml"); - var byteAryContent2 = new ByteArrayContent(byteArray2); - attachMultipartContent.Add(byteAryContent2, "file_to_attach", "file_name.xml"); - byteAryContent2.Headers.TryAddWithoutValidation("Content-Type", "application/xml"); + var byteArray = File.ReadAllBytes("/path/to/file.pdf"); + var byteAryContent = new ByteArrayContent(byteArray); + attachMultipartContent.Add(byteAryContent, "file", "file_name.pdf"); + byteAryContent.Headers.TryAddWithoutValidation("Content-Type", "application/pdf"); - attachRequest.Content = attachMultipartContent; - var attachResponse = await httpClient.SendAsync(attachRequest); + var byteArray2 = File.ReadAllBytes("/path/to/file.xml"); + var byteAryContent2 = new ByteArrayContent(byteArray2); + attachMultipartContent.Add(byteAryContent2, "file_to_attach", "file_name.xml"); + byteAryContent2.Headers.TryAddWithoutValidation("Content-Type", "application/xml"); - var attachResult = await attachResponse.Content.ReadAsStringAsync(); - Console.WriteLine("Attachement response received."); - Console.WriteLine(attachResult); + attachRequest.Content = attachMultipartContent; + var attachResponse = await httpClient.SendAsync(attachRequest); - dynamic responseData = JObject.Parse(attachResult); - string attachementID = responseData.outputId; + var attachResult = await attachResponse.Content.ReadAsStringAsync(); + Console.WriteLine("Attachement response received."); + Console.WriteLine(attachResult); - using (var request = new HttpRequestMessage(HttpMethod.Post, "pdfa")) - { - request.Headers.TryAddWithoutValidation("Api-Key", apiKey); - request.Headers.Accept.Add(new("application/json")); - var multipartContent = new MultipartFormDataContent(); + dynamic responseData = JObject.Parse(attachResult); + string attachementID = responseData.outputId; + // Begin PDF/A conversion + var pdfaRequest = new HttpRequestMessage(HttpMethod.Post, "pdfa"); - var byteArrayOption = new ByteArrayContent(Encoding.UTF8.GetBytes(attachementID)); - multipartContent.Add(byteArrayOption, "id"); + pdfaRequest.Headers.TryAddWithoutValidation("Api-Key", apiKey); + pdfaRequest.Headers.Accept.Add(new("application/json")); + var multipartContent = new MultipartFormDataContent(); - var byteArrayOption2 = new ByteArrayContent(Encoding.UTF8.GetBytes("PDF/A-3b")); - multipartContent.Add(byteArrayOption2, "output_type"); + var byteArrayOption = new ByteArrayContent(Encoding.UTF8.GetBytes(attachementID)); + multipartContent.Add(byteArrayOption, "id"); - request.Content = multipartContent; - var response = await httpClient.SendAsync(request); + var byteArrayOption2 = new ByteArrayContent(Encoding.UTF8.GetBytes("PDF/A-3b")); + multipartContent.Add(byteArrayOption2, "output_type"); - var apiResult = await response.Content.ReadAsStringAsync(); - Console.WriteLine("PDF/A response received."); - Console.WriteLine(apiResult); - } - } + pdfaRequest.Content = multipartContent; + var response = await httpClient.SendAsync(pdfaRequest); + + var apiResult = await response.Content.ReadAsStringAsync(); + + Console.WriteLine("PDF/A response received."); + Console.WriteLine(apiResult); } diff --git a/DotNET/Complex Flow Examples/preserve-word-document.cs b/DotNET/Complex Flow Examples/preserve-word-document.cs index d10a11a..ef97823 100644 --- a/DotNET/Complex Flow Examples/preserve-word-document.cs +++ b/DotNET/Complex Flow Examples/preserve-word-document.cs @@ -12,48 +12,51 @@ using (var httpClient = new HttpClient { BaseAddress = new Uri("https://api.pdfrest.com") }) { - using (var pdfRequest = new HttpRequestMessage(HttpMethod.Post, "pdf")) - { - pdfRequest.Headers.TryAddWithoutValidation("Api-Key", apiKey); - pdfRequest.Headers.Accept.Add(new("application/json")); - var pdfMultipartContent = new MultipartFormDataContent(); - var byteArray = File.ReadAllBytes("/path/to/file.doc"); - var byteAryContent = new ByteArrayContent(byteArray); - pdfMultipartContent.Add(byteAryContent, "file", "file_name.doc"); - byteAryContent.Headers.TryAddWithoutValidation("Content-Type", "application/msword"); + // Begin PDF conversion + var pdfRequest = new HttpRequestMessage(HttpMethod.Post, "pdf"); - pdfRequest.Content = pdfMultipartContent; - var pdfResponse = await httpClient.SendAsync(pdfRequest); + pdfRequest.Headers.TryAddWithoutValidation("Api-Key", apiKey); + pdfRequest.Headers.Accept.Add(new("application/json")); + var pdfMultipartContent = new MultipartFormDataContent(); - var pdfResult = await pdfResponse.Content.ReadAsStringAsync(); - Console.WriteLine("PDF response received."); - Console.WriteLine(pdfResult); + var byteArray = File.ReadAllBytes("/path/to/file.doc"); + var byteAryContent = new ByteArrayContent(byteArray); + pdfMultipartContent.Add(byteAryContent, "file", "file_name.doc"); + byteAryContent.Headers.TryAddWithoutValidation("Content-Type", "application/msword"); - dynamic responseData = JObject.Parse(pdfResult); - string pdfID = responseData.outputId; + pdfRequest.Content = pdfMultipartContent; + var pdfResponse = await httpClient.SendAsync(pdfRequest); - using (var request = new HttpRequestMessage(HttpMethod.Post, "pdfa")) - { - request.Headers.TryAddWithoutValidation("Api-Key", apiKey); - request.Headers.Accept.Add(new("application/json")); - var multipartContent = new MultipartFormDataContent(); + var pdfResult = await pdfResponse.Content.ReadAsStringAsync(); + Console.WriteLine("PDF response received."); + Console.WriteLine(pdfResult); + dynamic responseData = JObject.Parse(pdfResult); + string pdfID = responseData.outputId; - var byteArrayOption = new ByteArrayContent(Encoding.UTF8.GetBytes(pdfID)); - multipartContent.Add(byteArrayOption, "id"); + // Begin PDF/A conversion + var pdfaRequest = new HttpRequestMessage(HttpMethod.Post, "pdfa"); - var byteArrayOption2 = new ByteArrayContent(Encoding.UTF8.GetBytes("PDF/A-3b")); - multipartContent.Add(byteArrayOption2, "output_type"); + pdfaRequest.Headers.TryAddWithoutValidation("Api-Key", apiKey); + pdfaRequest.Headers.Accept.Add(new("application/json")); + var multipartContent = new MultipartFormDataContent(); - request.Content = multipartContent; - var response = await httpClient.SendAsync(request); + var byteArrayOption = new ByteArrayContent(Encoding.UTF8.GetBytes(pdfID)); + multipartContent.Add(byteArrayOption, "id"); + + var byteArrayOption2 = new ByteArrayContent(Encoding.UTF8.GetBytes("PDF/A-3b")); + multipartContent.Add(byteArrayOption2, "output_type"); + + + pdfaRequest.Content = multipartContent; + var response = await httpClient.SendAsync(pdfaRequest); + + var apiResult = await response.Content.ReadAsStringAsync(); + + Console.WriteLine("PDF/A response received."); + Console.WriteLine(apiResult); - var apiResult = await response.Content.ReadAsStringAsync(); - Console.WriteLine("PDF/A response received."); - Console.WriteLine(apiResult); - } - } } diff --git a/DotNET/Complex Flow Examples/protected-watermark.cs b/DotNET/Complex Flow Examples/protected-watermark.cs index 855fd11..d6ea3af 100644 --- a/DotNET/Complex Flow Examples/protected-watermark.cs +++ b/DotNET/Complex Flow Examples/protected-watermark.cs @@ -13,57 +13,57 @@ using (var httpClient = new HttpClient { BaseAddress = new Uri("https://api.pdfrest.com") }) { - using (var watermarkRequest = new HttpRequestMessage(HttpMethod.Post, "watermarked-pdf")) - { - watermarkRequest.Headers.TryAddWithoutValidation("Api-Key", apiKey); - watermarkRequest.Headers.Accept.Add(new("application/json")); - var watermarkMultipartContent = new MultipartFormDataContent(); + // Begin watermarking + var watermarkRequest = new HttpRequestMessage(HttpMethod.Post, "watermarked-pdf"); - var watermarkByteArray = File.ReadAllBytes("/path/to/file.pdf"); - var watermarkByteAryContent = new ByteArrayContent(watermarkByteArray); - watermarkMultipartContent.Add(watermarkByteAryContent, "file", "file.pdf"); - watermarkByteAryContent.Headers.TryAddWithoutValidation("Content-Type", "application/pdf"); + watermarkRequest.Headers.TryAddWithoutValidation("Api-Key", apiKey); + watermarkRequest.Headers.Accept.Add(new("application/json")); + var watermarkMultipartContent = new MultipartFormDataContent(); - var watermarkByteArrayOption = new ByteArrayContent(Encoding.UTF8.GetBytes("Watermarked")); - watermarkMultipartContent.Add(watermarkByteArrayOption, "watermark_text"); + var watermarkByteArray = File.ReadAllBytes("/path/to/file.pdf"); + var watermarkByteAryContent = new ByteArrayContent(watermarkByteArray); + watermarkMultipartContent.Add(watermarkByteAryContent, "file", "file.pdf"); + watermarkByteAryContent.Headers.TryAddWithoutValidation("Content-Type", "application/pdf"); - watermarkRequest.Content = watermarkMultipartContent; - var watermarkResponse = await httpClient.SendAsync(watermarkRequest); + var watermarkByteArrayOption = new ByteArrayContent(Encoding.UTF8.GetBytes("Watermarked")); + watermarkMultipartContent.Add(watermarkByteArrayOption, "watermark_text"); - var watermarkResult = await watermarkResponse.Content.ReadAsStringAsync(); - Console.WriteLine("Watermark to PDF response received."); - Console.WriteLine(watermarkResult); + watermarkRequest.Content = watermarkMultipartContent; + var watermarkResponse = await httpClient.SendAsync(watermarkRequest); - dynamic watermarkResponseData = JObject.Parse(watermarkResult); - string watermarkID = watermarkResponseData.outputId; + var watermarkResult = await watermarkResponse.Content.ReadAsStringAsync(); + Console.WriteLine("Watermark to PDF response received."); + Console.WriteLine(watermarkResult); - using (var restrictRequest = new HttpRequestMessage(HttpMethod.Post, "restricted-pdf")) - { - restrictRequest.Headers.TryAddWithoutValidation("Api-Key", apiKey); - restrictRequest.Headers.Accept.Add(new("application/json")); - var restrictMultipartContent = new MultipartFormDataContent(); + dynamic watermarkResponseData = JObject.Parse(watermarkResult); + string watermarkID = watermarkResponseData.outputId; - var watermarkIDByteArrayOption = new ByteArrayContent(Encoding.UTF8.GetBytes(watermarkID)); - restrictMultipartContent.Add(watermarkIDByteArrayOption, "id"); + // Begin restricting + var restrictRequest = new HttpRequestMessage(HttpMethod.Post, "restricted-pdf"); - var byteArrayOption = new ByteArrayContent(Encoding.UTF8.GetBytes("password")); - restrictMultipartContent.Add(byteArrayOption, "new_permissions_password"); + restrictRequest.Headers.TryAddWithoutValidation("Api-Key", apiKey); + restrictRequest.Headers.Accept.Add(new("application/json")); + var restrictMultipartContent = new MultipartFormDataContent(); - var byteArrayOption2 = new ByteArrayContent(Encoding.UTF8.GetBytes("copy_content")); - restrictMultipartContent.Add(byteArrayOption2, "restrictions[]"); - var byteArrayOption3 = new ByteArrayContent(Encoding.UTF8.GetBytes("edit_content")); - restrictMultipartContent.Add(byteArrayOption3, "restrictions[]"); - var byteArrayOption4 = new ByteArrayContent(Encoding.UTF8.GetBytes("edit_annotations")); - restrictMultipartContent.Add(byteArrayOption3, "restrictions[]"); + var watermarkIDByteArrayOption = new ByteArrayContent(Encoding.UTF8.GetBytes(watermarkID)); + restrictMultipartContent.Add(watermarkIDByteArrayOption, "id"); + var byteArrayOption = new ByteArrayContent(Encoding.UTF8.GetBytes("password")); + restrictMultipartContent.Add(byteArrayOption, "new_permissions_password"); - restrictRequest.Content = restrictMultipartContent; - var restrictResponse = await httpClient.SendAsync(restrictRequest); + var byteArrayOption2 = new ByteArrayContent(Encoding.UTF8.GetBytes("copy_content")); + restrictMultipartContent.Add(byteArrayOption2, "restrictions[]"); + var byteArrayOption3 = new ByteArrayContent(Encoding.UTF8.GetBytes("edit_content")); + restrictMultipartContent.Add(byteArrayOption3, "restrictions[]"); + var byteArrayOption4 = new ByteArrayContent(Encoding.UTF8.GetBytes("edit_annotations")); + restrictMultipartContent.Add(byteArrayOption3, "restrictions[]"); - var apiResult = await restrictResponse.Content.ReadAsStringAsync(); - Console.WriteLine("Restrict response received."); - Console.WriteLine(apiResult); - } - } + restrictRequest.Content = restrictMultipartContent; + var restrictResponse = await httpClient.SendAsync(restrictRequest); + + var apiResult = await restrictResponse.Content.ReadAsStringAsync(); + + Console.WriteLine("Restrict response received."); + Console.WriteLine(apiResult); }