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
SNEHA SALUNKHESNEHA SALUNKHE 

rendering of vf page as pdf is showing an error message failed to load the pdf

screenshot of the error message that i am getting
hi i am getting the attached error while rendering the page.
I checked in the debug logs i can see the content in the blob string but it is not getting rendered also the pdf is getting attached with the document object to and the mime type is also shown as application/pdf still i am facing the above error.
Please help

Thanks
Himanshu ParasharHimanshu Parashar
Hi Sneha,

To find the exact issue. try to enable debug mode first and then remove renderas="PDF" attribute from page. You should see actual issue then.

Let me know if that works.

Thanks,
Himanshu
Sai Ram ASai Ram A
Hi SNEHA

Share the Code. so we can help with your Issue

Thank you
BLearn - Sai
SNEHA SALUNKHESNEHA SALUNKHE
Approval Page:
<apex:commandButton value="Udskriv kvittering" rendered="{!receiptPage}" onclick="return redirectPrint();"/>

this is the button on click of which the receipt page gets downloaded 

function redirectPrint()
        { 
           var docURL = '/servlet/servlet.FileDownload?file={!AttachmentID}';
               
            var receipt = window.open(docURL,'_Self','menubar=yes,width=680,height=692,toolbar=yes,scrollbars=yes');
            receipt.focus();
            return false;
        }

Controller Class:
Boolean receiptSaved = false;
    public Id AttachmentID {get;set;} 
     
     public void saveReceipt()
    {      
                //Pagereference pr = Page.DealerProductReceipt;
                Pagereference pr = Page.DemoPdfPage;
             //   pr.getParameters().put('id',parentId);
      //  Attachment attach = new Attachment();
                Blob b;
                if(!(testMode)){
                    //b = pr.getcontent(); 
                    b = pr.getContentAsPDF();
                   
                    system.debug('Blob Data in string format @@@@@@@@@@@@ '+b.tostring());
                    system.debug('string in the blob !!!!!!!  '+b);
                } 
                else{
                     b = Blob.valueof('Dummy Content in email body for Apex Test Run');            
                   
                }   
               
                Document receipt = new Document();
                receipt.folderId = [select id from folder where Name='Customer Form Documents'].id;
                receipt.Name = cCustInstAdd.customerNumber + '.pdf'; 
                receipt.body = b;
        		receipt.ContentType = 'application/pdf';
        		receipt.IsPublic = true;
                
                System.debug('receipt->'+receipt.body);
        
                insert receipt; 
              system.debug('receipt id--------'+receipt.id);
        
                AttachmentID = receipt.id;
         system.debug('receipt id--------'+AttachmentID);
                receiptSaved = true;
    }
    
    public pagereference printReceipt()
    {
        if(!receiptSaved)
       		saveReceipt();
        
        return Page.DealerProductReceipt;
    }

receipt page:
<apex:page Controller="DealerProductPageController3" sidebar="false" showHeader="false" applyBodyTag="false">
<head> 
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
</head>

.........
.................
......................
................
</apex:page>
the receipt page is the page that needed to be converted into pdf but renderAs gives ab encoding error after the button is clicked on the approval page.'

thanks in advance