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
BuildBuild 

Broken Image show in PDF when I sent out this PDF by email

Hi Everyone,
Since I am new to Salesforce.

I have request from my customer regarding sending out an email with PDF.

My problem is that in the PDF I need to show image in there too but the problem is that the image shown in the PDF is

broken. Image is save in the document and Externally Available is true. 

I have tried several scenario since I cannot use the actual URL of the image directly.

1) I have tried putting image URL in Rich Text Field (in img tag) . In salesforce image is showing correctly but when I send out an

email this image is showing as broken.

2) I have try putting image URL in URL field and then using that field in the PDF but image is still broken,

 

Can anyone guide me on how should I do it ?

 

Thank a lot.

BHinnersBHinners
Please post the relevant lines of code for generating the image in the PDF file so that we can help with suggestions...
BuildBuild

Hi BHinners ,
This is my lines of code : https://c.cs6.content.force.com/servlet/servlet.ImageServer?id='+DocumentID+'&oid='+OrganisationID

If I used the direct URL of am image it works but if I use in this way the image is showing as broken image

BuildBuild

When I hardcode URL it works :

https://c.cs6.content.force.com/servlet/servlet.ImageServer?id=015N0000000CkAI&oid=00DN0000000AB3c

When I use id from Apex controller the image is broken :

https://c.cs6.content.force.com/servlet/servlet.ImageServer?id='{!DocumentID}+'&oid='+{!OrganisationID}
 

BHinnersBHinners
The method you are using is not a best practice. It would be better to use a static resource. Or, since you appear to be using a bar code, compute the barcode each time you generate the PDF. Can you post the controller code that goes with the URL and populates the document ID?
BuildBuild

I cannot use the static resource as the image is send in the base64 form.
Right now I am creating barcode each time the base64 image is being send from another system.

This is the code that I used to create document.

Blob Pic;
Pic = EncodingUtil.base64Decode(Base64code);
                           
Document UploadDoc = new Document();
UploadDoc.Body = Pic;
UploadDoc.Name = 'Barcode : '+BillPayment.Billing_Barcode_CS_ID__c;
UploadDoc.ContentType = 'image/jpeg';
UploadDoc.IsPublic = true;
UploadDoc.FolderId = '00lN0000000MuAL';
UploadDoc.Type = 'jpeg';
insert(UploadDoc);


In another way, if the image is save in Rich text field can I access that image ?