Ah good catch.  PdfDocument is a subclass of Document... which is used to build 
new files.  I'd image it's still the default size, whereas the 
reader.getPageSize() will actually look at the page in question.
 
PS: getPageSize is looking at the page's Media Box.  It ignores all the other 
boxes a page might have (crop box being the most common), as well as the page's 
rotation.
 
--Mark Storer
  Senior Software Engineer
  Cardiff.com
 
import legalese.Disclaimer;
Disclaimer<Cardiff> DisCard = null;
 
 


________________________________

        From: Paulo Soares [mailto:[email protected]] 
        Sent: Wednesday, August 04, 2010 1:32 AM
        To: Post all your questions about iText here
        Subject: Re: [iText-questions] PdfStamper vs PdfReader page size
        
        
        page.getPdfDocument() doesn't make sense in this context where you 
don't really have a PdfDocument to write to.
         
        Paulo


________________________________

                From: Karol Bryd [mailto:[email protected]] 
                Sent: Tuesday, August 03, 2010 9:49 PM
                To: [email protected]
                Subject: [iText-questions] PdfStamper vs PdfReader page size
                
                
                Hello
                
                Perhaps this is a silly question but I am still going to ask it 
:-)
                
                I have a following code fragment:
                
                 public static void main( String[] args ) throws Exception {
                        PdfReader reader = new PdfReader("/tmp/input.pdf");
                
                        File tmpFile = File.createTempFile("tmp_stamper", 
".pdf");
                        System.out.println("Reader page size " + 
reader.getPageSize(1).getWidth() + "x" + reader.getPageSize(1).getHeight());
                        PdfStamper stamper = new PdfStamper(reader, new 
FileOutputStream(tmpFile));
                        System.out.println("Stamper Size " + 
stamper.getWriter().getPageSize().getWidth() + "x" + 
stamper.getWriter().getPageSize().getHeight());
                
                        Image img = 
Image.getInstance("http://kombajn.ath.cx/test.jpg";);
                        img.setAbsolutePosition(0, 0);
                
                        for(int n = 1; n < reader.getNumberOfPages(); n++) {
                            PdfContentByte page = stamper.getUnderContent(n);
                //            
img.scaleAbsolute(stamper.getReader().getPageSize(n).getWidth(), 
stamper.getReader().getPageSize(n).getHeight());   // THIS WORKS FINE
                            
img.scaleAbsolute(page.getPdfDocument().getPageSize().getWidth(), 
page.getPdfDocument().getPageSize().getHeight()); // THIS DOESN'T
                            page.addImage(img);
                        }
                        stamper.close();
                        reader.close();
                    }
                
                
                The input focument /tmp/input.pdf is a simple PDF document with 
pages which have 612x792 pixels (US Letter Portrait). 
                
                Question is: why page size retrieved from PdfStamper differes 
from page size from the PdfReader? This code when run will output this:
                
                Reader page size 612.0x792.0
                Stamper Size 595.0x842.0
                
                and the img.scaleAbsolute will not work correctly when the page 
size is taken from the page.getPdfDocument().getPageSize() but it will work 
just fine
                when width and height is from the PdfReader? Why is that?
                
                
                Thanks
                Karol
                
                

        
________________________________

        Aviso Legal:
        Esta mensagem é destinada exclusivamente ao destinatário. Pode conter 
informação confidencial ou legalmente protegida. A incorrecta transmissão desta 
mensagem não significa a perca de confidencialidade. Se esta mensagem for 
recebida por engano, por favor envie-a de volta para o remetente e apague-a do 
seu sistema de imediato. É proibido a qualquer pessoa que não o destinatário de 
usar, revelar ou distribuir qualquer parte desta mensagem. 
        
        Disclaimer:
        This message is destined exclusively to the intended receiver. It may 
contain confidential or legally protected information. The incorrect 
transmission of this message does not mean the loss of its confidentiality. If 
this message is received by mistake, please send it back to the sender and 
delete it from your system immediately. It is forbidden to any person who is 
not the intended receiver to use, distribute or copy any part of this message.
        

        

        No virus found in this incoming message.
        Checked by AVG - www.avg.com
        Version: 9.0.851 / Virus Database: 271.1.1/3047 - Release Date: 
08/03/10 21:45:00
        

        

------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share
of $1 Million in cash or HP Products. Visit us here for more details:
http://p.sf.net/sfu/dev2dev-palm
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to