From: SALAZAR, DANTE [mailto:digitron...@cwpanama.net] 
Sent: Thursday, August 15, 2013 8:56 AM
To: Post all your questions about iText here
Subject: Re: [iText-questions] Vertical Position of the first paragraph

IdentationLeft works for me, but in this case I would need IdentationUp, but 
this don't exist
SpacingBefore would be good for me, but it don't works.
In the meantime I used this:
I printed a blank paragraph first
        prf = New Paragraph("                           ", fnt)
        Doc.Add(prf)
and then printed my actual paragraph, with SapacingBefore=100
        prf = New Paragraph(x, fnt)
        prf.SpacingBefore = 100
        prf.set()
        Doc.Add(prf)
I am sure this way is not fine, but runs well
How would be your code if you need to begin printing a paragraph at position 
620?

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

Something like this?  I don't know...

        public static void paragraphAtPosition(){
                
                Document document = new Document(PageSize.LETTER);
                document.setMargins(0, 0, 0, 0);

                String path = System.getProperty("user.dir");
                String filename = "HelloWorld.pdf";
                
                Paragraph p = new Paragraph("A phrase positioned at 620 units 
from left and 10 units from the top");
                Paragraph p2 = new Paragraph("A phrase positioned at 0 units 
from left");
                
                PdfWriter writer = null;
                PdfContentByte cb = null;
                
                PdfPTable table = new PdfPTable(1);
                table.setTotalWidth(250);
                table.addCell(p);
                
                PdfPTable table2 = new PdfPTable(1);
                table2.setTotalWidth(250);
                table2.addCell(p2);
                
                try{
                        FileOutputStream fos = new FileOutputStream(filename);

                        writer = PdfWriter.getInstance(document, fos);

                        document.open();
                        document.addTitle("Hello World !!");
                        
                        cb = writer.getDirectContent();
                        
                        table.writeSelectedRows(0, -1, 172, 
document.getPageSize().getTop() - 10, cb);
                        
                        table2.writeSelectedRows(0, -1, 0, 
document.getPageSize().getTop() - 10 - table.getTotalHeight(), cb);

                        
                } catch (Exception e){
                        e.printStackTrace();
                }
                
                System.out.println("writer vertical pos: " + 
writer.getVerticalPosition(false));  // prints:  writer vertical pos: 792.0
                
                document.close();
                
                File file = new File(path + "\\" + filename);
                
                try {
                        Desktop.getDesktop().open(file);
                } catch (IOException e) {
                        e.printStackTrace();
                }
        }

------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead. 
Download for free and get started troubleshooting in minutes. 
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to