function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ram123ram123 

PDF content as String ?

I want to get pdf file content as string in apex, currently i don't see any option? how do I get raw pdf back with all formats like '%PDF', "%%EOF", "trailer"

 

All the pdf data i'm getting from content, document, visulaforce render as pdf are mostly blob or base64 format, but when i try to convert them into string using encoding util class, i can't able to get the raw pdf file as i epxect,

 

any help?

 

Thanks

Ram

vriavmvriavm

I am guessing you are tryng to save the PDF as DOcument or Quotedocument, attachment or some other custom object. All you have to do is use getcontent or get contectasPDF methoods in Salesforce and store it as a blob.

 

vriavmvriavm

        pr = New PageReference('/apex/ReportPDF?id=' + id ); 

 

        pdf = pr.getContentAsPDF();

        

        Attachment a = New Attachment();

        a.body = pdf;

        a.parentID = <parent object id>;

        a.Name = 'FSA.pdf';

        insert a;

 

Hopefully this example helps...

ram123ram123

I want the other way around, I'm retriveing a contentversion or getting page conent as pdf, but all i'm getting is blob  object, there is no way for me to get back the raw pdf as string

 

Thanks

Ram

 

vriavmvriavm

If your intent is saving the PDF content then you use the logic I provided may I know why u want the content as String.

If you convert using String.ValueOf(<BLod>); but this will make the content miserable...

 

ram123ram123

if you want to send a pdf content to outside webservices you might face this issue,, its requirements not a question of whats possible,

 

 

let see what the other ideas around the community ? 

 

Thanks

Ram

cooldamselcooldamsel
Hi Ram123,

Were you able to get a solution for this? I am also facing the same situation. Please provide ur solution.

Thanks in advance.