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
Francisco Riccomagno 1Francisco Riccomagno 1 

How to align an image in a VF page render as PDF?

I'm trying to generate a PDF dinamically from the information we have. I managed to work this by using a VisualForce page with renderAs="pdf". The problem that we are having now is that we want an image to be center in the header, and for some reason I'm unable to make it work with standard css. Here is the part of the code i'm unsing in the page:
<apex:pageBlock >
        <apex:pageBlockSection collapsible="false">                     
            <apex:repeat value="{!pictures}" var="picture">
               <div style="width:100%;">    
                    <img src="{!URLFOR($Action.Attachment.Download, picture)}" style="display:block; margin:0 auto"/>        
               </div>                 
            </apex:repeat>              
        </apex:pageBlockSection>
  </apex:pageBlock>
If I use this desing in a plain HTML page, it works perfectly, but it seems that the apex code is messing up with my stilling. 
Is there a way to make my image to be centered?
Thank you.
Best Answer chosen by Francisco Riccomagno 1
Francisco Riccomagno 1Francisco Riccomagno 1
I found that the problem was with the <apex:pageBlock> so i removed all that and keep it more in HTML standar format:
<apex:repeat value="{!pictures}" var="picture">
       <div style="width:100%;"> 
           <p align="center">  
                <img src="{!URLFOR($Action.Attachment.Download, picture)}"/> 
           </p>      
       </div>                 
    </apex:repeat>
By doing this, my image now got centered when showing as PDF.