简体   繁体   中英

How can I draw a rectangle into pdf file and fill it with text?

I've started to work on a simple Android project recently, where I have to collect some data from a database and put them into a pdf file.

I'd like to put these data into some rectangles, to get something like this:

在此处输入图片说明

I've read about rectangles on this post , and I think it's gonna work in Android too. The only thing I can't get is how to fill my data into the rectangle.

Could you give me any suggestion, please?

Thank you in advance...

I have a similar code where i used table and set the value.It may provide you with some hint:

private static Font blackFont = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD);

private void createSeg_Table(Document document)throws DocumentException,IOException{
        PdfPTable table = new PdfPTable(1);
        table.setWidthPercentage(100);

        try{

          PdfPCell c1 = new PdfPCell(new Paragraph("text you want to show",blackFont));
          c1.setVerticalAlignment(Element.ALIGN_LEFT);
          c1.setBorder(Rectangle.BOX);
                  table.addCell(c1);                                     
                  document.add(table);
        }
        catch(Exception ex){
            System.out.println(ex);
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM