PDF to Markdown

The PDF to Markdown API (included with the PDF Services API) is a cloud-based web service that automatically converts PDF documents – native or scanned – into well-formatted LLM-friendly Markdown text. This service preserves the document's structure and formatting while converting it into a format that's widely used for LLM flows, content authoring and documentation.

Structured Information Output Format

The output of a PDF to Markdown operation includes:

Output Structure

The following is a summary of key elements in the converted Markdown:

Elements

Ordered list of semantic elements converted from the PDF document, preserving the natural reading order and document structure. The conversion handles:

Content Types

The API processes various content types as follows:

Text Elements
Images and Figures
Tables

Element Types and Paths

The API recognizes and converts the following structural elements:

Category
Element Type
Description
Aside
Aside
Content that is not part of the regular content flow
Figure
Figure
Non-reflowable constructs such as graphs, images, and flowcharts
Footnote
Footnote
Footnote
Headings
H, H1, H2, etc
Heading levels
List
L, Li, Lbl, Lbody
List and list item elements
Paragraph
P, ParagraphSpan
Paragraphs and paragraph segments
Reference
Reference
Links
Section
Sect
Logical section of the document
StyleSpan
StyleSpan
Styling variations within text
Table
Table, TD, TH, TR
Table elements
Title
Title
Document title

Reading Order

The reading order in the output Markdown maintains:

Use Cases

The PDF to Markdown API is particularly valuable for:

API Limitations

For File Constraints and Processing Limits, see Licensing and Usage Limits.

Document Requirements

REST API

See our public API Reference for PDF to Markdown API.

Get Markdown from a PDF

Use the sample below to create Markdowns from PDFs

Please refer the API usage guide to understand how to use our APIs.

data-slots=heading, code
data-repeat=3
data-languages=.NET, Python, REST API

.NET

// 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

# 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

// 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 to understand how to use our APIs.

data-slots=heading, code
data-repeat=3
data-languages=.NET, Python, REST API

.NET

// 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

# 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

// 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
}'