One of the long requested and anticipated missing components in Dynamics 365 CE is the creation of PDF documents.
As of version 9.0.1905.2010 you will have the native capability to create a PDF document for quote.

Yes, finally great feature, let’s enable it! Navigate to the sales hub “app settings” and select “PDF generation” in the left hand menu.

Enable generate PDF feature

After enabling the “Create Pdf” and “Email as PDF” menu will appear on quote’s.

A quote form showing the Create PDF button on the command bar

Microsoft Docs: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/sales-enterprise/create-quote-pdf

But as you might have already noticed, the devil is in the details, it’s only available on quotes (or at least for the moment). I expect that they will open up this feature to other document template enabled entities.

For the people who can’t wait, it’s possible to already use the export to PDF functionality for other entities, but it will require to write some code.

First let’s having a closer look at what happens when selecting a template to generate a PDF document. Dynamics is calling the following endpoint:

https://{org}.{region}.dynamics.com/api/data/v9.0/ExportPdfDocument

And the following data is submitted:

{
       "EntityTypeCode": 1084,
       "SelectedTemplate": {
              "@odata.type": "Microsoft.Dynamics.CRM.documenttemplate",
              "documenttemplateid": "153dc496-d79d-e711-8109-e0071b65ce81"
       },
       "SelectedRecords": "[\"{E3A79DA1-9B91-E811-8133-E0071B65CE81}\"]"
}

The response will contain a “PdfFile” attribute which is a base64 representation of the PDF file.

{
     "@odata.context": "https://{org}.{region}.dynamics.com/api/data/v9.0/$metadata#Microsoft.Dynamics.CRM.ExportPdfDocumentResponse",
       "PdfFile": "JVBERi0xLjUNCjQgMCBvYmoNCjw8L1R5cGUgL1BhZ2UvUGFyZW50IDMgMCBSL0..."
}
Now let’s try to do this from a C# console app for an invoice record.

Then the captured information from the above call would translate in something like:

//Endpoint based on https://{org}.{region}.dynamics.com/api/data/v9.0/ExportPdfDocument
OrganizationRequest request = new OrganizationRequest("ExportPdfDocument");

request["EntityTypeCode"] = 1090; //invoice
request["SelectedTemplate"] = new EntityReference("documenttemplate", new Guid("cbbcd2d8-e48e-e711-8136-e0071b65cea1")); // invoice document template

//serialize JSON array of the records
List<Guid> records = new List<Guid> { new Guid("2609328d-296c-e911-a989-000d3ab982f2") };
request["SelectedRecords"] = JsonConvert.SerializeObject(records);

OrganizationResponse pdfResponse= (OrganizationResponse)_client.Execute(request);

//Write to file
string b64File = Convert.ToBase64String((byte[])pdfResponse["PdfFile"]);
File.WriteAllBytes("invoicedocument.pdf", pdfResponse["PdfFile"] as byte[]);

Imaging adding this code to a workflow assembly with the appropriate input and output parameters, and the possiblities this would give….