首页 > 解决方案 > 如何在itext pdf中浮动表格

问题描述

我想让桌子向右浮动,但它不起作用。

public static String CreatePdf(String datapart1,String mobileNumber, String datapart2, String datapart3, String datapart4, String datapart5, String bankinfo, String time, String adminName) {
        QueryHelper qh = new QueryHelper();

          String copy = "<html>" + "<head>" + " <title></title>" + "<style>#demo{float:right;}</style>"
          + "</head>" + "<body>" +
          "<div class=\"row col-lg-12\">"+"<b><h1 style=\"text-align:center;\">\r\n" +
          "<u>Invoice</u>\r\n" + "</h1></b>\r\n" + "</div>" +
          "<div class=\"col-lg-12\"  style=\"width: 100%; height: 160px; margin-top: -6px \"><div class=\"col-md-6\" style=\"font-size: 13px; float: left; width: 50%; height: 160px;\">"
          + datapart1 + "</div>" +
          "<div style=\"width: 75%; height: 160px; font-size: 13px; float: right; text-align: left;\">"
          + bankinfo + "</div></div>" +
          "<div style=\"margin-right: 0px; margin-left: 0px; margin-top: 0px; width:100%;\"><table style=\"border:1px solid #ccc; width: 100%; margin-bottom: 0px; border-collapse: collapse; font-size: 12px;\">"
          + datapart2 + "</table>" +
          "<table style=\" border:1px solid #ccc; width: 100%; margin-bottom: 0px; float: right; border-collapse: collapse; font-size: 12px;\">"
          + datapart3 + "</table></div>" +
          "<div class=\"col-lg-12 row\" style=\"width:100%;\" ><div class=\"col-md-6\" style=\" float:left; width=:60%; \" > </div>"
          + "<div class=\"col-md-6\" style=\"height: auto;\"><table style=\" border:1px solid #ccc;width: 40%; margin-bottom: 20px; float:right; border-collapse: collapse; text-align: right; font-size: 12px;\" > "
          + datapart4 + "</table></div></div>" +
          "<table style=\" border:1px solid #ccc; width: 100%; font-size: 13px; text-align: center; border-collapse: collapse;\">"
          + datapart5 + "</table>"+""
                + "<table style=\"border:1px; float:center; \"> <tr> <td>demo</td></tr> </table>"
          + "</body>" + "</html>";

        /*
         * String copy="<html>"+ "<head>"+ "</head>"+ "<body>"+
         * bankinfo+"</body></html>";
         */
        String status = "fasle";
        System.out.println(copy);
        try {
            String filePath;
            Document document = new Document();
            Random rand = new Random();
            int rand_int1 = rand.nextInt(1000);
            String fileName = mobileNumber + rand_int1 + ".pdf";
            filePath = "/opt/apache-tomcat-8.5.45/Invoice PDF/" + fileName;
            OutputStream file = new FileOutputStream(new File(fileName));
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filePath));
            StringBuilder htmlString = new StringBuilder();
            htmlString.append(new String(copy));
//          System.out.println(htmlString);

            Image image;
            image = Image.getInstance("/opt/apache-tomcat-8.5.45/webapps/images/zakas-20-20.png");

            document.open();
            document.add(image);
            InputStream is = new ByteArrayInputStream(htmlString.toString().getBytes());
            XMLWorkerHelper.getInstance().parseXHtml(writer, document, is);
            System.out.println("Method Pdf >> invoiceText " + writer);

//          document.add(new Chunk("\n"));
//          document.add(new Chunk("\t"));

            System.out.println(document);
            status = "true";



                document.close();
                writer.close();
                file.close();
            System.out.println("genrated");
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
        return status;
    }

标签: javaitext

解决方案


推荐阅读