diff --git a/Delete Text From PDF/C#/Remove And Blackout Credit Card Data From PDF/ByteScoutWebApiExample.NETCore.csproj b/Delete Text From PDF/C#/Remove And Blackout Credit Card Data From PDF/ByteScoutWebApiExample.NETCore.csproj new file mode 100644 index 000000000..82e9705c7 --- /dev/null +++ b/Delete Text From PDF/C#/Remove And Blackout Credit Card Data From PDF/ByteScoutWebApiExample.NETCore.csproj @@ -0,0 +1,35 @@ + + + + Exe + netcoreapp2.0 + false + false + false + false + false + false + false + false + false + false + false + false + + + + + + + + + + + + + + + Always + + + \ No newline at end of file diff --git a/Delete Text From PDF/C#/Remove And Blackout Credit Card Data From PDF/ByteScoutWebApiExample.NETCore.sln b/Delete Text From PDF/C#/Remove And Blackout Credit Card Data From PDF/ByteScoutWebApiExample.NETCore.sln new file mode 100644 index 000000000..6527b80b4 --- /dev/null +++ b/Delete Text From PDF/C#/Remove And Blackout Credit Card Data From PDF/ByteScoutWebApiExample.NETCore.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.32126.317 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ByteScoutWebApiExample.NETCore", "ByteScoutWebApiExample.NETCore.csproj", "{6C67B480-C7E2-4AF7-AE7B-0E12A5799D9C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6C67B480-C7E2-4AF7-AE7B-0E12A5799D9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6C67B480-C7E2-4AF7-AE7B-0E12A5799D9C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6C67B480-C7E2-4AF7-AE7B-0E12A5799D9C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6C67B480-C7E2-4AF7-AE7B-0E12A5799D9C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {FBAE862B-1737-4E3F-96CF-5B8772A7AC09} + EndGlobalSection +EndGlobal diff --git a/Delete Text From PDF/C#/Remove And Blackout Credit Card Data From PDF/ByteScoutWebApiExample.csproj b/Delete Text From PDF/C#/Remove And Blackout Credit Card Data From PDF/ByteScoutWebApiExample.csproj new file mode 100644 index 000000000..c5130112c --- /dev/null +++ b/Delete Text From PDF/C#/Remove And Blackout Credit Card Data From PDF/ByteScoutWebApiExample.csproj @@ -0,0 +1,63 @@ + + + + + Debug + AnyCPU + {1E1C2C34-017E-4605-AE2B-55EA3313BE51} + Exe + Properties + ByteScoutWebApiExample + ByteScoutWebApiExample + v4.6 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + packages\Newtonsoft.Json.10.0.3\lib\net40\Newtonsoft.Json.dll + True + + + + + + + + + + + + + + + Always + + + + + \ No newline at end of file diff --git a/Delete Text From PDF/C#/Remove And Blackout Credit Card Data From PDF/ByteScoutWebApiExample.sln b/Delete Text From PDF/C#/Remove And Blackout Credit Card Data From PDF/ByteScoutWebApiExample.sln new file mode 100644 index 000000000..44721634f --- /dev/null +++ b/Delete Text From PDF/C#/Remove And Blackout Credit Card Data From PDF/ByteScoutWebApiExample.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.40629.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ByteScoutWebApiExample", "ByteScoutWebApiExample.csproj", "{1E1C2C34-017E-4605-AE2B-55EA3313BE51}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1E1C2C34-017E-4605-AE2B-55EA3313BE51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1E1C2C34-017E-4605-AE2B-55EA3313BE51}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1E1C2C34-017E-4605-AE2B-55EA3313BE51}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1E1C2C34-017E-4605-AE2B-55EA3313BE51}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Delete Text From PDF/C#/Remove And Blackout Credit Card Data From PDF/Program.cs b/Delete Text From PDF/C#/Remove And Blackout Credit Card Data From PDF/Program.cs new file mode 100644 index 000000000..9ebada1bb --- /dev/null +++ b/Delete Text From PDF/C#/Remove And Blackout Credit Card Data From PDF/Program.cs @@ -0,0 +1,233 @@ +//*******************************************************************************************// +// // +// Download Free Evaluation Version From: https://bytescout.com/download/web-installer // +// // +// Also available as Web API! Get Your Free API Key: https://app.pdf.co/signup // +// // +// Copyright © 2017-2020 ByteScout, Inc. All rights reserved. // +// https://www.bytescout.com // +// https://pdf.co // +// // +//*******************************************************************************************// + + +using System; +using System.IO; +using System.Net; +using Newtonsoft.Json.Linq; +using System.Threading; +using System.Collections.Generic; +using Newtonsoft.Json; + +// Cloud API asynchronous "Delete Text from PDF" job example. + +namespace ByteScoutWebApiExample +{ + class Program + { + // The authentication key (API Key). + // Get your own by registering at https://app.pdf.co + const String API_KEY = "YOUR_PDFco_API_KEY_HERE"; + + // Source PDF file + const string SourceFile = @".\sample.pdf"; + + // PDF document password. Leave empty for unprotected documents. + const string Password = ""; + + // Regex Enabled Search + const bool RegexEnabled = true; + + // Destination PDF file name + const string DestinationFile = @".\result.pdf"; + + + static void Main(string[] args) + { + // Upload file to the cloud + string uploadedFileUrl = UploadFile(SourceFile); + + if (string.IsNullOrEmpty(uploadedFileUrl)) + { + Console.WriteLine("File upload error."); + return; + } + + // Regular Expression for Credit Card + string regex_creditCard = @"[0-9]{4} [0-9]{4} [0-9]{4} [0-9]{4}"; + + // Regular expression CVV number + string regex_cvv = @"\b[0-9]{3}\b"; + + // Regular expression mm/year + string regex_month_year = @"[0-9]{2}(\/|-)[0-9]{4}"; + + // Create standard .NET web client instance + WebClient webClient = new WebClient(); + + // Set API Key + webClient.Headers.Add("x-api-key", API_KEY); + + // Prepare requests params as JSON + // See documentation: https://apidocs.pdf.co/#pdf-search-and-delete-text-from-pdf + Dictionary parameters = new Dictionary(); + parameters.Add("name", Path.GetFileName(DestinationFile)); + parameters.Add("password", Password); + parameters.Add("url", uploadedFileUrl); + parameters.Add("searchStrings", new string[] { regex_creditCard, regex_cvv, regex_month_year }); + parameters.Add("regex", RegexEnabled); + + // Important: Specify Blackout Color + parameters.Add("profiles", @"{'UsePatch': true, 'PatchColor': '#000000'}"); + + parameters.Add("async", true); // ! Making Async request + + // Convert dictionary of params to JSON + string jsonPayload = JsonConvert.SerializeObject(parameters); + + // URL of `Delete Text from PDF` API call + string url = "https://api.pdf.co/v1/pdf/edit/delete-text"; + + try + { + // Execute POST request with JSON payload + string response = webClient.UploadString(url, jsonPayload); + + // Parse JSON response + JObject json = JObject.Parse(response); + + if (json["error"].ToObject() == false) + { + // Asynchronous job ID + string jobId = json["jobId"].ToString(); + // URL of generated PDF file that will available after the job completion + string resultFileUrl = json["url"].ToString(); + + // Check the job status in a loop. + // If you don't want to pause the main thread you can rework the code + // to use a separate thread for the status checking and completion. + do + { + string status = CheckJobStatus(jobId); // Possible statuses: "working", "failed", "aborted", "success". + + // Display timestamp and status (for demo purposes) + Console.WriteLine(DateTime.Now.ToLongTimeString() + ": " + status); + + if (status == "success") + { + // Download PDF file + webClient.DownloadFile(resultFileUrl, DestinationFile); + + Console.WriteLine("Generated PDF file saved as \"{0}\" file.", DestinationFile); + break; + } + else if (status == "working") + { + // Pause for a few seconds + Thread.Sleep(3000); + } + else + { + Console.WriteLine(status); + break; + } + } + while (true); + } + else + { + Console.WriteLine(json["message"].ToString()); + } + } + catch (WebException e) + { + Console.WriteLine(e.ToString()); + } + + webClient.Dispose(); + + + Console.WriteLine(); + Console.WriteLine("Press any key..."); + Console.ReadKey(); + } + + /// + /// Uploads file to the cloud and return URL of uploaded file to use in further API calls. + /// + /// Source file name (path). + /// URL of uploaded file + static string UploadFile(string file) + { + // Create standard .NET web client instance + WebClient webClient = new WebClient(); + + // Set API Key + webClient.Headers.Add("x-api-key", API_KEY); + + try + { + // 1. RETRIEVE THE PRESIGNED URL TO UPLOAD THE FILE. + // * If you already have a direct file URL, skip to the step 3. + + // Prepare URL for `Get Presigned URL` API call + string query = Uri.EscapeUriString(string.Format( + "https://api.pdf.co/v1/file/upload/get-presigned-url?contenttype=application/octet-stream&name={0}", + Path.GetFileName(file))); + + // Execute request + string response = webClient.DownloadString(query); + + // Parse JSON response + JObject json = JObject.Parse(response); + + if (json["error"].ToObject() == false) + { + // Get URL to use for the file upload + string uploadUrl = json["presignedUrl"].ToString(); + // Get URL of uploaded file to use with later API calls + string uploadedFileUrl = json["url"].ToString(); + + // 2. UPLOAD THE FILE TO CLOUD. + + webClient.Headers.Add("content-type", "application/octet-stream"); + webClient.UploadFile(uploadUrl, "PUT", file); // You can use UploadData() instead if your file is in byte[] or Stream + + return uploadedFileUrl; + } + else + { + // Display service reported error + Console.WriteLine(json["message"].ToString()); + } + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } + finally + { + webClient.Dispose(); + } + + return null; + } + + static string CheckJobStatus(string jobId) + { + using (WebClient webClient = new WebClient()) + { + // Set API Key + webClient.Headers.Add("x-api-key", API_KEY); + + string url = "https://api.pdf.co/v1/job/check?jobid=" + jobId; + + string response = webClient.DownloadString(url); + JObject json = JObject.Parse(response); + + return Convert.ToString(json["status"]); + } + } + } +} diff --git a/Delete Text From PDF/C#/Remove And Blackout Credit Card Data From PDF/Properties/AssemblyInfo.cs b/Delete Text From PDF/C#/Remove And Blackout Credit Card Data From PDF/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..9986fbb0e --- /dev/null +++ b/Delete Text From PDF/C#/Remove And Blackout Credit Card Data From PDF/Properties/AssemblyInfo.cs @@ -0,0 +1,49 @@ +//*******************************************************************************************// +// // +// Download Free Evaluation Version From: https://bytescout.com/download/web-installer // +// // +// Also available as Web API! Get Your Free API Key: https://app.pdf.co/signup // +// // +// Copyright © 2017-2020 ByteScout, Inc. All rights reserved. // +// https://www.bytescout.com // +// https://pdf.co // +// // +//*******************************************************************************************// + + +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ByteScoutWebApiExample")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ByteScoutWebApiExample")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("872b5135-146b-4782-894d-7b6c3162308a")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Delete Text From PDF/C#/Remove And Blackout Credit Card Data From PDF/packages.config b/Delete Text From PDF/C#/Remove And Blackout Credit Card Data From PDF/packages.config new file mode 100644 index 000000000..03c709252 --- /dev/null +++ b/Delete Text From PDF/C#/Remove And Blackout Credit Card Data From PDF/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Delete Text From PDF/C#/Remove And Blackout Credit Card Data From PDF/sample.pdf b/Delete Text From PDF/C#/Remove And Blackout Credit Card Data From PDF/sample.pdf new file mode 100644 index 000000000..cadd1770e Binary files /dev/null and b/Delete Text From PDF/C#/Remove And Blackout Credit Card Data From PDF/sample.pdf differ diff --git a/Delete Text From PDF/C#/Remove And Blackout Email and SSN Data From PDF/ByteScoutWebApiExample.NETCore.csproj b/Delete Text From PDF/C#/Remove And Blackout Email and SSN Data From PDF/ByteScoutWebApiExample.NETCore.csproj new file mode 100644 index 000000000..82e9705c7 --- /dev/null +++ b/Delete Text From PDF/C#/Remove And Blackout Email and SSN Data From PDF/ByteScoutWebApiExample.NETCore.csproj @@ -0,0 +1,35 @@ + + + + Exe + netcoreapp2.0 + false + false + false + false + false + false + false + false + false + false + false + false + + + + + + + + + + + + + + + Always + + + \ No newline at end of file diff --git a/Delete Text From PDF/C#/Remove And Blackout Email and SSN Data From PDF/ByteScoutWebApiExample.NETCore.sln b/Delete Text From PDF/C#/Remove And Blackout Email and SSN Data From PDF/ByteScoutWebApiExample.NETCore.sln new file mode 100644 index 000000000..6527b80b4 --- /dev/null +++ b/Delete Text From PDF/C#/Remove And Blackout Email and SSN Data From PDF/ByteScoutWebApiExample.NETCore.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.32126.317 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ByteScoutWebApiExample.NETCore", "ByteScoutWebApiExample.NETCore.csproj", "{6C67B480-C7E2-4AF7-AE7B-0E12A5799D9C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6C67B480-C7E2-4AF7-AE7B-0E12A5799D9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6C67B480-C7E2-4AF7-AE7B-0E12A5799D9C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6C67B480-C7E2-4AF7-AE7B-0E12A5799D9C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6C67B480-C7E2-4AF7-AE7B-0E12A5799D9C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {FBAE862B-1737-4E3F-96CF-5B8772A7AC09} + EndGlobalSection +EndGlobal diff --git a/Delete Text From PDF/C#/Remove And Blackout Email and SSN Data From PDF/ByteScoutWebApiExample.csproj b/Delete Text From PDF/C#/Remove And Blackout Email and SSN Data From PDF/ByteScoutWebApiExample.csproj new file mode 100644 index 000000000..c5130112c --- /dev/null +++ b/Delete Text From PDF/C#/Remove And Blackout Email and SSN Data From PDF/ByteScoutWebApiExample.csproj @@ -0,0 +1,63 @@ + + + + + Debug + AnyCPU + {1E1C2C34-017E-4605-AE2B-55EA3313BE51} + Exe + Properties + ByteScoutWebApiExample + ByteScoutWebApiExample + v4.6 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + packages\Newtonsoft.Json.10.0.3\lib\net40\Newtonsoft.Json.dll + True + + + + + + + + + + + + + + + Always + + + + + \ No newline at end of file diff --git a/Delete Text From PDF/C#/Remove And Blackout Email and SSN Data From PDF/ByteScoutWebApiExample.sln b/Delete Text From PDF/C#/Remove And Blackout Email and SSN Data From PDF/ByteScoutWebApiExample.sln new file mode 100644 index 000000000..44721634f --- /dev/null +++ b/Delete Text From PDF/C#/Remove And Blackout Email and SSN Data From PDF/ByteScoutWebApiExample.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.40629.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ByteScoutWebApiExample", "ByteScoutWebApiExample.csproj", "{1E1C2C34-017E-4605-AE2B-55EA3313BE51}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1E1C2C34-017E-4605-AE2B-55EA3313BE51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1E1C2C34-017E-4605-AE2B-55EA3313BE51}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1E1C2C34-017E-4605-AE2B-55EA3313BE51}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1E1C2C34-017E-4605-AE2B-55EA3313BE51}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Delete Text From PDF/C#/Remove And Blackout Email and SSN Data From PDF/Program.cs b/Delete Text From PDF/C#/Remove And Blackout Email and SSN Data From PDF/Program.cs new file mode 100644 index 000000000..e1ab02fad --- /dev/null +++ b/Delete Text From PDF/C#/Remove And Blackout Email and SSN Data From PDF/Program.cs @@ -0,0 +1,231 @@ +//*******************************************************************************************// +// // +// Download Free Evaluation Version From: https://bytescout.com/download/web-installer // +// // +// Also available as Web API! Get Your Free API Key: https://app.pdf.co/signup // +// // +// Copyright © 2017-2020 ByteScout, Inc. All rights reserved. // +// https://www.bytescout.com // +// https://pdf.co // +// // +//*******************************************************************************************// + + +using System; +using System.IO; +using System.Net; +using Newtonsoft.Json.Linq; +using System.Threading; +using System.Collections.Generic; +using Newtonsoft.Json; + +// Cloud API asynchronous "Delete Text from PDF" job example. + +namespace ByteScoutWebApiExample +{ + class Program + { + // The authentication key (API Key). + // Get your own by registering at https://app.pdf.co + const String API_KEY = "YOUR_PDFco_API_KEY_HERE"; + + // Source PDF file + const string SourceFile = @".\sample.pdf"; + + // PDF document password. Leave empty for unprotected documents. + const string Password = ""; + + // Regex Enabled Search + const bool RegexEnabled = true; + + // Destination PDF file name + const string DestinationFile = @".\result.pdf"; + + + static void Main(string[] args) + { + // Upload file to the cloud + string uploadedFileUrl = UploadFile(SourceFile); + + if (string.IsNullOrEmpty(uploadedFileUrl)) + { + Console.WriteLine("File upload error."); + return; + } + + // Regular Expression to Search for SSN + string regex_ssn = @"[0-9]{3}-[0-9]{2}-[0-9]{4}"; + + // Regular Expression to Search Email Address + string regex_email = @"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}"; + + + // Create standard .NET web client instance + WebClient webClient = new WebClient(); + + // Set API Key + webClient.Headers.Add("x-api-key", API_KEY); + + // Prepare requests params as JSON + // See documentation: https://apidocs.pdf.co/#pdf-search-and-delete-text-from-pdf + Dictionary parameters = new Dictionary(); + parameters.Add("name", Path.GetFileName(DestinationFile)); + parameters.Add("password", Password); + parameters.Add("url", uploadedFileUrl); + parameters.Add("searchStrings", new string[] { regex_ssn, regex_email }); + parameters.Add("regex", RegexEnabled); + + // Important: Specify Blackout Color + parameters.Add("profiles", @"{'UsePatch': true, 'PatchColor': '#000000'}"); + + parameters.Add("async", true); // ! Making Async request + + // Convert dictionary of params to JSON + string jsonPayload = JsonConvert.SerializeObject(parameters); + + // URL of `Delete Text from PDF` API call + string url = "https://api.pdf.co/v1/pdf/edit/delete-text"; + + try + { + // Execute POST request with JSON payload + string response = webClient.UploadString(url, jsonPayload); + + // Parse JSON response + JObject json = JObject.Parse(response); + + if (json["error"].ToObject() == false) + { + // Asynchronous job ID + string jobId = json["jobId"].ToString(); + // URL of generated PDF file that will available after the job completion + string resultFileUrl = json["url"].ToString(); + + // Check the job status in a loop. + // If you don't want to pause the main thread you can rework the code + // to use a separate thread for the status checking and completion. + do + { + string status = CheckJobStatus(jobId); // Possible statuses: "working", "failed", "aborted", "success". + + // Display timestamp and status (for demo purposes) + Console.WriteLine(DateTime.Now.ToLongTimeString() + ": " + status); + + if (status == "success") + { + // Download PDF file + webClient.DownloadFile(resultFileUrl, DestinationFile); + + Console.WriteLine("Generated PDF file saved as \"{0}\" file.", DestinationFile); + break; + } + else if (status == "working") + { + // Pause for a few seconds + Thread.Sleep(3000); + } + else + { + Console.WriteLine(status); + break; + } + } + while (true); + } + else + { + Console.WriteLine(json["message"].ToString()); + } + } + catch (WebException e) + { + Console.WriteLine(e.ToString()); + } + + webClient.Dispose(); + + + Console.WriteLine(); + Console.WriteLine("Press any key..."); + Console.ReadKey(); + } + + /// + /// Uploads file to the cloud and return URL of uploaded file to use in further API calls. + /// + /// Source file name (path). + /// URL of uploaded file + static string UploadFile(string file) + { + // Create standard .NET web client instance + WebClient webClient = new WebClient(); + + // Set API Key + webClient.Headers.Add("x-api-key", API_KEY); + + try + { + // 1. RETRIEVE THE PRESIGNED URL TO UPLOAD THE FILE. + // * If you already have a direct file URL, skip to the step 3. + + // Prepare URL for `Get Presigned URL` API call + string query = Uri.EscapeUriString(string.Format( + "https://api.pdf.co/v1/file/upload/get-presigned-url?contenttype=application/octet-stream&name={0}", + Path.GetFileName(file))); + + // Execute request + string response = webClient.DownloadString(query); + + // Parse JSON response + JObject json = JObject.Parse(response); + + if (json["error"].ToObject() == false) + { + // Get URL to use for the file upload + string uploadUrl = json["presignedUrl"].ToString(); + // Get URL of uploaded file to use with later API calls + string uploadedFileUrl = json["url"].ToString(); + + // 2. UPLOAD THE FILE TO CLOUD. + + webClient.Headers.Add("content-type", "application/octet-stream"); + webClient.UploadFile(uploadUrl, "PUT", file); // You can use UploadData() instead if your file is in byte[] or Stream + + return uploadedFileUrl; + } + else + { + // Display service reported error + Console.WriteLine(json["message"].ToString()); + } + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } + finally + { + webClient.Dispose(); + } + + return null; + } + + static string CheckJobStatus(string jobId) + { + using (WebClient webClient = new WebClient()) + { + // Set API Key + webClient.Headers.Add("x-api-key", API_KEY); + + string url = "https://api.pdf.co/v1/job/check?jobid=" + jobId; + + string response = webClient.DownloadString(url); + JObject json = JObject.Parse(response); + + return Convert.ToString(json["status"]); + } + } + } +} diff --git a/Delete Text From PDF/C#/Remove And Blackout Email and SSN Data From PDF/Properties/AssemblyInfo.cs b/Delete Text From PDF/C#/Remove And Blackout Email and SSN Data From PDF/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..9986fbb0e --- /dev/null +++ b/Delete Text From PDF/C#/Remove And Blackout Email and SSN Data From PDF/Properties/AssemblyInfo.cs @@ -0,0 +1,49 @@ +//*******************************************************************************************// +// // +// Download Free Evaluation Version From: https://bytescout.com/download/web-installer // +// // +// Also available as Web API! Get Your Free API Key: https://app.pdf.co/signup // +// // +// Copyright © 2017-2020 ByteScout, Inc. All rights reserved. // +// https://www.bytescout.com // +// https://pdf.co // +// // +//*******************************************************************************************// + + +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ByteScoutWebApiExample")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ByteScoutWebApiExample")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("872b5135-146b-4782-894d-7b6c3162308a")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Delete Text From PDF/C#/Remove And Blackout Email and SSN Data From PDF/packages.config b/Delete Text From PDF/C#/Remove And Blackout Email and SSN Data From PDF/packages.config new file mode 100644 index 000000000..03c709252 --- /dev/null +++ b/Delete Text From PDF/C#/Remove And Blackout Email and SSN Data From PDF/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Delete Text From PDF/C#/Remove And Blackout Email and SSN Data From PDF/sample.pdf b/Delete Text From PDF/C#/Remove And Blackout Email and SSN Data From PDF/sample.pdf new file mode 100644 index 000000000..f859f2e8e Binary files /dev/null and b/Delete Text From PDF/C#/Remove And Blackout Email and SSN Data From PDF/sample.pdf differ diff --git a/Index.txt b/Index.txt index 4aac50f52..a5d7d611a 100644 --- a/Index.txt +++ b/Index.txt @@ -244,6 +244,8 @@ \Delete Text From PDF\C#\Delete PDF Text From Uploaded File \Delete Text From PDF\C#\Delete PDF Text From URL \Delete Text From PDF\C#\Delete PDF Text From URL Asynchronously +\Delete Text From PDF\C#\Remove And Blackout Credit Card Data From PDF +\Delete Text From PDF\C#\Remove And Blackout Email and SSN Data From PDF \Delete Text From PDF\C#\Remove Credit Card Data From PDF \Delete Text From PDF\C#\Remove Email and SSN Data From PDF \Delete Text From PDF\cURL\Delete Multiple Replacement @@ -1185,6 +1187,7 @@ \PDF Splitting API\PHP \PDF Splitting API\PowerShell \PDF Splitting API\Python +\PDF Splitting API\Salesforce \PDF Splitting API\VB.NET \PDF Splitting API\AWS Lambda\Split PDF By Barcode From URL (Node.js) \PDF Splitting API\AWS Lambda\Split PDF By Text From URL (Node.js) @@ -1243,6 +1246,9 @@ \PDF Splitting API\Python\Split PDF By Text From Uploaded File Asynchronously \PDF Splitting API\Python\Split PDF From Uploaded File \PDF Splitting API\Python\Split PDF From Uploaded File Asynchronously +\PDF Splitting API\Salesforce\Split PDF By Barcode +\PDF Splitting API\Salesforce\Split PDF By Page Number +\PDF Splitting API\Salesforce\Split PDF By Text Search \PDF Splitting API\VB.NET\Async file upload and async Split PDF \PDF Splitting API\VB.NET\Async file upload and async Split PDF By Barcode \PDF Splitting API\VB.NET\Async file upload and async Split PDF By Text diff --git a/PDF Splitting API/Salesforce/Split PDF By Barcode/SplitPDFByBarcode.cls b/PDF Splitting API/Salesforce/Split PDF By Barcode/SplitPDFByBarcode.cls new file mode 100644 index 000000000..beb519262 --- /dev/null +++ b/PDF Splitting API/Salesforce/Split PDF By Barcode/SplitPDFByBarcode.cls @@ -0,0 +1,85 @@ +public class SplitPDFByBarcode { + + String API_KEY = '****************'; + string DestinationFile = 'SplitPDFByBarcode_Result'; + string endPointUrl = 'https://api.pdf.co/v1/pdf/split2'; + + public void splitPdfByBarcode() + { + List toBeInserted = new List(); + try + { + String jsonBody = '{ "url": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/pdf-split/split_by_barcode.pdf", "searchString": "[[barcode:qrcode,datamatrix /bytescout\\.com/]]", "excludeKeyPages": true, "regexSearch": false, "caseSensitive": false, "inline": true, "name": "output-split-by-barcode", "async": false }'; + Http http = new Http(); + HttpRequest request = new HttpRequest(); + request.setHeader('x-api-key', API_KEY); + request.setEndpoint(endPointUrl); + request.setHeader('Content-Type', 'application/json'); + request.setMethod('POST'); + request.setBody(jsonBody); + HttpResponse response = http.send(request); + Map json = (Map)JSON.deserializeUntyped(response.getBody()); + if(response.getStatusCode() == 200) + { + if ((Boolean)json.get('error') == false) + { + System.debug('response.getBody() :: '+response.getBody()); + List resultFileUrl =(List)json.get('urls'); + Integer count=1; + for(Object fileUrl : resultFileUrl) + { + downloadFile(String.valueOf(fileUrl), DestinationFile+'_'+count, toBeInserted); + count++; + } + System.debug('Generated PDF file saved as \'{0}\' file.'+ DestinationFile); + } + } + else + { + System.debug('Error Response ' + response.getBody()); + System.Debug(' Status ' + response.getStatus()); + System.Debug(' Status Code' + response.getStatusCode()); + System.Debug(' Response String' + response.toString()); + } + if(toBeInserted.size() > 0) + insert toBeInserted; + } + catch(Exception ex) + { + String errorBody = 'Message: ' + ex.getMessage() + ' -- Cause: ' + ex.getCause() + ' -- Stacktrace: ' + ex.getStackTraceString(); + System.Debug(errorBody); + } + } + + @TestVisible + private static void downloadFile(String extFileUrl, String DestinationFile, List toBeInserted) + { + Http h = new Http(); + HttpRequest req = new HttpRequest(); + extFileUrl = extFileUrl.replace(' ', '%20'); + req.setEndpoint(extFileUrl); + req.setMethod('GET'); + req.setHeader('Content-Type', 'application/pdf'); + req.setCompressed(true); + req.setTimeout(60000); + HttpResponse res = h.send(req); + if(res.getStatusCode() == 200) + { + blob fileContent = res.getBodyAsBlob(); + ContentVersion conVer = new ContentVersion(); + conVer.ContentLocation = 'S'; + conVer.PathOnClient = DestinationFile + '.pdf'; // The files name, extension is very important here which will help the file in preview. + conVer.Title = DestinationFile; // Display name of the files + conVer.VersionData = fileContent; + toBeInserted.add(conVer); + System.Debug('Success'); + } + else + { + System.debug('Error Response ' + res.getBody()); + System.Debug(' Status ' + res.getStatus()); + System.Debug(' Status Code' + res.getStatusCode()); + System.Debug(' Response String' + res.toString()); + } + } +} \ No newline at end of file diff --git a/PDF Splitting API/Salesforce/Split PDF By Barcode/SplitPDFByBarcodeTest.cls b/PDF Splitting API/Salesforce/Split PDF By Barcode/SplitPDFByBarcodeTest.cls new file mode 100644 index 000000000..a5b57364c --- /dev/null +++ b/PDF Splitting API/Salesforce/Split PDF By Barcode/SplitPDFByBarcodeTest.cls @@ -0,0 +1,31 @@ +@isTest +private class SplitPDFByBarcodeTest { + + static testmethod void testSplitPDFbyBarcode() + { + Test.startTest(); + Test.setMock(HttpCalloutMock.class, new SplitPDFByBarcodeTest.SplitPDFByBarcodeMock()); + SplitPDFByBarcode splitPdf = new SplitPDFByBarcode(); + splitPdf.splitPdfByBarcode(); + Test.stopTest(); + } + + static testmethod void testSplitPDFbyBarcodeForCatch() + { + Test.startTest(); + SplitPDFByBarcode splitPdf = new SplitPDFByBarcode(); + splitPdf.splitPdfByBarcode(); + Test.stopTest(); + } + + public class SplitPDFByBarcodeMock implements HttpCalloutMock { + public HttpResponse respond(HTTPRequest req) { + HttpResponse res = new HttpResponse(); + String testBody = '{ "urls": [ "https://pdf-temp-files.s3.us-west-2.amazonaws.com/FAMAJC25DIDJ69FMLTVOWJ7IL8IZVA6E/output-split-by-barcode_page1.pdf?X-Amz-Expires=3600&X-Amz-Security-Token=FwoGZXIvYXdzEG8aDNkg0DYoVoCyvF88aSKCAYgbOizJoYULBIgYUdfJgJG5Tw7PlcNavOD6q4JNwLz5wT89pkTBS%2FPbnykQjNrJeh%2B6njlDmjcLqAjt2RApVDtXFJrb%2F%2B67T43qQZJXCj83zIugG2oTGsA1tK2q7KmD8YV%2FWM%2FUEXEhiiKYXtae2GQAsMPowLTWCrw6%2BUhX8AQQjPIor42nnwYyKDAWzJatWBqURnasvqtS10U2A4EaRxD%2BrpU5dwOqWN47Dkqzq9TBfug%3D&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIA4NRRSZPHCRJF34GF/20230213/us-west-2/s3/aws4_request&X-Amz-Date=20230213T054645Z&X-Amz-SignedHeaders=host&X-Amz-Signature=d342a4a232fe62f83bd3965335128428347dbb6b9f97c71f1f17e3e42d80edcd" ], "pageCount": 10, "error": false, "status": 200, "name": "output-split-by-barcode.pdf", "credits": 350, "duration": 4809, "remainingCredits": 1165920 }'; + res.setHeader('Content-Type', 'application/json'); + res.setBody(testBody); + res.setStatusCode(200); + return res; + } + } +} \ No newline at end of file diff --git a/PDF Splitting API/Salesforce/Split PDF By Page Number/SplitPDFByPageNumber.cls b/PDF Splitting API/Salesforce/Split PDF By Page Number/SplitPDFByPageNumber.cls new file mode 100644 index 000000000..b95209f0b --- /dev/null +++ b/PDF Splitting API/Salesforce/Split PDF By Page Number/SplitPDFByPageNumber.cls @@ -0,0 +1,85 @@ +public class SplitPDFByPageNumber { + + String API_KEY = '***********************'; + string DestinationFile = 'SplitPDFByPageNo_Result'; + string endPointUrl = 'https://api.pdf.co/v1/pdf/split'; + + public void splitPdfUsingPage() + { + List toBeInserted = new List(); + try + { + String jsonBody = '{"url": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/pdf-split/sample.pdf", "pages": "1-2,3-", "inline": true, "name": "result.pdf", "async": false }'; + Http http = new Http(); + HttpRequest request = new HttpRequest(); + request.setHeader('x-api-key', API_KEY); + request.setEndpoint(endPointUrl); + request.setHeader('Content-Type', 'application/json'); + request.setMethod('POST'); + request.setBody(jsonBody); + HttpResponse response = http.send(request); + Map json = (Map)JSON.deserializeUntyped(response.getBody()); + if(response.getStatusCode() == 200) + { + if ((Boolean)json.get('error') == false) + { + System.debug('response.getBody() :: '+response.getBody()); + List resultFileUrl =(List)json.get('urls'); + Integer count=1; + for(Object fileUrl : resultFileUrl) + { + downloadFile(String.valueOf(fileUrl), DestinationFile+'_'+count, toBeInserted); + count++; + } + System.debug('Generated PDF file saved as \'{0}\' file.'+ DestinationFile); + } + } + else + { + System.debug('Error Response ' + response.getBody()); + System.Debug(' Status ' + response.getStatus()); + System.Debug(' Status Code' + response.getStatusCode()); + System.Debug(' Response String' + response.toString()); + } + if(toBeInserted.size() > 0) + insert toBeInserted; + } + catch(Exception ex) + { + String errorBody = 'Message: ' + ex.getMessage() + ' -- Cause: ' + ex.getCause() + ' -- Stacktrace: ' + ex.getStackTraceString(); + System.Debug(errorBody); + } + } + + @TestVisible + private static void downloadFile(String extFileUrl, String DestinationFile, List toBeInserted) + { + Http h = new Http(); + HttpRequest req = new HttpRequest(); + extFileUrl = extFileUrl.replace(' ', '%20'); + req.setEndpoint(extFileUrl); + req.setMethod('GET'); + req.setHeader('Content-Type', 'application/pdf'); + req.setCompressed(true); + req.setTimeout(60000); + HttpResponse res = h.send(req); + if(res.getStatusCode() == 200) + { + blob fileContent = res.getBodyAsBlob(); + ContentVersion conVer = new ContentVersion(); + conVer.ContentLocation = 'S'; + conVer.PathOnClient = DestinationFile + '.pdf'; // The files name, extension is very important here which will help the file in preview. + conVer.Title = DestinationFile; // Display name of the files + conVer.VersionData = fileContent; + toBeInserted.add(conVer); + System.Debug('Success'); + } + else + { + System.debug('Error Response ' + res.getBody()); + System.Debug(' Status ' + res.getStatus()); + System.Debug(' Status Code' + res.getStatusCode()); + System.Debug(' Response String' + res.toString()); + } + } +} \ No newline at end of file diff --git a/PDF Splitting API/Salesforce/Split PDF By Page Number/SplitPDFByPageNumberTest.cls b/PDF Splitting API/Salesforce/Split PDF By Page Number/SplitPDFByPageNumberTest.cls new file mode 100644 index 000000000..eb2acca7c --- /dev/null +++ b/PDF Splitting API/Salesforce/Split PDF By Page Number/SplitPDFByPageNumberTest.cls @@ -0,0 +1,31 @@ +@isTest +private class SplitPDFByPageNumberTest { + + static testMethod void testSplitPdfUsingPage() + { + Test.startTest(); + Test.setMock(HttpCalloutMock.class, new SplitPDFByPageNumberTest.SplitPDFByPageNoMock()); + SplitPDFByPageNumber splitPdf = new SplitPDFByPageNumber(); + splitPdf.splitPdfUsingPage(); + Test.stopTest(); + } + + static testMethod void testSplitPdfUsingPageforCatch() + { + Test.startTest(); + SplitPDFByPageNumber splitPdf = new SplitPDFByPageNumber(); + splitPdf.splitPdfUsingPage(); + Test.stopTest(); + } + + public class SplitPDFByPageNoMock implements HttpCalloutMock { + public HTTPResponse respond(HTTPRequest req) { + HttpResponse res = new HttpResponse(); + String testBody = '{ "urls": [ "https://pdf-temp-files.s3.us-west-2.amazonaws.com/YPG46FWTZPJA0XOYS4WW9REHCHLO659Y/result_page1-2.pdf?X-Amz-Expires=3600&X-Amz-Security-Token=FwoGZXIvYXdzEG8aDNkg0DYoVoCyvF88aSKCAYgbOizJoYULBIgYUdfJgJG5Tw7PlcNavOD6q4JNwLz5wT89pkTBS%2FPbnykQjNrJeh%2B6njlDmjcLqAjt2RApVDtXFJrb%2F%2B67T43qQZJXCj83zIugG2oTGsA1tK2q7KmD8YV%2FWM%2FUEXEhiiKYXtae2GQAsMPowLTWCrw6%2BUhX8AQQjPIor42nnwYyKDAWzJatWBqURnasvqtS10U2A4EaRxD%2BrpU5dwOqWN47Dkqzq9TBfug%3D&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIA4NRRSZPHCRJF34GF/20230213/us-west-2/s3/aws4_request&X-Amz-Date=20230213T054449Z&X-Amz-SignedHeaders=host&X-Amz-Signature=8f5a5c43ab6aecde4deef658d5f8d93deca1cca19487453cc9fc75a09f918b8b" ], "pageCount": 4, "error": false, "status": 200, "name": "result.pdf", "credits": 8, "duration": 359, "remainingCredits": 1166375 }'; + res.setHeader('Content-Type', 'application/json'); + res.setBody(testBody); + res.setStatusCode(200); + return res; + } + } +} \ No newline at end of file diff --git a/PDF Splitting API/Salesforce/Split PDF By Text Search/SplitPDFByTextSearch.cls b/PDF Splitting API/Salesforce/Split PDF By Text Search/SplitPDFByTextSearch.cls new file mode 100644 index 000000000..b3d8f8146 --- /dev/null +++ b/PDF Splitting API/Salesforce/Split PDF By Text Search/SplitPDFByTextSearch.cls @@ -0,0 +1,85 @@ +public class SplitPDFByTextSearch { + + String API_KEY = '*****************'; + string DestinationFile = 'SplitPDFByTextSearch_Result'; + string endPointUrl = 'https://api.pdf.co/v1/pdf/split2'; + + public void splitPdfByText() + { + List toBeInserted = new List(); + try + { + String jsonBody = '{ "url": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/pdf-split/multiple-invoices.pdf", "searchString": "invoice number", "excludeKeyPages": false, "regexSearch": false, "caseSensitive": false, "inline": true, "name": "invoice-extracted", "async": false }'; + Http http = new Http(); + HttpRequest request = new HttpRequest(); + request.setHeader('x-api-key', API_KEY); + request.setEndpoint(endPointUrl); + request.setHeader('Content-Type', 'application/json'); + request.setMethod('POST'); + request.setBody(jsonBody); + HttpResponse response = http.send(request); + Map json = (Map)JSON.deserializeUntyped(response.getBody()); + if(response.getStatusCode() == 200) + { + if ((Boolean)json.get('error') == false) + { + System.debug('response.getBody() :: '+response.getBody()); + List resultFileUrl =(List)json.get('urls'); + Integer count=1; + for(Object fileUrl : resultFileUrl) + { + downloadFile(String.valueOf(fileUrl), DestinationFile+'_'+count, toBeInserted); + count++; + } + System.debug('Generated PDF file saved as \'{0}\' file.'+ DestinationFile); + } + } + else + { + System.debug('Error Response ' + response.getBody()); + System.Debug(' Status ' + response.getStatus()); + System.Debug(' Status Code' + response.getStatusCode()); + System.Debug(' Response String' + response.toString()); + } + if(toBeInserted.size() > 0) + insert toBeInserted; + } + catch(Exception ex) + { + String errorBody = 'Message: ' + ex.getMessage() + ' -- Cause: ' + ex.getCause() + ' -- Stacktrace: ' + ex.getStackTraceString(); + System.Debug(errorBody); + } + } + + @TestVisible + private static void downloadFile(String extFileUrl, String DestinationFile, List toBeInserted) + { + Http h = new Http(); + HttpRequest req = new HttpRequest(); + extFileUrl = extFileUrl.replace(' ', '%20'); + req.setEndpoint(extFileUrl); + req.setMethod('GET'); + req.setHeader('Content-Type', 'application/pdf'); + req.setCompressed(true); + req.setTimeout(60000); + HttpResponse res = h.send(req); + if(res.getStatusCode() == 200) + { + blob fileContent = res.getBodyAsBlob(); + ContentVersion conVer = new ContentVersion(); + conVer.ContentLocation = 'S'; + conVer.PathOnClient = DestinationFile + '.pdf'; // The files name, extension is very important here which will help the file in preview. + conVer.Title = DestinationFile; // Display name of the files + conVer.VersionData = fileContent; + toBeInserted.add(conVer); + System.Debug('Success'); + } + else + { + System.debug('Error Response ' + res.getBody()); + System.Debug(' Status ' + res.getStatus()); + System.Debug(' Status Code' + res.getStatusCode()); + System.Debug(' Response String' + res.toString()); + } + } +} \ No newline at end of file diff --git a/PDF Splitting API/Salesforce/Split PDF By Text Search/SplitPDFByTextSearchTest.cls b/PDF Splitting API/Salesforce/Split PDF By Text Search/SplitPDFByTextSearchTest.cls new file mode 100644 index 000000000..9ef923e16 --- /dev/null +++ b/PDF Splitting API/Salesforce/Split PDF By Text Search/SplitPDFByTextSearchTest.cls @@ -0,0 +1,31 @@ +@isTest +private class SplitPDFByTextSearchTest { + + static testMethod void testSplitPdfUsingPage() + { + Test.startTest(); + Test.setMock(HttpCalloutMock.class, new SplitPDFByTextSearchTest.SplitPDFByTextMock()); + SplitPDFByTextSearch splitPdf = new SplitPDFByTextSearch(); + splitPdf.splitPdfByText(); + Test.stopTest(); + } + + static testMethod void testSplitPdfUsingPageForCatch() + { + Test.startTest(); + SplitPDFByTextSearch splitPdf = new SplitPDFByTextSearch(); + splitPdf.splitPdfByText(); + Test.stopTest(); + } + + public class SplitPDFByTextMock implements HttpCalloutMock { + public HTTPResponse respond(HTTPRequest req) { + HttpResponse res = new HttpResponse(); + String testBody = '{ "urls": [ "https://pdf-temp-files.s3.us-west-2.amazonaws.com/BV5R88QIPOZPKVO0PE7GYKVBETULHN0Y/invoice-extracted_page1.pdf?X-Amz-Expires=3600&X-Amz-Security-Token=FwoGZXIvYXdzEG8aDKuBm3gDES1tmO7uSSKCATaP8OHW3vpxMhhGOh4utp7hCQzkW5aPbntexlu9TwfIMzceDB6zBv%2F5L4kWTEf8xwOqTckcDrAeDd0oL%2FbWpbPgP68r01OjXwSBbB0TMu3KftSf7VN%2B7NhOl4MXX1HIOSCrvcCUvLOql2DcpVhjFwPJ%2B1JMx6yorVx1zNMLwj98Kuco%2FI6nnwYyKBbvDvsM%2FQpG1PaeKq7jq7kfl4MIt7KkwPs8LyuEMIkaLznfkdpSMFw%3D&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIA4NRRSZPHFPQ3GI5S/20230213/us-west-2/s3/aws4_request&X-Amz-Date=20230213T054546Z&X-Amz-SignedHeaders=host&X-Amz-Signature=f3d62c0952b8bc772a77c3d146b7fb55a8e86129b5cb351500f73aead8c1dbfa", "https://pdf-temp-files.s3.us-west-2.amazonaws.com/98TZ8L6PIAX3QWHF4POX4Q9TN6BHPIIH/invoice-extracted_page2.pdf?X-Amz-Expires=3600&X-Amz-Security-Token=FwoGZXIvYXdzEG8aDKuBm3gDES1tmO7uSSKCATaP8OHW3vpxMhhGOh4utp7hCQzkW5aPbntexlu9TwfIMzceDB6zBv%2F5L4kWTEf8xwOqTckcDrAeDd0oL%2FbWpbPgP68r01OjXwSBbB0TMu3KftSf7VN%2B7NhOl4MXX1HIOSCrvcCUvLOql2DcpVhjFwPJ%2B1JMx6yorVx1zNMLwj98Kuco%2FI6nnwYyKBbvDvsM%2FQpG1PaeKq7jq7kfl4MIt7KkwPs8LyuEMIkaLznfkdpSMFw%3D&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIA4NRRSZPHFPQ3GI5S/20230213/us-west-2/s3/aws4_request&X-Amz-Date=20230213T054546Z&X-Amz-SignedHeaders=host&X-Amz-Signature=98d5bf380c9176f410178b1554dae798faad7158f52153bbe1dbe1b86cb91fe7" ], "pageCount": 3, "error": false, "status": 200, "name": "invoice-extracted.pdf", "credits": 105, "duration": 465, "remainingCredits": 1166270 }'; + res.setHeader('Content-Type', 'application/json'); + res.setBody(testBody); + res.setStatusCode(200); + return res; + } + } +} \ No newline at end of file diff --git a/PDF from HTML template/VB.NET/Invoice With Multiple Pages/packages.config b/PDF from HTML template/VB.NET/Invoice With Multiple Pages/packages.config index 03c709252..d9261b814 100644 --- a/PDF from HTML template/VB.NET/Invoice With Multiple Pages/packages.config +++ b/PDF from HTML template/VB.NET/Invoice With Multiple Pages/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file