如何配置MS Flow的Post请求调用Docker部署的PdfReactor REST API转HTML为PDF
Got it, let's walk through how to set up that HTTP POST request for PDFreactor in Docker with Microsoft Flow—this should get your HTML-to-PDF conversion working smoothly.
First, make sure you have the correct endpoint for your running PDFreactor container. By default, the REST API endpoint is:http://<your-docker-host-ip>:9423/service/rest
To verify the service is reachable, you can test it with a simple curl command or Postman:
curl http://localhost:9423/service/rest
You should get a JSON response confirming the API is active. If not, double-check your Docker port mapping (you need -p 9423:9423 in your docker run command to expose the port).
Now let's build the request in Flow:
- Add an HTTP action to your Flow, set the method to
POST - Paste your PDFreactor endpoint into the URI field
- Under Headers, add a key-value pair:
- Key:
Content-Type - Value:
application/json
- Key:
- For the Body, use a JSON payload tailored to your HTML source. Here are two common scenarios:
Scenario 1: Directly embed HTML content
If you have the HTML inline or stored as a variable in Flow, use this payload:
{ "content": "<!DOCTYPE html><html><body><h1>My Converted PDF</h1><p>This is a test from Microsoft Flow + PDFreactor</p></body></html>", "outputFormat": "PDF", "pageSize": "A4", "margin": {"top": "2cm", "bottom": "2cm", "left": "1.5cm", "right": "1.5cm"} }
Scenario 2: Pull HTML from a file (e.g., SharePoint)
If your HTML is stored in a file, first add a Get file content action to retrieve the HTML text, then reference it in the payload:
{ "content": "@{body('Get_file_content')}", "outputFormat": "PDF" }
PDFreactor returns the PDF as binary data in the response body. To save it:
- Add a Create file action (e.g., for SharePoint, OneDrive, or Azure Blob Storage)
- Set the File content to the
Bodyoutput from your HTTP action - Define a filename (e.g.,
converted-document.pdf)
- CORS Issues: If Flow throws a cross-origin error, update your PDFreactor Docker config to allow Flow's domain. You can add a
CORS_ALLOWED_ORIGINSenvironment variable when starting the container. - External Resources: If your HTML references images/CSS from external URLs, ensure the Docker container has network access to those resources.
- API Limits: Check PDFreactor's documentation for rate limits or payload size restrictions if you're converting large HTML files.
内容的提问来源于stack exchange,提问作者JaDDeL

