How to generate PDF files in Power Apps / Power Platform: step by step
Generating PDF files directly from a Canvas App in Power Apps is useful for creating receipts, reports, or invoices that can be shared or archived. This tutorial shows how to create a simple PDF using HTML, the Power Automate connector and save the file in OneDrive or SharePoint.
Prerequisites
- Account with access to Power Apps and Power Automate.
- Permissions to create flows and write to OneDrive or SharePoint.
- Basic knowledge of Canvas Apps and formula expressions in Power Apps.
Step 1: Concept — why use HTML + Power Automate
Power Apps does not have native PDF conversion; therefore we create an HTML document in the app, send it to Power Automate which uses the conversion action (e.g., "OneDrive for Business - Convert file" or a third-party connector) to generate the PDF and then saves the file to the desired location. This approach is simple, flexible and allows customizing the PDF layout with HTML/CSS.
Step 2: Create the Canvas App and the sample screen
Create a Canvas App (Tablet or Phone) and add controls to capture the data you want in the PDF. Minimal example: TextInput for Name, TextInput for Note and a Button to generate the PDF.
// Controlo: TextInputNome (Default: "")
// Controlo: TextInputNota (Default: "")
// Botão: btnGerarPDF (OnSelect será configurado mais abaixo)
Step 3: Build the HTML inside the App
Create a variable that contains the HTML of the document. Use a simple string with inline styles to avoid external dependencies. Store the HTML in a context or global variable before calling Power Automate.
// No OnSelect do botão, antes de chamar o Flow:
Set(varHTML,
"" &
"Relatório
" &
"Nome: " & TextInputNome.Text & "
" &
"Nota: " & TextInputNota.Text & "
" &
""
)
Step 4: Create the Power Automate Flow that converts HTML to PDF
Create an automated flow that is triggered from the Canvas App (trigger "PowerApps"). The Flow receives the HTML as input, creates a temporary HTML file in OneDrive/SharePoint and uses the conversion action to generate the PDF. Then it returns the link or saves the final file.
// Estrutura do Flow (resumo):
1. Gatilho: PowerApps
2. Ação: Create file (OneDrive for Business) — Path: /temp/relatorio.html, Content: receber parâmetro HTML
3. Ação: Convert file (OneDrive for Business) — Id: id do ficheiro HTML, Target type: PDF
4. Ação: Create file (OneDrive for Business / SharePoint) — Guardar o ficheiro PDF em /Relatorios/relatorio_{utcNow()}.pdf
5. Responder a PowerApps com a URL do ficheiro (opcional)
// No Power Automate use a expressão utcNow() para timestamp quando necessário.
Step 5: Connect the App to the Flow and invoke the conversion
In Power Apps, add the Flow created via "Data > Power Automate". Then invoke it in the OnSelect of the button, passing the varHTML variable. Handle the response to get the PDF URL or confirm success.
// Exemplo no OnSelect do btnGerarPDF:
// Assume Flow chama-se ConvertHTMLToPDF
ConvertHTMLToPDF.Run(varHTML).Run() // Se o Flow devolver valor usar variáveis para capturar
// Exemplo com captura da resposta (se o Flow usar 'Respond to PowerApps'):
Set(varResposta, ConvertHTMLToPDF.Run(varHTML));
If(!IsBlank(varResposta.pdfUrl),
Launch(varResposta.pdfUrl),
Notify("PDF gerado mas não foi possível obter a URL", NotificationType.Warning)
)
Step 6: Common errors and how to resolve them
Typical errors: 1) Insufficient permissions to create files in OneDrive/SharePoint — check permissions; 2) Malformed HTML — validate with an editor; 3) The conversion action is not available on your license — check the connector/plan or use an external service (conversion API) with a Custom Connector. If the Flow fails, check the run history for details.
Verify the result
Open the folder in OneDrive/SharePoint where you saved the PDF and confirm the name, date and content. Open the PDF file to check formatting, text and special characters. In the App, test with various inputs (long, accented characters) to ensure UTF-8 encoding is preserved.
Conclusion
You now know how to generate PDF files in Power Apps / Power Platform using HTML and Power Automate, save to OneDrive/SharePoint and present or share the result. Next steps: add images to the HTML, create more sophisticated templates or use a Custom Connector for PDF services. Tip: before converting, always validate the HTML and test the Flow in isolation to simplify troubleshooting.