Re: Pdf Annotaion and Tab order error.

Ramagopal R Devapatla <[email protected]>
Newsgroups gmane.comp.java.lib.itext.general
Message-ID <CAGVtND7pzQYeQ1Yf8taLrF0GXpya=-MAdUzPbdm7HUPYd9_6dQ@mail.gmail.com>
Hi All,

I am attaching code snippett and message as txt file.



On Tue, Aug 12, 2014 at 12:21 PM, Ramagopal R Devapatla <
[email protected]> wrote:

> Hi All,
>
>
>
> I have created a pdf file with list of states table in first page and when
> you click the link it takes to the page, on the state page there is link
> again to come back to the list of states page.
>
>
>
> The attached document has pdf screen shots and error report.
>
>
>
> My Code snippet to create the pdf is as follows :
>
>
>
> 1: to create pdf table with links :
>
> *private* PdfPTable createStateLinksTable(List<OcseMatrixDO>
> empServInfoList) *throws* DocumentException{
>
>
>
>
>
>               PdfPTable pdfTable = *new* PdfPTable(3);
>
>               pdfTable.getDefaultCell().setBorder(0);
>
>               pdfTable.getDefaultCell().setPaddingTop(100f);
>
>
>
>               *int*[] tableWidth = *new* *int*[3];
>
>               tableWidth[0] = 200;
>
>               tableWidth[1] =200;
>
>               tableWidth[2] = 200;
>
>               pdfTable.setWidths(tableWidth);
>
>        //     pdfTable.setTotalWidth(500f);
>
>               pdfTable.setTotalWidth(600f);
>
>
>
>               Font link = FontFactory.*getFont*(FontFactory.*HELVETICA*,
> 12, Font.*UNDERLINE*, Color.*BLUE*);
>
>               OcseMatrixDO ocseMatrixDO = *null*;
>
>               PdfPTable stateTable1 = *new* PdfPTable(1);
>
>               PdfPTable stateTable2 = *new* PdfPTable(1);
>
>               PdfPTable stateTable3 = *new* PdfPTable(1);
>
>               stateTable1.getDefaultCell().setBorder(0);
>
>               stateTable2.getDefaultCell().setBorder(0);
>
>               stateTable3.getDefaultCell().setBorder(0);
>
>
>
>               PdfPCell addCell1;
>
>               Chunk chunk1 = *null*;
>
>
>
>               addCell1 = *new* PdfPCell(*new* Phrase(" "));
>
>               addCell1.setBorder(0);
>
>
>
>               pdfTable.addCell(addCell1);
>
>               pdfTable.addCell(addCell1);
>
>               pdfTable.addCell(addCell1);
>
>
>
>               *int* geoListSize = empServInfoList.size();
>
>               *for*(*int* g=0; g<geoListSize; g++ )
>
>               {
>
>                      ocseMatrixDO = empServInfoList.get(g);
>
>
>
>                      chunk1 = *new* Chunk(ocseMatrixDO.getGeoName(),
> link).setLocalGoto(" "+ocseMatrixDO.getGuid());
>
>                      addCell1 = *new* PdfPCell(*new* Phrase(chunk1));
>
>                      addCell1.setBorder(0);
>
>
>
>                      *if*(g<(geoListSize/3))
>
>                            stateTable1.addCell(addCell1);
>
>                      *else* *if* (g<((geoListSize * 2)/3))
>
>                            stateTable2.addCell(addCell1);
>
>                      *else*
>
>                            stateTable3.addCell(addCell1);
>
>               }
>
>               pdfTable.addCell(stateTable1);
>
>               pdfTable.addCell(stateTable2);
>
>               pdfTable.addCell(stateTable3);
>
>
>
>               *return* pdfTable;
>
>        }
>
>
>
> 2: to render the pdf table using content byte :
>
> *private* *void* setStateLinksData(PdfWriter writer, List<OcseMatrixDO>
> empServInfoList) *throws* MalformedURLException, DocumentException
>
>        {
>
>               PdfPTable pdfTable = createStateLinksTable(empServInfoList);
>
>
>
>               PdfStructureTreeRoot root = writer.getStructureTreeRoot();
>
>               PdfStructureElement linktable = *new*
> PdfStructureElement(root, *new*    PdfName("Table"));
>
>               linktable.put(PdfName.*LANG*, *new* PdfString("en-us"));
>
>               *int* columnCount      = 3;
>
>               *float* xPos = 145;
>
>         *float* yPos =525f;
>
>
>
>         *float* widths[] = pdfTable.getAbsoluteWidths();
>
>         pdfTable.setHeaderRows(1);
>
>
>
>               *for*(*int* i=0; i < pdfTable.size();  i++) {
>
>                      PdfContentByte canvases[] = PdfPTable.
> *beginWritingRows*(writer.getDirectContent());
>
>
>
>                PdfStructureElement tr = *new*
> PdfStructureElement(linktable, *new* PdfName("TR"));
>
>                tr.put(PdfName.*LANG*, *new* PdfString("en-us"));
>
>                *for*(*int* j = 0; j < columnCount; j++) {
>
>                      PdfStructureElement td = *null*;
>
>                      *if*(i==0)
>
>                             td = *new* PdfStructureElement(tr, *new*
> PdfName("TH"));
>
>                      *else*
>
>                             td = *new* PdfStructureElement(tr, *new*
> PdfName("TD"));
>
>                      td.put(PdfName.*LANG*, *new* PdfString("en-us"));
>
>
>
>                    PdfContentByte cb = canvases[PdfPTable.*TEXTCANVAS*];
>
>                    cb.beginMarkedContentSequence(td);
>
>                    *if*((j+1) == columnCount) {
>
>                      yPos = pdfTable.writeSelectedRows(j, j + 1, i, i+1,
> xPos,yPos, canvases);
>
>                           xPos = 145;
>
>                    } *else* {
>
>                       pdfTable.writeSelectedRows(j, j + 1, i, i+1, xPos ,
> yPos,    canvases);
>
>                         xPos += widths[j];
>
>                    }
>
>                    cb.endMarkedContentSequence();
>
>                }
>
>                PdfPTable.*endWritingRows*(canvases);
>
>               }
>
>
>
>        }
>
>
>
> 3: to create link of each state details page:
>
>
>
> *private* *void* getStateLinksData(PdfWriter writer, *boolean*
> isDestination) *throws* DocumentException
>
>        {
>
>               Font link = FontFactory.*getFont*(FontFactory.*HELVETICA*,
> 10, Font.*UNDERLINE*, Color.*BLUE*);
>
>               PdfStructureElement div = *new*
> PdfStructureElement(writer.getStructureTreeRoot(), *new* PdfName("Span"));
>
>               div.put(PdfName.*LANG*, *new* PdfString("en-US"));
>
>
>
>               PdfContentByte cb = writer.getDirectContent();
>
>
>
>               *float* xPos = 680;
>
>               *float* yPos = 480;
>
>
>
>               *if*(isDestination){
>
>                      xPos = 350;
>
>                      yPos = 450;
>
>               }
>
>
>
>               cb.saveState();
>
>               cb.beginMarkedContentSequence(div);
>
>               cb.beginText();
>
>
>
>               *if*(isDestination){
>
>                      PdfDestination pdfDest = *new*
> PdfDestination(PdfDestination.*XYZ*,-1,-1,0);
>
>                      cb.setFontAndSize(link.getBaseFont(), 12);
>
>                      cb.showTextAligned(PdfContentByte.*ALIGN_LEFT*, "List
> of States", xPos, yPos, 0);
>
>                      cb.localDestination("STA", pdfDest);
>
>               }*else*{
>
>                      cb.setFontAndSize(link.getBaseFont(), 10);
>
>                      cb.setColorFill(Color.*BLUE*);
>
>                      cb.showTextAligned(PdfContentByte.*ALIGN_LEFT*, "List
> of States", xPos, yPos, 0);
>
>                      cb.localGoto("STA", xPos, yPos, xPos+60, yPos+5);
>
>
>               }
>
>
>
>               cb.endText();
>
>               cb.setColorFill(Color.*BLACK*);
>
>               cb.endMarkedContentSequence();
>
>               //cb.restoreState();
>
>               cb.saveState();
>
>        }
>
> Thanks and Regards,
> Ramagopal Devapatla.
>
>



-- 
Thanks and Regards,
Ramagopal Devapatla
856-656-0456

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

_______________________________________________
iText-questions mailing list
[email protected]
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
PdfCodeSnippet.txt (text/plain, 7.1 KB)
Hi All,

 

I have created a pdf file with list of states table in first page and when you click the link it takes to the page, on the state page there is link again to come back to the list of states page.

 

The attached document has pdf screen shots and error report.

 

My Code snippet to create the pdf is as follows :

 


1: to create pdf table with links :

private PdfPTable createStateLinksTable(List<OcseMatrixDO> empServInfoList) throws DocumentException{
 
              

              

              PdfPTable pdfTable = new PdfPTable(3);
 
              pdfTable.getDefaultCell().setBorder(0);
 
              pdfTable.getDefaultCell().setPaddingTop(100f);
 
              

              int[] tableWidth = new int[3];
 
              tableWidth[0] = 200;
 
              tableWidth[1] =200;
 
              tableWidth[2] = 200;
 
              pdfTable.setWidths(tableWidth);
 
       //     pdfTable.setTotalWidth(500f);
 
              pdfTable.setTotalWidth(600f);
 
 

              Font link = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.UNDERLINE, Color.BLUE);
 
              OcseMatrixDO ocseMatrixDO = null;
 
              PdfPTable stateTable1 = new PdfPTable(1);
 
              PdfPTable stateTable2 = new PdfPTable(1);
 
              PdfPTable stateTable3 = new PdfPTable(1);
 
              stateTable1.getDefaultCell().setBorder(0);
 
              stateTable2.getDefaultCell().setBorder(0);
 
              stateTable3.getDefaultCell().setBorder(0);
 
                                                

              PdfPCell addCell1;
 
              Chunk chunk1 = null;
 
              

              addCell1 = new PdfPCell(new Phrase(" "));
 
              addCell1.setBorder(0);
 
                           

              pdfTable.addCell(addCell1);
 
              pdfTable.addCell(addCell1);
 
              pdfTable.addCell(addCell1);
 
                           

              int geoListSize = empServInfoList.size();

              for(int g=0; g<geoListSize; g++ )

              {

                     ocseMatrixDO = empServInfoList.get(g);

                     

                     chunk1 = new Chunk(ocseMatrixDO.getGeoName(), link).setLocalGoto(" "+ocseMatrixDO.getGuid());
 
                     addCell1 = new PdfPCell(new Phrase(chunk1));
 
                     addCell1.setBorder(0);
 
                     

                     if(g<(geoListSize/3))
 
                           stateTable1.addCell(addCell1);
 
                     else if (g<((geoListSize * 2)/3))

                           stateTable2.addCell(addCell1);
 
                     else
 
                           stateTable3.addCell(addCell1);
 
              }

              pdfTable.addCell(stateTable1);
 
              pdfTable.addCell(stateTable2);
 
              pdfTable.addCell(stateTable3);
 
              

              return pdfTable;
 
       }

 


2: to render the pdf table using content byte :

private void setStateLinksData(PdfWriter writer, List<OcseMatrixDO> empServInfoList) throws MalformedURLException, DocumentException

       {

              PdfPTable pdfTable = createStateLinksTable(empServInfoList);

              

              PdfStructureTreeRoot root = writer.getStructureTreeRoot();

              PdfStructureElement linktable = new PdfStructureElement(root, new    PdfName("Table"));
 
              linktable.put(PdfName.LANG, new PdfString("en-us"));
 
              int columnCount      = 3;   

              float xPos = 145;
 
        float yPos =525f;
 
        

        float widths[] = pdfTable.getAbsoluteWidths();

        pdfTable.setHeaderRows(1);
 
        

              for(int i=0; i < pdfTable.size();  i++) {

                     PdfContentByte canvases[] = PdfPTable.beginWritingRows(writer.getDirectContent());         

               

               PdfStructureElement tr = new PdfStructureElement(linktable, new PdfName("TR"));
 
               tr.put(PdfName.LANG, new PdfString("en-us"));
 
               for(int j = 0; j < columnCount; j++) {        

                     PdfStructureElement td = null;                

                     if(i==0)
 
                            td = new PdfStructureElement(tr, new PdfName("TH"));
 
                     else

                            td = new PdfStructureElement(tr, new PdfName("TD"));
 
                     td.put(PdfName.LANG, new PdfString("en-us"));
 
                     

                   PdfContentByte cb = canvases[PdfPTable.TEXTCANVAS];
 
                   cb.beginMarkedContentSequence(td);
 
                   if((j+1) == columnCount) {
 
                     yPos = pdfTable.writeSelectedRows(j, j + 1, i, i+1, xPos,yPos, canvases);     

                          xPos = 145; 

                   } else {
 
                      pdfTable.writeSelectedRows(j, j + 1, i, i+1, xPos , yPos,    canvases);

                        xPos += widths[j];
 
                   }   

                   cb.endMarkedContentSequence();
 
               }

               PdfPTable.endWritingRows(canvases);       

              }

              

       }      

       


3: to create link of each state details page:

 

private void getStateLinksData(PdfWriter writer, boolean isDestination) throws DocumentException
 
       {

              Font link = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.UNDERLINE, Color.BLUE); 

              PdfStructureElement div = new PdfStructureElement(writer.getStructureTreeRoot(), new PdfName("Span"));
 
              div.put(PdfName.LANG, new PdfString("en-US"));
 
              

              PdfContentByte cb = writer.getDirectContent();

              

              float xPos = 680;
 
              float yPos = 480;          

              

              if(isDestination){
 
                     xPos = 350;
 
                     yPos = 450;          

              }

              

              cb.saveState();
 
              cb.beginMarkedContentSequence(div);
 
              cb.beginText();            

              

              if(isDestination){
 
                     PdfDestination pdfDest = new PdfDestination(PdfDestination.XYZ,-1,-1,0);
 
                     cb.setFontAndSize(link.getBaseFont(), 12);

                     cb.showTextAligned(PdfContentByte.ALIGN_LEFT, "List of States", xPos, yPos, 0);

                     cb.localDestination("STA", pdfDest);
 
              }else{
 
                     cb.setFontAndSize(link.getBaseFont(), 10);

                     cb.setColorFill(Color.BLUE);
 
                     cb.showTextAligned(PdfContentByte.ALIGN_LEFT, "List of States", xPos, yPos, 0);

                     cb.localGoto("STA", xPos, yPos, xPos+60, yPos+5);                    

              }

              

              cb.endText();
 
              cb.setColorFill(Color.BLACK);
 
              cb.endMarkedContentSequence();    

              //cb.restoreState();
 
              cb.saveState();
 
       }
PdfAnootationand TabOrderError.doc (application/msword, 92 KB) - not displayed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.