Skip to content

Instantly share code, notes, and snippets.

@aspose-cloud
Last active November 25, 2021 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-cloud/2ce55f005cf6cd83bad59be16b98676d to your computer and use it in GitHub Desktop.
Save aspose-cloud/2ce55f005cf6cd83bad59be16b98676d to your computer and use it in GitHub Desktop.
This Gist contains code snippets regarding the conversion of HTML files to PDF format using Aspose.PDF Cloud SDK for Python
This Gist contains code snippets regarding the conversion of HTML files to PDF format using Aspose.PDF Cloud SDK for Python
def html2pdf():
try:
#initialize PdfApi client instance using ClientID and ClientSecret
pdf_api_client = asposepdfcloud.api_client.ApiClient("406b404b2df649611e508bbcfcd2a77f", "88d1cda8-b12c-4a80-b1ad-c85ac483c5c5")
# create PdfApi instance while passing PdfApiClient as argument
pdf_api = PdfApi(pdf_api_client)
# Input HTML file
input_file_name = 'source.zip'
# name of resultant PDF file
resultant_file_name = 'Converted.pdf'
# Call API to convert HTML to PDF format
# the source HTML is in .zip format along with .css and related images
response = pdf_api.put_html_in_storage_to_pdf(src_path='source.zip', html_file_name='completeWorkbook.html', name=resultant_file_name, height='1024', width='800', is_landscape='false')
# print message in console (optional)
print('HTML successfully converted to PDF format !')
except ApiException as e:
print("Exception while calling PdfApi: {0}".format(e))
def web2pdf():
try:
#initialize PdfApi client instance using ClientID and ClientSecret
pdf_api_client = asposepdfcloud.api_client.ApiClient("406b404b2df649611e508bbcfcd2a77f", "88d1cda8-b12c-4a80-b1ad-c85ac483c5c5")
# create PdfApi instance while passing PdfApiClient as argument
pdf_api = PdfApi(pdf_api_client)
# Resultant PDF file
resultant_file_name = 'Web2PDF.pdf'
# Call API to convert webpage/URL to PDF
# we have set isLandscape true for better accommodation of webpage contents
response = pdf_api.put_web_in_storage_to_pdf(name=resultant_file_name, url='https://www.aspose.cloud/', is_landscape='true')
# print message in console (optional)
print('Webpage successfully converted to PDF format !')
except ApiException as e:
print("Exception while calling PdfApi: {0}".format(e))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment