Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/pages/overview/pdf-services-api/howtos/create-pdf.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Create PDF | How Tos | PDF Services API | Adobe PDF Services
---
# Create PDF

Create PDFs from a variety of formats, including static and dynamic HTML; Microsoft Word, PowerPoint, and Excel; as well as text, image, Zip, and URL. Support for HTML to PDF, DOC to PDF, DOCX to PDF, PPT to PDF, PPTX to PDF, XLS to PDF, XLSX to PDF, TXT to PDF, RTF to PDF, BMP to PDF, JPEG to PDF, GIF to PDF, TIFF to PDF, PNG to PDF
Create PDFs from a variety of formats, including static and dynamic HTML; Microsoft Word, PowerPoint, and Excel; as well as text, image, Zip, and URL. Support for HTML to PDF, DOC to PDF, DOCX to PDF, PPT to PDF, PPTX to PDF, XLS to PDF, XLSX to PDF, TXT to PDF, MD to PDF, RTF to PDF, BMP to PDF, JPEG to PDF, GIF to PDF, TIFF to PDF, PNG to PDF

## REST API

Expand All @@ -24,7 +24,7 @@ following formats:
- Microsoft Word (DOC, DOCX)
- Microsoft PowerPoint (PPT, PPTX)
- Microsoft Excel (XLS, XLSX)
- Text (TXT, RTF)
- Text (TXT, RTF, MARKDOWN)
- Image (BMP, JPEG, GIF, TIFF, PNG)

<InlineAlert slots="text"/>
Expand Down
153 changes: 152 additions & 1 deletion src/pages/overview/pdf-services-api/howtos/export-pdf-form-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ The sample below exports PDF form data and returns it as a JSON file.

Please refer to the [API usage guide](../api-usage.md) to understand how to use our APIs.

<CodeBlock slots="heading, code" repeat="3" languages="Java, Python, REST API" />
<CodeBlock slots="heading, code" repeat="5" languages="Java, .NET, Node JS, Python, REST API" />

#### Java

Expand Down Expand Up @@ -79,6 +79,157 @@ public class ExportPDFFormData {
}
}
```
#### .NET

```javascript
// Get the samples from https://www.adobe.com/go/pdftoolsapi_net_samples
// Run the sample:
// cd ExportPDFFormData/
// dotnet run ExportPDFFormData.csproj

namespace ExportPDFFormData
{
class Program
{
private static readonly ILog log = LogManager.GetLogger(typeof(Program));

static void Main()
{
//Configure the logging
ConfigureLogging();
try
{
// Initial setup, create credentials instance
ICredentials credentials = new ServicePrincipalCredentials(
Environment.GetEnvironmentVariable("PDF_SERVICES_CLIENT_ID"),
Environment.GetEnvironmentVariable("PDF_SERVICES_CLIENT_SECRET"));

// Creates a PDF Services instance
PDFServices pdfServices = new PDFServices(credentials);

// Creates an asset(s) from source file(s) and upload
using Stream inputStream = File.OpenRead(@"exportPdfFormDataInput.pdf");
IAsset asset = pdfServices.Upload(inputStream, PDFServicesMediaType.PDF.GetMIMETypeValue());

// Creates a new job instance
ExportPDFFormDataJob exportPDFFormDataJob = new ExportPDFFormDataJob(asset);

// Submits the job and gets the job result
String location = pdfServices.Submit(exportPDFFormDataJob);
PDFServicesResponse<ExportPDFFormDataResult> pdfServicesResponse =
pdfServices.GetJobResult<ExportPDFFormDataResult>(location, typeof(ExportPDFFormDataResult));

// Get content from the resulting asset(s)
IAsset resultAsset = pdfServicesResponse.Result.Asset;
StreamAsset streamAsset = pdfServices.GetContent(resultAsset);

// Creating output streams and copying stream asset's content to it
String outputFilePath = CreateOutputFilePath();
new FileInfo(Directory.GetCurrentDirectory() + outputFilePath).Directory.Create();
Stream outputStream = File.OpenWrite(Directory.GetCurrentDirectory() + outputFilePath);
streamAsset.Stream.CopyTo(outputStream);
outputStream.Close();
}
catch (ServiceUsageException ex)
{
log.Error("Exception encountered while executing operation", ex);
}
catch (ServiceApiException ex)
{
log.Error("Exception encountered while executing operation", ex);
}
catch (SDKException ex)
{
log.Error("Exception encountered while executing operation", ex);
}
catch (IOException ex)
{
log.Error("Exception encountered while executing operation", ex);
}
catch (Exception ex)
{
log.Error("Exception encountered while executing operation", ex);
}
}

static void ConfigureLogging()
{
ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));
}
}
}
```

#### Node JS

```javascript
// Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample
// Run the sample:
// node src/importpdfformdata/import-pdf-form-data.js

const {
ServicePrincipalCredentials,
PDFServices,
MimeType,
ExportPDFFormDataJob,
ExportPDFFormDataResult,
SDKError,
ServiceUsageError,
ServiceApiError
} = require("@adobe/pdfservices-node-sdk");
const fs = require("fs");

(async () => {
let readStream;
try {
// Initial setup, create credentials instance
const credentials = new ServicePrincipalCredentials({
clientId: process.env.PDF_SERVICES_CLIENT_ID,
clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET
});

// Creates a PDF Services instance
const pdfServices = new PDFServices({credentials});

// Creates an asset(s) from source file(s) and uploads
readStream = fs.createReadStream("resources/exportPdfFormDataInput.pdf");
const inputAsset = await pdfServices.upload({
readStream,
mimeType: MimeType.PDF
});

// Creates a new job instance
const job = new ExportPDFFormDataJob({inputAsset});

// Submit the job and get the job result
const pollingURL = await pdfServices.submit({job});
const pdfServicesResponse = await pdfServices.getJobResult({
pollingURL,
resultType: ExportPDFFormDataResult
});

// Get content from the resulting asset(s)
const resultAsset = pdfServicesResponse.result.asset;
const streamAsset = await pdfServices.getContent({asset: resultAsset});

// Creates an output stream and copy stream asset's content to it
const outputFilePath = createOutputFilePath();
console.log(`Saving asset at ${outputFilePath}`);

const outputStream = fs.createWriteStream(outputFilePath);
streamAsset.readStream.pipe(outputStream);
} catch (err) {
if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) {
console.log("Exception encountered while executing operation", err);
} else {
console.log("Exception encountered while executing operation", err);
}
} finally {
readStream?.destroy();
}
})();
```

#### Python

Expand Down
181 changes: 180 additions & 1 deletion src/pages/overview/pdf-services-api/howtos/import-pdf-form-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ The sample below demonstrates how to import form data from a JSON into PDF and g

Please refer to the [API usage guide](../api-usage.md) to understand how to use our APIs.

<CodeBlock slots="heading, code" repeat="3" languages="Java, Python, REST API" />
<CodeBlock slots="heading, code" repeat="5" languages="Java, .NET, Node JS, Python, REST API" />

#### Java

Expand Down Expand Up @@ -94,6 +94,185 @@ public class ImportPdfFormData {
}
}
```
#### .NET

```javascript
// Get the samples from https://www.adobe.com/go/pdftoolsapi_net_samples
// Run the sample:
// cd ImportPDFFormData/
// dotnet run ImportPDFFormData.csproj

namespace ImportPDFFormData
{
class Program
{
private static readonly ILog log = LogManager.GetLogger(typeof(Program));

static void Main()
{
//Configure the logging
ConfigureLogging();
try
{
// Initial setup, create credentials instance
ICredentials credentials = new ServicePrincipalCredentials(
Environment.GetEnvironmentVariable("PDF_SERVICES_CLIENT_ID"),
Environment.GetEnvironmentVariable("PDF_SERVICES_CLIENT_SECRET"));

// Creates a PDF Services instance
PDFServices pdfServices = new PDFServices(credentials);

// Creates an asset(s) from source file(s) and upload
using Stream inputStream = File.OpenRead(@"importPdfFormDataInput.pdf");
IAsset asset = pdfServices.Upload(inputStream, PDFServicesMediaType.PDF.GetMIMETypeValue());

// Create parameters for the job
var formData = new JObject(
new JProperty("option_two", "Yes"),
new JProperty("option_one", "Yes"),
new JProperty("name", "sufia"),
new JProperty("option_three", "Off"),
new JProperty("age", "25"),
new JProperty("favorite_movie", "Star Wars Again")
);

ImportPDFFormDataParams importParams = ImportPDFFormDataParams.ImportPDFFormDataParamsBuilder()
.WithJsonFormFieldsData(formData)
.Build();

// Creates a new job instance
ImportPDFFormDataJob importPDFFormDataJob = new ImportPDFFormDataJob(asset);
importPDFFormDataJob.SetParams(importParams);

// Submits the job and gets the job result
String location = pdfServices.Submit(importPDFFormDataJob);
PDFServicesResponse<ImportPDFFormDataResult> pdfServicesResponse =
pdfServices.GetJobResult<ImportPDFFormDataResult>(location, typeof(ImportPDFFormDataResult));

// Get content from the resulting asset(s)
IAsset resultAsset = pdfServicesResponse.Result.Asset;
StreamAsset streamAsset = pdfServices.GetContent(resultAsset);

// Creating output streams and copying stream asset's content to it
String outputFilePath = CreateOutputFilePath();
new FileInfo(Directory.GetCurrentDirectory() + outputFilePath).Directory.Create();
Stream outputStream = File.OpenWrite(Directory.GetCurrentDirectory() + outputFilePath);
streamAsset.Stream.CopyTo(outputStream);
outputStream.Close();
}
catch (ServiceUsageException ex)
{
log.Error("Exception encountered while executing operation", ex);
}
catch (ServiceApiException ex)
{
log.Error("Exception encountered while executing operation", ex);
}
catch (SDKException ex)
{
log.Error("Exception encountered while executing operation", ex);
}
catch (IOException ex)
{
log.Error("Exception encountered while executing operation", ex);
}
catch (Exception ex)
{
log.Error("Exception encountered while executing operation", ex);
}
}

static void ConfigureLogging()
{
ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));
}
}
}
```

#### Node JS

```javascript
// Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample
// Run the sample:
// node src/importpdfformdata/import-pdf-form-data.js

const {
ServicePrincipalCredentials,
PDFServices,
MimeType,
ImportPDFFormDataJob,
ImportPDFFormDataResult,
ImportPDFFormDataParams,
SDKError,
ServiceUsageError,
ServiceApiError
} = require("@adobe/pdfservices-node-sdk");
const fs = require("fs");

(async () => {
let readStream;
try {
// Initial setup, create credentials instance
const credentials = new ServicePrincipalCredentials({
clientId: process.env.PDF_SERVICES_CLIENT_ID,
clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET
});

// Creates a PDF Services instance
const pdfServices = new PDFServices({credentials});

// Creates an asset(s) from source file(s) and uploads
readStream = fs.createReadStream("resources/importPdfFormDataInput.pdf");
const inputAsset = await pdfServices.upload({
readStream,
mimeType: MimeType.PDF
});

// Create parameters for the job
const params = new ImportPDFFormDataParams({
jsonFormFieldsData: {
"option_two": "Yes",
"option_one": "Off",
"name": "Supratim",
"option_three": "Off",
"age": "23",
"favorite_movie": "The Empire Strikes Back"
}
});

// Creates a new job instance
const job = new ImportPDFFormDataJob({ inputAsset, params });

// Submit the job and get the job result
const pollingURL = await pdfServices.submit({job});
const pdfServicesResponse = await pdfServices.getJobResult({
pollingURL,
resultType: ImportPDFFormDataResult
});

// Get content from the resulting asset(s)
const resultAsset = pdfServicesResponse.result.asset;
const streamAsset = await pdfServices.getContent({asset: resultAsset});

// Creates an output stream and copy stream asset's content to it
const outputFilePath = createOutputFilePath();
console.log(`Saving asset at ${outputFilePath}`);

const outputStream = fs.createWriteStream(outputFilePath);
streamAsset.readStream.pipe(outputStream);
} catch (err) {
if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) {
console.log("Exception encountered while executing operation", err);
} else {
console.log("Exception encountered while executing operation", err);
}
} finally {
readStream?.destroy();
}
})();
```

#### Python

Expand Down
Loading