{"library":"pdfservices-sdk","title":"Adobe PDF Services SDK for Python","description":"Adobe PDF Services SDK for Python provides client libraries to interact with Adobe Document Cloud PDF Services APIs. It enables developers to programmatically perform operations like PDF creation, export, compression, OCR, document generation, and more. The current version is 4.2.0. Releases are typically infrequent, corresponding to updates in the underlying Adobe API services.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install pdfservices-sdk"],"cli":null},"imports":["from pdfservices_sdk.pdf_services_client import PdfServiceClient","from pdfservices_sdk.pdf_services_config import PdfServicesConfig","from pdfservices_sdk.auth.credentials import AdobeAuthCredentials","from pdfservices_sdk.io.file_ref import FileRef","from pdfservices_sdk.jobs.createpdf.create_pdf_from_html_job import CreatePdfFromHtmlJob"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nfrom pdfservices_sdk.pdf_services_client import PdfServiceClient\nfrom pdfservices_sdk.pdf_services_config import PdfServicesConfig\nfrom pdfservices_sdk.auth.credentials import AdobeAuthCredentials\nfrom pdfservices_sdk.io.file_ref import FileRef\nfrom pdfservices_sdk.jobs.createpdf.create_pdf_from_html_job import CreatePdfFromHtmlJob\n\n# Ensure you have your credentials.json file path set as an environment variable\n# Or provide the path directly: credentials_path = \"./pdfservices-api-credentials.json\"\ncredentials_path = os.environ.get(\"PDF_SERVICES_SDK_CLIENT_CREDENTIALS_PATH\", \"./pdfservices-api-credentials.json\")\n\n# Create a dummy HTML file for conversion\ndummy_html_content = \"<h1>Hello from Adobe PDF Services!</h1><p>This is a test.</p>\"\nwith open(\"input.html\", \"w\") as f:\n    f.write(dummy_html_content)\n\ntry:\n    # 1. Build AdobeAuthCredentials using a file-based builder.\n    #    Ensure credentials.json has 'client_id', 'client_secret', and 'organization_id'.\n    credentials = AdobeAuthCredentials.file_based_credentials_builder()\\\n        .with_credentials_path(credentials_path).build()\n\n    # 2. Build PdfServicesConfig with the created credentials.\n    pdf_services_config = PdfServicesConfig.builder().with_credentials(credentials).build()\n\n    # 3. Create a PdfServiceClient.\n    pdf_service_client = PdfServiceClient.builder().with_pdf_services_config(pdf_services_config).build()\n\n    # 4. Create an input FileRef from the HTML file.\n    input_file_ref = FileRef.from_local_file(\"input.html\")\n\n    # 5. Create a CreatePdfFromHtmlJob instance.\n    create_pdf_from_html_job = CreatePdfFromHtmlJob(input_file_ref)\n\n    # 6. Execute the job and get the output FileRef.\n    result_file_ref = pdf_service_client.execute(create_pdf_from_html_job)\n\n    # 7. Save the result to a local file.\n    output_path = \"output.pdf\"\n    result_file_ref.save_as_file(output_path)\n    print(f\"Successfully created PDF: {output_path}\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\nfinally:\n    # Clean up dummy files\n    if os.path.exists(\"input.html\"):\n        os.remove(\"input.html\")\n    # if os.path.exists(\"output.pdf\"):\n    #     os.remove(\"output.pdf\") # Uncomment to remove generated PDF after successful run\n","lang":"python","description":"This quickstart demonstrates how to initialize the PDF Services client, authenticate using file-based credentials, and convert a simple HTML string to a PDF document. It highlights the use of `AdobeAuthCredentials` and `PdfServicesConfig` for setup, and `FileRef` for handling input/output files.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}