Skip to main content
Laetitia CIVEL (Splayce) 님이 #Salesforce Developer에 질문했습니다
Hello everyone,

We try to make pdf file with dynamic images for our products but we see an image with broken link.

Somebody has an idea ?

Our html code:

<apex:page standardcontroller="Product2" extensions="ProductPDFController" showHeader="false" sidebar="false" renderAs="pdf" applyHtmlTag="false"> <html> <apex:outputPanel rendered="{!(Product2.Marque_MKTG__c == 'YORO')}"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <title>{!Product2.Name}</title> <meta name="generator" content="BCL easyConverter SDK 5.0.252"/> <meta name="title" content="Fiche technique Produit salforce"/> <apex:stylesheet value="{!$Resource.ProductPDFYOROcss}"/>

....

<apex:image value="{!Product2.Image_Display__c}" style="padding: 5px;max-width:100%;height:300px;width:auto;"/>

...

-----------------------------------------------------

Controller code :

public class ProductPDFController{

    public Product2 product;

    public String contentversionId{get;set;}

    public String productId;

    

    public ProductPDFController(ApexPages.StandardController controller){

        product = (Product2)controller.getRecord();

        productId = product.Id;

        System.debug('⌗⌗productId '+productId);

        fetchImageLink(productId);

    }

    

    public void fetchImageLink(String product2Id){

        List<ContentDocument> contentDocumentList =  fetchContentDocumentDetails(product2Id);

        System.debug('$$contentDocumentList '+contentDocumentList);

        if(contentDocumentList != null){

            

            if(contentDocumentList.size() > 0){

                List<ContentVersion> contentVersionList=  [SELECT Id FROM

                         ContentVersion

                         WHERE contentDocumentId IN :contentDocumentList

                         ORDER BY CreatedDate desc];

               System.debug('$$contentVersionList '+contentVersionList);          

                if(contentVersionList.size()>0)

                    contentversionId = contentVersionList[0].Id;

            }

        }

        System.debug('$$contentversionId '+contentversionId);

    }

    

    public static List<ContentDocument> fetchContentDocumentDetails(Id product2Id){

        if(product2Id!=null){

            List<ContentDocument> ContentDocumentsIdList = new List<ContentDocument>();

            for(ContentDocumentlink contentLinkDocumentRecord:[SELECT ContentDocumentId,ContentDocument.Id,ContentDocument.Title,ContentDocument.CreatedDate

            FROM ContentDocumentlink

            WHERE LinkedEntityId =:product2Id

            ORDER BY ContentDocument.CreatedDate desc])

            {

                if(contentLinkDocumentRecord.ContentDocumentId != null){

                    if(contentLinkDocumentRecord.ContentDocument.Title.containsIgnoreCase('.jpg') || contentLinkDocumentRecord.ContentDocument.Title.containsIgnoreCase('.png')) {

                        system.debug('Adding Doc: '+contentLinkDocumentRecord.ContentDocument.Id);

                        system.debug('Adding Title: '+contentLinkDocumentRecord.ContentDocument.Title);

                        ContentDocumentsIdList.add(new ContentDocument(Id = contentLinkDocumentRecord.ContentDocument.Id,Title = contentLinkDocumentRecord.ContentDocument.Title));

                    }

                }

            }

            if(ContentDocumentsIdList.size()>0 && ContentDocumentsIdList!=null){

                return ContentDocumentsIdList;

            }

        }

        return null;

    }

Thanks,
답변 1개
0/9000