Apex: From Word Document get content and save as PDF

apexms-wordpdfvisualforce

According to Salesforce limits, generating PDF using special characters is impossible to show bold characters. I still have the issue described here, where from a rich text i want to show the field's value using the formatting (bold, etc). Since this is impossible using PDF, i was thinking of workarounds.

  • As i saw, printing the rich text area field as a word document (using Visualforce) seems to show properly the greek characters in bold.
  • Now, my next step is to somehow get the content of this word document and save it as PDF File.

Is this considered as a correct approach? Does anyone have any ideas on how i could handle my issue?
What i tried to do was to get the content of the word document using the "getContent" or "getContentAsPDF" functions and then save a file as PDF. But opening the PDF fails, meaning that it is invalid.

Best Answer

There's no way to escape the limitations of the system PDF renderer while you are operating on-platform. There's only one PDF renderer, whether you use render_as="pdf" or getContentAsPDF(), so you're always going to hit the same limitation.

Your best options are likely:

  1. Render some format other than PDF via your Visualforce page, and rely on the user to convert it to PDF. (Note: changing the MIME type does not convert the file to Word; most Visualforce pages that claim to generate Word docs are in fact generating HTML).
  2. Use a JavaScript-based PDF library on the front end to create your document.
  3. Purchase a commercial document generation solution that correctly supports Unicode characters in rendered PDFs.
  4. Use Salesforce Functions to render the document using JavaScript libraries off-platform.
Related Topic