2

I have a VF page on which I save that VF page content as a PDF, Now there is a new requirement in which I have to save a Word DOC file as well with that PDF so that I can perform some changes on it.

So now what I want to ask is How to convert a pdf file to DOC or Create a new DOC file from the blob of that PDF?

FYI ,I am using renderAs="pdf" on vf page.
ContentVersion:

String encodedBlob = EncodingUtil.base64Encode(body);
ContentVersion conVer = new ContentVersion();
conVer.ContentLocation = 'S';
conVer.PathOnClient = quote.Name+'.docx';
conVer.Title = 'Proposal '+ quote.Name;
conVer.VersionData = EncodingUtil.base64Decode(encodedBlob);
insert conVer;

1 Answer 1

3

Instead of trying to convert existing pdf version of the page, I suggest clone the current visualforce page and instead of render as pdf use contentType="application/msword#filename.doc

Now you can read this content as blob in apex

6
  • Thank u for the quick response @mohith, I tried the solution suggested but the VF page is saving as PDF as previously. Maybe something is wrong with contentVersion that I am inserting. Here I am using it as : In updated question Jan 3, 2022 at 10:30
  • 1
    PageReference pdfPage = Page.CRcontract; Blob pdfBlob = pdfPage.getContent(); I would try getting the getContent via pagereference Jan 3, 2022 at 10:48
  • And make sure page names is correct Jan 3, 2022 at 10:48
  • Thank for the help, one last issue I am facing is that I am not able to get the images in the doc file which I am accessing from static resources. Jan 3, 2022 at 11:12
  • I think it’s a different question! And it will need you to share code. Jan 3, 2022 at 11:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .