PDF is a binary format and Apex (presumably by design) is missing the language capabilities to manipulate bits and bytes. So it is not possible to edit the internals of a PDF file in Apex.
The purpose of the
renderAs="PDF" is to run code that generates a PDF file from the HTML tags and CSS in a Visualforce page. It has nothing to do with rendering a pre-existing PDF file.
So yes, if you an find an existing library that does what you need, you could host it on e.g. Heroku. You would be extremely lucky to find such a setup that already exists; you are more likely to need to create that service yourself.
Update on Rich text images
Here is the problem unless stored as a document with externally available flag, I do not think you can permit the image to be displayed on a word document.
Read this doc on why static resource images cannot be accessed in a template:
The only crazy solution I can think of is
1) Ask the user to upload the image for the rich text field as attachment on the parent object.
2) create a long text field on the parent object ( kill the rich text field) where the user can add his / her comments related to the image.
2) Create a trigger on attachment object which saves the image into a document
3) Once the image is saved as Doc take the doc id that got created and update it on the parent object using a field that is not editable and do not add to the page layout. ( If you have to add multiple images to your template, you may have to do more nasty coding )
4) On your vf page do
Here is a solution that I developed using the advice from these blogs
Instead of loading the image into a static resource I loaded it into the document and make sure Externally Available Image is checked.
My page tag:
<apex:page standardController="opportunity" contentType="application/msword#mydoc.doc" applyHtmlTag="false" showHeader="false" cache="true" readOnly="true" >
I used the following syntax for rendering the image
<img src="https://c.**yourinstance**.content.force.com/servlet/servlet.ImageServer?id=docId&oid=OrgID" />
You can get the above URL by
My word file output :
Here is a similar solution posted in dev forum. Hope this helps. I have copied the solution here.
Use this method as below.