Skip to content

Instantly share code, notes, and snippets.

Convert Markdown to PDF and PDF to Markdown in Python

You can convert Markdown to PDF and PDF to Markdown online programmatically in Python on the cloud. In this article, we will learn how to convert Markdown to PDF and PDF to Markdown in Python.

The following topics shall be covered in this article:

  1. Python Markdown to PDF and PDF to Markdown Converter Library
  2. Convert Markdown to PDF in Python using REST API
  3. Convert Markdown to PDF Online using Advanced Options in Python
  4. Convert PDF to Markdown in Python using REST API
# How to Convert Markdown to PDF using Advanced Options in Python
try:
# Create an instance of the API
convert_api = groupdocs_conversion_cloud.ConvertApi.from_keys(client_id, client_secret)
# Define convert settings
settings = groupdocs_conversion_cloud.ConvertSettings()
settings.storage_name = storage_name
settings.file_path = "python-testing/input-sample-file.md"
settings.format = "pdf"
# PDF convert options
convertOptions = groupdocs_conversion_cloud.PdfConvertOptions()
convertOptions.center_window = True
convertOptions.compress_images = False
convertOptions.display_doc_title = True
convertOptions.dpi = 1024.0
convertOptions.fit_window = False
convertOptions.from_page = 1
convertOptions.pages_count = 1
convertOptions.grayscale = False
convertOptions.image_quality = 100
convertOptions.linearize = False
convertOptions.margin_top = 5
convertOptions.margin_left = 5
convertOptions.unembed_fonts = True
convertOptions.remove_unused_streams = True
convertOptions.remove_unused_objects = True
convertOptions.remove_pdfa_compliance = False
settings.convert_options = convertOptions
settings.output_path = "python-testing/output-sample-file.pdf"
request = groupdocs_conversion_cloud.ConvertDocumentRequest(settings)
response = convert_api.convert_document(request)
print("Successfully converted MD to PDF online in Python: " + str(response))
except groupdocs_conversion_cloud.ApiException as e:
print("Exception while calling API: {0}".format(e.message))
# How to Convert Markdown to PDF in Python using REST API
try:
# Create an instance of the API
convert_api = groupdocs_conversion_cloud.ConvertApi.from_keys(client_id, client_secret)
# Define convert settings
settings = groupdocs_conversion_cloud.ConvertSettings()
settings.storage_name = storage_name
settings.file_path = "python-testing/input-sample-file.md"
settings.format = "pdf"
settings.output_path = "python-testing/output-sample-file.pdf"
request = groupdocs_conversion_cloud.ConvertDocumentRequest(settings)
response = convert_api.convert_document(request)
print("Successfully converted MD file to PDF online in Python: " + str(response))
except groupdocs_conversion_cloud.ApiException as e:
print("Exception while calling API: {0}".format(e.message))
# How to Convert PDF to Markdown in Python using REST API
try:
# Create an instance of the API
convert_api = groupdocs_conversion_cloud.ConvertApi.from_keys(client_id, client_secret)
# Define convert settings
settings = groupdocs_conversion_cloud.ConvertSettings()
settings.storage_name = storage_name
settings.file_path = "python-testing/input-sample-file.pdf"
settings.format = "md"
settings.output_path = "python-testing/output-sample-file.md"
request = groupdocs_conversion_cloud.ConvertDocumentRequest(settings)
response = convert_api.convert_document(request)
print("Successfully converted convert PDF to Markdown online in Python: " + str(response))
except groupdocs_conversion_cloud.ApiException as e:
print("Exception while calling API: {0}".format(e.message))
# Import Python SDK in your python application from http://api.groupdocs.cloud
import groupdocs_conversion_cloud
# Get client_id and client_secret from https://dashboard.groupdocs.cloud after free registration.
client_id = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
client_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# Get File API configurations
configuration = groupdocs_conversion_cloud.Configuration(client_id, client_secret)
configuration.api_base_url = "https://api.groupdocs.cloud"
storage_name = "InternalStorage"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment