-
Notifications
You must be signed in to change notification settings - Fork 10
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
1 parent
3ee4fa9
commit 983f3c8
Showing
24 changed files
with
741 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.Text; | ||
|
||
using (var httpClient = new HttpClient { BaseAddress = new Uri("https://api.pdfrest.com") }) | ||
{ | ||
using (var request = new HttpRequestMessage(HttpMethod.Post, "excel")) | ||
{ | ||
request.Headers.TryAddWithoutValidation("Api-Key", "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); | ||
request.Headers.Accept.Add(new("application/json")); | ||
var multipartContent = new MultipartFormDataContent(); | ||
|
||
var byteArray = File.ReadAllBytes("/path/to/file"); | ||
var byteAryContent = new ByteArrayContent(byteArray); | ||
multipartContent.Add(byteAryContent, "file", "file_name"); | ||
byteAryContent.Headers.TryAddWithoutValidation("Content-Type", "application/pdf"); | ||
|
||
|
||
request.Content = multipartContent; | ||
var response = await httpClient.SendAsync(request); | ||
|
||
var apiResult = await response.Content.ReadAsStringAsync(); | ||
|
||
Console.WriteLine("API response received."); | ||
Console.WriteLine(apiResult); | ||
} | ||
} |
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 @@ | ||
using System.Text; | ||
|
||
using (var httpClient = new HttpClient { BaseAddress = new Uri("https://api.pdfrest.com") }) | ||
{ | ||
using (var request = new HttpRequestMessage(HttpMethod.Post, "powerpoint")) | ||
{ | ||
request.Headers.TryAddWithoutValidation("Api-Key", "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); | ||
request.Headers.Accept.Add(new("application/json")); | ||
var multipartContent = new MultipartFormDataContent(); | ||
|
||
var byteArray = File.ReadAllBytes("/path/to/file"); | ||
var byteAryContent = new ByteArrayContent(byteArray); | ||
multipartContent.Add(byteAryContent, "file", "file_name"); | ||
byteAryContent.Headers.TryAddWithoutValidation("Content-Type", "application/pdf"); | ||
|
||
|
||
request.Content = multipartContent; | ||
var response = await httpClient.SendAsync(request); | ||
|
||
var apiResult = await response.Content.ReadAsStringAsync(); | ||
|
||
Console.WriteLine("API response received."); | ||
Console.WriteLine(apiResult); | ||
} | ||
} |
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 @@ | ||
using System.Text; | ||
|
||
using (var httpClient = new HttpClient { BaseAddress = new Uri("https://api.pdfrest.com") }) | ||
{ | ||
using (var request = new HttpRequestMessage(HttpMethod.Post, "word")) | ||
{ | ||
request.Headers.TryAddWithoutValidation("Api-Key", "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); | ||
request.Headers.Accept.Add(new("application/json")); | ||
var multipartContent = new MultipartFormDataContent(); | ||
|
||
var byteArray = File.ReadAllBytes("/path/to/file"); | ||
var byteAryContent = new ByteArrayContent(byteArray); | ||
multipartContent.Add(byteAryContent, "file", "file_name"); | ||
byteAryContent.Headers.TryAddWithoutValidation("Content-Type", "application/pdf"); | ||
|
||
|
||
request.Content = multipartContent; | ||
var response = await httpClient.SendAsync(request); | ||
|
||
var apiResult = await response.Content.ReadAsStringAsync(); | ||
|
||
Console.WriteLine("API response received."); | ||
Console.WriteLine(apiResult); | ||
} | ||
} |
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,61 @@ | ||
import io.github.cdimascio.dotenv.Dotenv; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import okhttp3.MediaType; | ||
import okhttp3.MultipartBody; | ||
import okhttp3.OkHttpClient; | ||
import okhttp3.Request; | ||
import okhttp3.RequestBody; | ||
import okhttp3.Response; | ||
import org.json.JSONObject; | ||
|
||
public class Excel { | ||
|
||
// Specify the path to your file here, or as the first argument when running the program. | ||
private static final String DEFAULT_FILE_PATH = "/path/to/file.pdf"; | ||
|
||
// Specify your API key here, or in the environment variable PDFREST_API_KEY. | ||
// You can also put the environment variable in a .env file. | ||
private static final String DEFAULT_API_KEY = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; | ||
|
||
public static void main(String[] args) { | ||
File inputFile; | ||
if (args.length > 0) { | ||
inputFile = new File(args[0]); | ||
} else { | ||
inputFile = new File(DEFAULT_FILE_PATH); | ||
} | ||
|
||
final Dotenv dotenv = Dotenv.configure().ignoreIfMalformed().ignoreIfMissing().load(); | ||
|
||
final RequestBody inputFileRequestBody = | ||
RequestBody.create(inputFile, MediaType.parse("application/pdf")); | ||
RequestBody requestBody = | ||
new MultipartBody.Builder() | ||
.setType(MultipartBody.FORM) | ||
.addFormDataPart("file", inputFile.getName(), inputFileRequestBody) | ||
.addFormDataPart("output", "pdfrest_excel") | ||
.build(); | ||
Request request = | ||
new Request.Builder() | ||
.header("Api-Key", dotenv.get("PDFREST_API_KEY", DEFAULT_API_KEY)) | ||
.url("https://api.pdfrest.com/excel") | ||
.post(requestBody) | ||
.build(); | ||
try { | ||
OkHttpClient client = new OkHttpClient().newBuilder().build(); | ||
Response response = client.newCall(request).execute(); | ||
System.out.println("Result code " + response.code()); | ||
if (response.body() != null) { | ||
System.out.println(prettyJson(response.body().string())); | ||
} | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private static String prettyJson(String json) { | ||
// https://stackoverflow.com/a/9583835/11996393 | ||
return new JSONObject(json).toString(4); | ||
} | ||
} |
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,61 @@ | ||
import io.github.cdimascio.dotenv.Dotenv; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import okhttp3.MediaType; | ||
import okhttp3.MultipartBody; | ||
import okhttp3.OkHttpClient; | ||
import okhttp3.Request; | ||
import okhttp3.RequestBody; | ||
import okhttp3.Response; | ||
import org.json.JSONObject; | ||
|
||
public class Powerpoint { | ||
|
||
// Specify the path to your file here, or as the first argument when running the program. | ||
private static final String DEFAULT_FILE_PATH = "/path/to/file.pdf"; | ||
|
||
// Specify your API key here, or in the environment variable PDFREST_API_KEY. | ||
// You can also put the environment variable in a .env file. | ||
private static final String DEFAULT_API_KEY = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; | ||
|
||
public static void main(String[] args) { | ||
File inputFile; | ||
if (args.length > 0) { | ||
inputFile = new File(args[0]); | ||
} else { | ||
inputFile = new File(DEFAULT_FILE_PATH); | ||
} | ||
|
||
final Dotenv dotenv = Dotenv.configure().ignoreIfMalformed().ignoreIfMissing().load(); | ||
|
||
final RequestBody inputFileRequestBody = | ||
RequestBody.create(inputFile, MediaType.parse("application/pdf")); | ||
RequestBody requestBody = | ||
new MultipartBody.Builder() | ||
.setType(MultipartBody.FORM) | ||
.addFormDataPart("file", inputFile.getName(), inputFileRequestBody) | ||
.addFormDataPart("output", "pdfrest_powerpoint") | ||
.build(); | ||
Request request = | ||
new Request.Builder() | ||
.header("Api-Key", dotenv.get("PDFREST_API_KEY", DEFAULT_API_KEY)) | ||
.url("https://api.pdfrest.com/powerpoint") | ||
.post(requestBody) | ||
.build(); | ||
try { | ||
OkHttpClient client = new OkHttpClient().newBuilder().build(); | ||
Response response = client.newCall(request).execute(); | ||
System.out.println("Result code " + response.code()); | ||
if (response.body() != null) { | ||
System.out.println(prettyJson(response.body().string())); | ||
} | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private static String prettyJson(String json) { | ||
// https://stackoverflow.com/a/9583835/11996393 | ||
return new JSONObject(json).toString(4); | ||
} | ||
} |
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,61 @@ | ||
import io.github.cdimascio.dotenv.Dotenv; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import okhttp3.MediaType; | ||
import okhttp3.MultipartBody; | ||
import okhttp3.OkHttpClient; | ||
import okhttp3.Request; | ||
import okhttp3.RequestBody; | ||
import okhttp3.Response; | ||
import org.json.JSONObject; | ||
|
||
public class Word { | ||
|
||
// Specify the path to your file here, or as the first argument when running the program. | ||
private static final String DEFAULT_FILE_PATH = "/path/to/file.pdf"; | ||
|
||
// Specify your API key here, or in the environment variable PDFREST_API_KEY. | ||
// You can also put the environment variable in a .env file. | ||
private static final String DEFAULT_API_KEY = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; | ||
|
||
public static void main(String[] args) { | ||
File inputFile; | ||
if (args.length > 0) { | ||
inputFile = new File(args[0]); | ||
} else { | ||
inputFile = new File(DEFAULT_FILE_PATH); | ||
} | ||
|
||
final Dotenv dotenv = Dotenv.configure().ignoreIfMalformed().ignoreIfMissing().load(); | ||
|
||
final RequestBody inputFileRequestBody = | ||
RequestBody.create(inputFile, MediaType.parse("application/pdf")); | ||
RequestBody requestBody = | ||
new MultipartBody.Builder() | ||
.setType(MultipartBody.FORM) | ||
.addFormDataPart("file", inputFile.getName(), inputFileRequestBody) | ||
.addFormDataPart("output", "pdfrest_word") | ||
.build(); | ||
Request request = | ||
new Request.Builder() | ||
.header("Api-Key", dotenv.get("PDFREST_API_KEY", DEFAULT_API_KEY)) | ||
.url("https://api.pdfrest.com/word") | ||
.post(requestBody) | ||
.build(); | ||
try { | ||
OkHttpClient client = new OkHttpClient().newBuilder().build(); | ||
Response response = client.newCall(request).execute(); | ||
System.out.println("Result code " + response.code()); | ||
if (response.body() != null) { | ||
System.out.println(prettyJson(response.body().string())); | ||
} | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private static String prettyJson(String json) { | ||
// https://stackoverflow.com/a/9583835/11996393 | ||
return new JSONObject(json).toString(4); | ||
} | ||
} |
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,32 @@ | ||
// This request demonstrates how to convert a PDF to an Excel file. | ||
var axios = require('axios'); | ||
var FormData = require('form-data'); | ||
var fs = require('fs'); | ||
|
||
// Create a new form data instance and append the PDF file and parameters to it | ||
var data = new FormData(); | ||
data.append('file', fs.createReadStream('/path/to/file')); | ||
data.append('output', 'pdfrest_linearized_pdf'); | ||
|
||
// define configuration options for axios request | ||
var config = { | ||
method: 'post', | ||
maxBodyLength: Infinity, // set maximum length of the request body | ||
url: 'https://api.pdfrest.com/excel', | ||
headers: { | ||
'Api-Key': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', // Replace with your API key | ||
...data.getHeaders() // set headers for the request | ||
}, | ||
data : data // set the data to be sent with the request | ||
}; | ||
|
||
// send request and handle response or error | ||
axios(config) | ||
.then(function (response) { | ||
console.log(JSON.stringify(response.data)); | ||
}) | ||
.catch(function (error) { | ||
console.log(error); | ||
}); | ||
|
||
// If you would like to download the file instead of getting the JSON response, please see the 'get-resource-id-endpoint.js' sample. |
32 changes: 32 additions & 0 deletions
32
JavaScript/Endpoint Examples/Multipart Payload/powerpoint.js
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,32 @@ | ||
// This request demonstrates how to convert a PDF to a PowerPoint file. | ||
var axios = require('axios'); | ||
var FormData = require('form-data'); | ||
var fs = require('fs'); | ||
|
||
// Create a new form data instance and append the PDF file and parameters to it | ||
var data = new FormData(); | ||
data.append('file', fs.createReadStream('/path/to/file')); | ||
data.append('output', 'pdfrest_linearized_pdf'); | ||
|
||
// define configuration options for axios request | ||
var config = { | ||
method: 'post', | ||
maxBodyLength: Infinity, // set maximum length of the request body | ||
url: 'https://api.pdfrest.com/powerpoint', | ||
headers: { | ||
'Api-Key': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', // Replace with your API key | ||
...data.getHeaders() // set headers for the request | ||
}, | ||
data : data // set the data to be sent with the request | ||
}; | ||
|
||
// send request and handle response or error | ||
axios(config) | ||
.then(function (response) { | ||
console.log(JSON.stringify(response.data)); | ||
}) | ||
.catch(function (error) { | ||
console.log(error); | ||
}); | ||
|
||
// If you would like to download the file instead of getting the JSON response, please see the 'get-resource-id-endpoint.js' sample. |
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,32 @@ | ||
// This request demonstrates how to convert a PDF to a Word file. | ||
var axios = require('axios'); | ||
var FormData = require('form-data'); | ||
var fs = require('fs'); | ||
|
||
// Create a new form data instance and append the PDF file and parameters to it | ||
var data = new FormData(); | ||
data.append('file', fs.createReadStream('/path/to/file')); | ||
data.append('output', 'pdfrest_linearized_pdf'); | ||
|
||
// define configuration options for axios request | ||
var config = { | ||
method: 'post', | ||
maxBodyLength: Infinity, // set maximum length of the request body | ||
url: 'https://api.pdfrest.com/word', | ||
headers: { | ||
'Api-Key': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', // Replace with your API key | ||
...data.getHeaders() // set headers for the request | ||
}, | ||
data : data // set the data to be sent with the request | ||
}; | ||
|
||
// send request and handle response or error | ||
axios(config) | ||
.then(function (response) { | ||
console.log(JSON.stringify(response.data)); | ||
}) | ||
.catch(function (error) { | ||
console.log(error); | ||
}); | ||
|
||
// If you would like to download the file instead of getting the JSON response, please see the 'get-resource-id-endpoint.js' sample. |
Oops, something went wrong.