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
yogesh goadyogesh goad 

Display only first 2 pages of pdf file in browser

i have uploaded a pdf file using document object in salesforce. i am using the below code to display that file in a pop up window in my browser. my requirement is to show only the first two pages of that file and not the whole document in the browser.

<apex:repeat var="dc" value="{!details}">
  <tr>
  <td><a target="_blank" href="https://c.ap1.content.force.com/servlet/servlet.FileDownload?file={!dc.id}" onclick="return windowpop(this.href, 545, 433)"> {!dc.Name} </a></td>
    <td>{!dc.Type}</td>
  </tr> </apex:repeat>
Pavan DavePavan Dave
Not sure if we can display minimized PDF with the same PDF.
Instead of these can we have a map instead of list "details".

Map detailedMap = new Map<id, MinimizedPDF>();

MinimizedPDF(){
    PageReference pr;
    Blob pdf;
  
    pr = New PageReference('https://c.ap1.content.force.com/servlet/servlet.FileDownload?file={!id} );
        
    pdf = pr.getContentAsPDF();    /* TRY TO FETCH JUST 2 PAGES INSTEAD OF COMPLETE PDF*/
       
    Attachment a = New Attachment();
    a.body = pdf;            
    a.parentID = f.id;
    a.Name = 'FSA.pdf';
    insert a;
}
yogesh goadyogesh goad
Hi  Pava Dave

your solution is not clear to me.
i think you dint get my question properly.let me state the question clearly.
i am using the below code to upload a document in salesforce
public class documentExt {
    public documentExt(ApexPages.StandardController controller) {
        Document d = (Document) controller.getRecord();
        d.folderid = UserInfo.getUserId(); //this puts it in My Personal Documents
    }                 
}
and iam using this controller to fetch a list of all uploded documents
public class ViewFile {

    public List<Document> getDetails() {
        return [select id,type,name from Document];
    }

}
i am using the following vf page to display the list
<apex:page controller="ViewFile" sidebar="false" showHeader="false">

<html>
<head>
<script>
function windowpop(url, width, height) {
var leftPosition, topPosition;
leftPosition = (window.screen.width / 2) - ((width / 2) + 10);
topPosition = (window.screen.height / 2) - ((height / 2) + 50);
window.open(url, "Window2", "status=no,height=" + height + ",width=" + width + ",resizable=yes,left=" + leftPosition + ",top=" + topPosition + ",screenX=" + leftPosition + ",screenY=" + topPosition + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no");
}
</script>

</head>
<body>

<table border="1">
       <thead>
           
               <th>Title</th>
               <th>FileType</th>
               
       </thead>
       <tbody>
           <apex:repeat var="dc" value="{!details}">
           <tr>
                <td><a target="_blank" href="https://c.ap1.content.force.com/servlet/servlet.FileDownload?file={!dc.id}" onclick="return windowpop(this.href, 545, 433)"> {!dc.Name} </a></td>
                <td>{!dc.Type}</td>
               
               
           </tr>
       </apex:repeat>
       </tbody>
</table>
  
</body>
</html>

</apex:page>
now i get the following displayUser-added image

when i click on the link under the title header of table it shows me the entire document in a pop up window as belowUser-added image

what i want is to only show the first two pages to the user who clicks on the link under title header in the table.

hope the question is clear now.