-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
800 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...mage From PDF/C#/Replace Placeholder With Signature/ByteScoutWebApiExample.NETCore.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
<EnableDefaultCompileItems>false</EnableDefaultCompileItems> | ||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> | ||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> | ||
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute> | ||
<GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute> | ||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> | ||
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute> | ||
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute> | ||
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute> | ||
<GenerateAssemblyTrademarkAttribute>false</GenerateAssemblyTrademarkAttribute> | ||
<GenerateAssemblyCultureAttribute>false</GenerateAssemblyCultureAttribute> | ||
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<EmbeddedResource Remove="Properties\**" /> | ||
<None Remove="Properties\**" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Program.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Windows.Compatibility" Version="2.0.0" /> | ||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Update="sample.pdf"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
</Project> |
25 changes: 25 additions & 0 deletions
25
...h Image From PDF/C#/Replace Placeholder With Signature/ByteScoutWebApiExample.NETCore.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
60 changes: 60 additions & 0 deletions
60
...t With Image From PDF/C#/Replace Placeholder With Signature/ByteScoutWebApiExample.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{1E1C2C34-017E-4605-AE2B-55EA3313BE51}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>ByteScoutWebApiExample</RootNamespace> | ||
<AssemblyName>ByteScoutWebApiExample</AssemblyName> | ||
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> | ||
<HintPath>packages\Newtonsoft.Json.10.0.3\lib\net40\Newtonsoft.Json.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
22 changes: 22 additions & 0 deletions
22
...Text With Image From PDF/C#/Replace Placeholder With Signature/ByteScoutWebApiExample.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
147 changes: 147 additions & 0 deletions
147
...Web API/Replace Text With Image From PDF/C#/Replace Placeholder With Signature/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
//*******************************************************************************************// | ||
// // | ||
// 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 "Replace Text With Image 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 = "*****************************"; | ||
|
||
// Direct URL of source PDF file. | ||
// You can also upload your own file into PDF.co and use it as url. Check "Upload File" samples for code snippets: https://github.com/bytescout/pdf-co-api-samples/tree/master/File%20Upload/ | ||
const string SourceFileUrl = "https://pdfco-test-files.s3.us-west-2.amazonaws.com/pdf-search-and-replace/sample-agreement-template-signature-page-2.pdf"; | ||
// PDF document password. Leave empty for unprotected documents. | ||
const string Password = ""; | ||
// Destination PDF file name | ||
const string DestinationFile = @".\result.pdf"; | ||
// (!) Make asynchronous job | ||
const bool Async = true; | ||
|
||
|
||
static void Main(string[] args) | ||
{ | ||
// Create standard .NET web client instance | ||
WebClient webClient = new WebClient(); | ||
|
||
// Set API Key | ||
webClient.Headers.Add("x-api-key", API_KEY); | ||
|
||
// URL for `Replace Text With Image from PDF` API call | ||
string url = "https://api.pdf.co/v1/pdf/edit/replace-text-with-image"; | ||
|
||
// Prepare requests params as JSON | ||
Dictionary<string, object> parameters = new Dictionary<string, object>(); | ||
parameters.Add("name", Path.GetFileName(DestinationFile)); | ||
parameters.Add("password", Password); | ||
parameters.Add("url", SourceFileUrl); | ||
parameters.Add("async", Async); | ||
parameters.Add("searchString", "[CLIENT-SIGNATURE]"); | ||
parameters.Add("caseSensitive", true); | ||
parameters.Add("replaceImage", "https://pdfco-test-files.s3.us-west-2.amazonaws.com/pdf-search-and-replace/john-doe-signature-image.png"); | ||
|
||
// Convert dictionary of params to JSON | ||
string jsonPayload = JsonConvert.SerializeObject(parameters); | ||
|
||
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<bool>() == 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(); | ||
} | ||
|
||
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"]); | ||
} | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...Text With Image From PDF/C#/Replace Placeholder With Signature/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")] |
4 changes: 4 additions & 0 deletions
4
...PI/Replace Text With Image From PDF/C#/Replace Placeholder With Signature/packages.config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net40" /> | ||
</packages> |
Oops, something went wrong.