How to Merge PDF Files in Business Central Using a Python API
When working with documents in Microsoft Dynamics 365 Business Central, sometimes we need to combine multiple PDF files into a single document — for example, when generating a bundle of invoices or reports. In this post, I’ll show you how to achieve that by integrating Business Central AL code with a Python-based API using FastAPI and PyPDF2. 🐍 The Python API (FastAPI + PyPDF2) We’ll expose a /merge-pdf endpoint using FastAPI that: Accepts a list of PDFs encoded in Base64 Merges them using PyPDF2.PdfMerger Returns the combined PDF as a Base64 string Here’s the Python code: python from fastapi import FastAPI, Header, HTTPException from pydantic import BaseModel import base64 from PyPDF2 import PdfMerger from io import BytesIO app = FastAPI() class PDFRequest ( BaseModel ): archivos_pdf: list [ str ] # List of Base64 PDF files class PDFResponse ( BaseModel ): pdf_unido: str # Base64-encoded merged PDF API_KEY = "YourApiKey" ...