如何使用java中的list元素填充Table

时间:2014-02-20 06:02:03

标签: java pdfbox

我想生成一个包含标题为数字,状态和计数的表。

然后想要用从列表中获得的元素中填充数据。

数字将是s.no,状态将是从列表中获取的元素  count是元素在列表中退出的次数。 但我不知道如何使用pdf框生成表格并生成pdf。 我已正常生成pdf但不知道如何制作表格。 我想在表格中添加itr作为表格数据...请帮帮我

public PerformResult perform(CronJobModel arg0)
{
    final String method_name = "getListByStatus";

    LOG.debug("Entering - " + method_name);
    List<String> orderModelList = osiReportGenerate.getStatusList();

    // Check if the order list is empty
    if (CollectionUtils.isNotEmpty(orderModelList)) {
        Iterator<String> itr=orderModelList.iterator();
        int y=670,x=600,no=1;

        PDDocument document;
        try
        {
            System.out.println("hello cron job");
            document = new PDDocument();

            PDPage page = new PDPage();
            document.addPage(page);
            PDFont font = PDType1Font.HELVETICA_BOLD;
            PDPageContentStream contentStream = new PDPageContentStream(document, page);
            //DrawString for Number to pdf
            contentStream.beginText();
            contentStream.setFont( font, 12 );
            contentStream.moveTextPositionByAmount( 10,y );
            contentStream.drawString("Number");
            contentStream.endText();
            //DrawString for status to pdf
            contentStream.beginText();
            contentStream.setFont( font, 12 );
            contentStream.moveTextPositionByAmount( 200,y );
            contentStream.drawString("Status");
            contentStream.endText();
            //DrawString for count to pdf
            contentStream.beginText();
            contentStream.setFont( font, 12 );
            contentStream.moveTextPositionByAmount( 400,y );
            contentStream.drawString("Count");
            contentStream.endText();

            while(itr.hasNext()){
                //for printing numbers.....
                contentStream.beginText();
                contentStream.setFont( font, 12 );
                contentStream.moveTextPositionByAmount( 10,x );
                contentStream.drawString(""+no);
                contentStream.endText();
                no++;
                //For printing status....
                contentStream.beginText();
                contentStream.setFont( font, 12 );
                contentStream.moveTextPositionByAmount( 200,x );
                contentStream.drawString(itr.next());
                contentStream.endText();
                x=x-25;
            }

            PDXObjectImage ximage = new PDJpeg(document, new        FileInputStream("C:\\Users\\Dell\\Downloads\\rr.jpg"));
            System.out.println("1");

            System.out.println("2");
            //DrawImage for to pdf
            contentStream.drawImage(ximage,10,680);
            System.out.println("3");


            //contentStream.endText();
            contentStream.close();
            Date date=new Date();
            int filename=date.getSeconds();
            document.save("D:\\"+filename+".pdf");
            document.close();


        }

        catch (Exception e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }



    }
    return new PerformResult(CronJobResult.SUCCESS, CronJobStatus.FINISHED);
           }

0 个答案:

没有答案