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
3 changes: 3 additions & 0 deletions src/pages/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@
- [Java](overview/pdf-extract-api/quickstarts/extract-pdf/java/index.md)
- [.NET](overview/pdf-extract-api/quickstarts/extract-pdf/dotnet/index.md)
- [Python](overview/pdf-extract-api/quickstarts/extract-pdf/python/index.md)
- [PDF to Markdown](overview/pdf-extract-api/quickstarts/pdf-to-markdown/index.md)
- [.NET](overview/pdf-extract-api/quickstarts/pdf-to-markdown/dotnet/index.md)
- [Python](overview/pdf-extract-api/quickstarts/pdf-to-markdown/python/index.md)
- [How Tos](overview/pdf-extract-api/howtos/index.md)
- [PDF Extract API](overview/pdf-extract-api/howtos/extract-api.md)
- [PDF to Markdown API](overview/pdf-extract-api/howtos/pdf-to-markdown-api.md)
Expand Down
414 changes: 401 additions & 13 deletions src/pages/overview/pdf-extract-api/howtos/extract-api.md

Large diffs are not rendered by default.

340 changes: 340 additions & 0 deletions src/pages/overview/pdf-extract-api/howtos/pdf-to-markdown-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,343 @@ For File Constraints and Processing Limits, see [Licensing and Usage Limits](../
## REST API

See our public API Reference for [PDF to Markdown API](../../../apis/index.md#tag/PDF-To-Markdown).

## Get Markdown from a PDF

Use the sample below to create Markdowns from PDFs

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

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

#### .NET

```javascript
// Get the samples from https://github.com/adobe/PDFServices.NET.SDK.Samples
// Run the sample:
// cd PDFToMarkdown/
// dotnet run PDFToMarkdown.csproj
namespace PDFToMarkdown
{
class Program
{
private static readonly ILog log = LogManager.GetLogger(typeof(Program));

static void Main()
{
ConfigureLogging();
try
{
ICredentials credentials = new ServicePrincipalCredentials(
Environment.GetEnvironmentVariable("PDF_SERVICES_CLIENT_ID"),
Environment.GetEnvironmentVariable("PDF_SERVICES_CLIENT_SECRET"));

PDFServices pdfServices = new PDFServices(credentials);

using Stream inputStream = File.OpenRead(@"pdfToMarkdownInput.pdf");
IAsset asset = pdfServices.Upload(inputStream, PDFServicesMediaType.PDF.GetMIMETypeValue());


PDFToMarkdownJob pdfToMarkdownJob = new PDFToMarkdownJob(asset);

String location = pdfServices.Submit(pdfToMarkdownJob);
PDFServicesResponse<PDFToMarkdownResult> pdfServicesResponse =
pdfServices.GetJobResult<PDFToMarkdownResult>(location, typeof(PDFToMarkdownResult));

IAsset resultAsset = pdfServicesResponse.Result.Asset;
StreamAsset streamAsset = pdfServices.GetContent(resultAsset);

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"));
}

private static String CreateOutputFilePath()
{
String timeStamp = DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH'-'mm'-'ss");
return ("/output/pdfToMarkdown" + timeStamp + ".md");
}
}
}
```

#### Python

```python
# Get the samples https://github.com/adobe/pdfservices-python-sdk-samples
# Run the sample:
# python src/pdftomarkdown/pdf_to_markdown.py

# Initialize the logger
logging.basicConfig(level=logging.INFO)

class PDFToMarkdown:
def __init__(self):
try:
file = open('src/resources/pdfToMarkdownInput.pdf', 'rb')
input_stream = file.read()
file.close()

# Initial setup, create credentials instance
credentials = ServicePrincipalCredentials(
client_id=os.getenv('PDF_SERVICES_CLIENT_ID'),
client_secret=os.getenv('PDF_SERVICES_CLIENT_SECRET')
)

# Creates a PDF Services instance
pdf_services = PDFServices(credentials=credentials)

# Creates an asset(s) from source file(s) and upload
input_asset = pdf_services.upload(input_stream=input_stream,
mime_type=PDFServicesMediaType.PDF)

# Creates a new job instance
pdf_to_markdown_job = PDFToMarkdownJob(input_asset=input_asset)

# Submit the job and gets the job result
location = pdf_services.submit(pdf_to_markdown_job)
pdf_services_response = pdf_services.get_job_result(location, PDFToMarkdownResult)

# Get content from the resulting asset(s)
result_asset: CloudAsset = pdf_services_response.get_result().get_asset()
stream_asset: StreamAsset = pdf_services.get_content(result_asset)

# Creates an output stream and copy stream asset's content to it
output_file_path = self.create_output_file_path()
with open(output_file_path, "wb") as file:
file.write(stream_asset.get_input_stream())

except (ServiceApiException, ServiceUsageException, SdkException) as e:
logging.exception(f'Exception encountered while executing operation: {e}')

# Generates a string containing a directory structure and file name for the output file
@staticmethod
def create_output_file_path() -> str:
now = datetime.now()
time_stamp = now.strftime("%Y-%m-%dT%H-%M-%S")
os.makedirs("output/PDFToMarkdown", exist_ok=True)
return f"output/PDFToMarkdown/markdown{time_stamp}.md"


if __name__ == "__main__":
PDFToMarkdown()
```

#### REST API

```javascript
// Please refer our REST API docs for more information
// https://developer.adobe.com/document-services/docs/apis/#tag/PDF-To-Markdown

curl --location --request POST 'https://pdf-services.adobe.io/operation/pdftomarkdown' \
--header 'x-api-key: {{Placeholder for client_id}}' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{Placeholder for token}}' \
--data-raw '{
"assetID": "urn:aaid:AS:UE1:23c30ee0-2e4d-46d6-87f2-087832fca718"
}'
```

## Get Markdown from a PDF with Figures

Use the sample below to create Markdowns from PDFs with figures embedded in the PDFs

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

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

#### .NET

```javascript
// Get the samples from https://github.com/adobe/PDFServices.NET.SDK.Samples
// Run the sample:
// cd PDFToMarkdownWithFigures/
// dotnet run PDFToMarkdownWithFigures.csproj
namespace PDFToMarkdownWithFigures
{
class Program
{
private static readonly ILog log = LogManager.GetLogger(typeof(Program));

static void Main()
{
ConfigureLogging();
try
{
ICredentials credentials = new ServicePrincipalCredentials(
Environment.GetEnvironmentVariable("PDF_SERVICES_CLIENT_ID"),
Environment.GetEnvironmentVariable("PDF_SERVICES_CLIENT_SECRET"));

PDFServices pdfServices = new PDFServices(credentials);

using Stream inputStream = File.OpenRead(@"pdfToMarkdownInput.pdf");
IAsset asset = pdfServices.Upload(inputStream, PDFServicesMediaType.PDF.GetMIMETypeValue());

// Create parameters for the job (include figure renditions in the output)
PDFToMarkdownParams pdfToMarkdownParams = PDFToMarkdownParams.PDFToMarkdownParamsBuilder()
.WithGetFigures(true)
.Build();

PDFToMarkdownJob pdfToMarkdownJob = new PDFToMarkdownJob(asset)
.SetParams(pdfToMarkdownParams);

String location = pdfServices.Submit(pdfToMarkdownJob);
PDFServicesResponse<PDFToMarkdownResult> pdfServicesResponse =
pdfServices.GetJobResult<PDFToMarkdownResult>(location, typeof(PDFToMarkdownResult));

IAsset resultAsset = pdfServicesResponse.Result.Asset;
StreamAsset streamAsset = pdfServices.GetContent(resultAsset);

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"));
}

private static String CreateOutputFilePath()
{
String timeStamp = DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH'-'mm'-'ss");
return ("/output/pdfToMarkdownWithFigures" + timeStamp + ".md");
}
}
}
```

#### Python

```python
# Get the samples https://github.com/adobe/pdfservices-python-sdk-samples
# Run the sample:
# python src/pdftomarkdown/pdf_to_markdown.py

# Initialize the logger
logging.basicConfig(level=logging.INFO)

class PDFToMarkdownWithOptions:
def __init__(self):
try:
file = open('src/resources/pdfToMarkdownInput.pdf', 'rb')
input_stream = file.read()
file.close()

# Initial setup, create credentials instance
credentials = ServicePrincipalCredentials(
client_id=os.getenv('PDF_SERVICES_CLIENT_ID'),
client_secret=os.getenv('PDF_SERVICES_CLIENT_SECRET')
)

# Creates a PDF Services instance
pdf_services = PDFServices(credentials=credentials)

# Creates an asset(s) from source file(s) and upload
input_asset = pdf_services.upload(input_stream=input_stream,
mime_type=PDFServicesMediaType.PDF)

# Create parameters for the job with figures extraction enabled
pdf_to_markdown_params = PDFToMarkdownParams(get_figures=True)

# Creates a new job instance
pdf_to_markdown_job = PDFToMarkdownJob(input_asset=input_asset,
pdf_to_markdown_params=pdf_to_markdown_params)

# Submit the job and gets the job result
location = pdf_services.submit(pdf_to_markdown_job)
pdf_services_response = pdf_services.get_job_result(location, PDFToMarkdownResult)

# Get content from the resulting asset(s)
result_asset: CloudAsset = pdf_services_response.get_result().get_asset()
stream_asset: StreamAsset = pdf_services.get_content(result_asset)

# Creates an output stream and copy stream asset's content to it
output_file_path = self.create_output_file_path()
with open(output_file_path, "wb") as file:
file.write(stream_asset.get_input_stream())

except (ServiceApiException, ServiceUsageException, SdkException) as e:
logging.exception(f'Exception encountered while executing operation: {e}')

# Generates a string containing a directory structure and file name for the output file
@staticmethod
def create_output_file_path() -> str:
now = datetime.now()
time_stamp = now.strftime("%Y-%m-%dT%H-%M-%S")
os.makedirs("output/PDFToMarkdownWithOptions", exist_ok=True)
return f"output/PDFToMarkdownWithOptions/markdown{time_stamp}.md"


if __name__ == "__main__":
PDFToMarkdownWithOptions()
```

#### REST API

```javascript
// Please refer our REST API docs for more information
// https://developer.adobe.com/document-services/docs/apis/#tag/PDF-To-Markdown

curl --location --request POST 'https://pdf-services.adobe.io/operation/pdftomarkdown' \
--header 'x-api-key: {{Placeholder for client_id}}' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{Placeholder for token}}' \
--data-raw '{
"assetID": "urn:aaid:AS:UE1:23c30ee0-2e4d-46d6-87f2-087832fca718",
"getFigures": true
}'
```
3 changes: 2 additions & 1 deletion src/pages/overview/pdf-extract-api/quickstarts/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ description: |

Want to quickly test out Extract PDF API and PDF To Markdown API? Choose your operation to get started:

* [Extract PDF](extract-pdf/index.md)
* [Extract PDF](extract-pdf/index.md)
* [PDF to Markdown](pdf-to-markdown/index.md)
Binary file not shown.
Loading
Loading