Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 文档已关闭。你可以';不要添加任何元素_Spring_Itextpdf - Fatal编程技术网

Spring 文档已关闭。你可以';不要添加任何元素

Spring 文档已关闭。你可以';不要添加任何元素,spring,itextpdf,Spring,Itextpdf,我正在使用以下代码: protected void buildPdfDocument(Map<String, Object> model, Document document, PdfWriter writer, HttpServletRequest request,HttpServletResponse response) throws Exception { try { ArrayList<OrderDetails&g

我正在使用以下代码:

protected void buildPdfDocument(Map<String, Object> model,
    Document document, PdfWriter writer,
    HttpServletRequest request,HttpServletResponse response)
        throws Exception {
    try {
        ArrayList<OrderDetails> list = (ArrayList<OrderDetails>)model.get("orderDetailsList");
        document.setMargins(-24, -24, 135,60);        
        writer.setBoxSize("art", new Rectangle(36, 54, 559, 788));
        HeaderFooter event = new HeaderFooter();
        writer.setPageEvent((PdfPageEvent) event);
        PdfContentByte cb = writer.getDirectContent();
        PdfPTable upperTable = new PdfPTable(3);
        upperTable.setTotalWidth(515);
        upperTable.getDefaultCell().setPadding(6);
        upperTable.setWidthPercentage(100.0f);

        for(OrderDetails orderDetails : list) {
            document.open();  
            Font f3 = new Font(FontFamily.TIMES_ROMAN, 12.0f, Font.BOLD, BaseColor.GREEN);
            Font f1 = new Font(FontFamily.TIMES_ROMAN, 12.0f, Font.BOLD, BaseColor.WHITE);
            Font f2 = new Font(FontFamily.TIMES_ROMAN, 12.0f, Font.BOLD, BaseColor.BLACK);
            PdfPTable table1 = new PdfPTable(4);
            Font font = FontFactory.getFont(FontFactory.HELVETICA);
            font.setColor(BaseColor.BLACK);
            // define table header cell
            PdfPCell cell2 = new PdfPCell();
            cell2.setBackgroundColor(BaseColor.WHITE);
            cell2.setPadding(5);
            cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
            table1.getDefaultCell().setVerticalAlignment(Element.ALIGN_CENTER);
            // write table header
            cell2.setPhrase(new Phrase("Sno", font));
            table1.addCell(cell2);
            cell2.setPhrase(new Phrase("ISBN", font));
            table1.addCell(cell2);
            cell2.setPhrase(new Phrase("Quantity", font));
            table1.addCell(cell2);
            cell2.setPhrase(new Phrase("Status", font));
            table1.addCell(cell2);
            Date strDate=orderDetails.getDataInserted();
            DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
            String createdDate = formatter.format(strDate);
            upperTable.setWidths(new float[] {33,33,33});
            upperTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
            upperTable.getDefaultCell().setBackgroundColor(BaseColor.BLACK);      
            upperTable.addCell(new Phrase("  Bhavish Order Id :"+orderDetails.getBhavishOrderId(),f1));
            upperTable.addCell(new Phrase("Client Name:"+orderDetails.getClientName(),f1));
            upperTable.addCell(new Phrase("    Order Date:"+orderDetails.getOrderDate(),f1));   
            upperTable.writeSelectedRows(0, -1,40,734,cb );
            upperTable.flushContent();  
            upperTable = new PdfPTable(2); 
            upperTable.setTotalWidth(515);
            upperTable.getDefaultCell().setPadding(6);       
            upperTable.setWidths(new float[] {70,30});
            PdfPCell cell1 = upperTable.getDefaultCell();
            cell1.setBorder(Rectangle.NO_BORDER);
            Barcode128 code128 = new Barcode128();
            code128.setBarHeight(10);
            code128.setSize(5);
            code128.setCode("0123456789");
            upperTable.addCell(new Phrase("Batch ID :"+orderDetails.getBatchId(),f2));
            upperTable.getDefaultCell().setRowspan(2);
            upperTable.addCell(code128.createImageWithBarcode(cb, null, null));
            upperTable.getDefaultCell().setRowspan(1);
            upperTable.addCell(new Phrase("Epz/Nepz  :"+orderDetails.getEpzNepz(),f2));
            document.add(upperTable);
            upperTable.flushContent();   
            upperTable = new PdfPTable(3);
            upperTable.setWidths(new float[] {40,30,30});
            upperTable.setTotalWidth(515);
            upperTable.getDefaultCell().setPadding(6);        
            upperTable.getDefaultCell().setBackgroundColor(BaseColor.GRAY);         
            upperTable.addCell(new Phrase("        Order Details -  :",f1)); 
            upperTable.addCell(new Phrase("Type:"+orderDetails.getOrderType(),f1)); 
            upperTable.addCell(new Phrase("  On :"+createdDate,f1));  
            document.add(upperTable);
            upperTable.flushContent();   
            PdfPTable table = new PdfPTable(6);   
            table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
            table.setWidths(new float[] {19,2,29,20,2,29});     
            table.setSpacingBefore(5);
            table.getDefaultCell().setPadding(6);
            PdfPCell cell = table.getDefaultCell();
            cell.setBorder(Rectangle.NO_BORDER);
            cell.setHorizontalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(new Phrase("Client Name :",f2));       
            table.addCell(new Phrase(":"));      
            table.addCell(new Phrase(orderDetails.getClientName()));
            table.addCell(new Phrase("Urgent/Normal :",f2));         
            table.addCell(new Phrase(":"));       
            table.addCell(new Phrase(orderDetails.getNormalUrgent()));    
            table.addCell(new Phrase("Order Number :",f2));       
            table.addCell(new Phrase(":"));      
            table.addCell(new Phrase(orderDetails.getOrderNumber()));
            Set<OrderIsbnDetails> list1  = orderDetails.getOrderIsbnDetails(); 
            int ListISBN=list1.size();
            table.addCell(new Phrase("Total ISBN :",f2));         
            table.addCell(new Phrase(":"));       
            table.addCell(new Phrase(String.valueOf(ListISBN)));    
            document.add(table);
            table.flushContent();   
            int i=0;
            for (OrderIsbnDetails orderIsbnDetails : list1) {   
                i=i+1;
                table1.setWidthPercentage(70.0f);
                table1.setWidths(new float[] {0.2f, 1.0f, 0.4f, 1.0f});
                table1.setSpacingBefore(0);
                cell2.setPhrase(new Phrase(String.valueOf(i),font));
                cell2.setVerticalAlignment (Element.ALIGN_CENTER);
                table1.addCell(cell2);
                cell2.setPhrase(new Phrase(orderIsbnDetails.getIsbn(),font));
                System.out.println("The ISBN List "+orderIsbnDetails.getIsbn());
                cell2.setVerticalAlignment (Element.ALIGN_CENTER);
                table1.addCell(cell2);
                cell2.setPhrase(new Phrase(String.valueOf(orderIsbnDetails.getQuantity()),font));
                System.out.println("The ISBN List "+String.valueOf(orderIsbnDetails.getQuantity()));
                cell2.setVerticalAlignment (Element.ALIGN_CENTER);
                table1.addCell(cell2);
                cell2.setPhrase(new Phrase(orderIsbnDetails.getIsbnstatus(),font));
                System.out.println("The ISBN Status"+orderIsbnDetails.getIsbnstatus());
                cell2.setVerticalAlignment (Element.ALIGN_CENTER);
                table1.addCell(cell2);
                document.add(table1);
                table1.flushContent();
            }
            document.close();
        }
    }
    catch(Exception e)
    {
        e.printStackTrace();
        System.out.println("To Check the error In Order Detail PDF"+e);
    }
}
受保护的void buildPDF文档(地图模型,
文档,PDF编写器,
HttpServletRequest请求,HttpServletResponse响应)
抛出异常{
试一试{
ArrayList=(ArrayList)model.get(“orderDetailsList”);
文件。设置页边距(-24,-24135,60);
setBoxSize(“艺术”,新矩形(36、54、559、788));
HeaderFooter事件=新建HeaderFooter();
writer.setPageEvent((PdfPageEvent)事件);
PdfContentByte cb=writer.getDirectContent();
PdfPTable upperTable=新PdfPTable(3);
上表。设置总宽度(515);
upperTable.getDefaultCell().setPadding(6);
上表。设置宽度百分比(100.0f);
for(订单详细信息订单详细信息:列表){
document.open();
Font f3=新字体(FontFamily.TIMES_ROMAN,12.0f,Font.BOLD,BaseColor.GREEN);
Font f1=新字体(FontFamily.TIMES_ROMAN,12.0f,Font.BOLD,BaseColor.WHITE);
Font f2=新字体(FontFamily.TIMES_ROMAN,12.0f,Font.BOLD,BaseColor.BLACK);
PdfPTable TABLE 1=新的PdfPTable(4);
Font=FontFactory.getFont(FontFactory.HELVETICA);
font.setColor(BaseColor.BLACK);
//定义表格标题单元格
PdfPCell cell2=新的PdfPCell();
cell2.setBackgroundColor(基色:白色);
细胞2。设置填充(5);
单元格2.设置水平对齐(元素.对齐\中心);
表1.getDefaultCell().setVerticalAlignment(Element.ALIGN_CENTER);
//写表头
单元格2.设置短语(新短语(“Sno”,字体));
表1.addCell(cell2);
单元格2.设置词组(新词组(“ISBN”,字体));
表1.addCell(cell2);
单元格2.设置短语(新短语(“数量”,字体));
表1.addCell(cell2);
单元格2.设置短语(新短语(“状态”,字体));
表1.addCell(cell2);
Date strDate=orderDetails.getDataInserted();
DateFormat格式化程序=新的SimpleDataFormat(“dd-MM-yyyy-HH:MM:ss”);
字符串createdDate=formatter.format(strDate);
setWidths(新的float[]{33,33,33});
upperTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
upperTable.getDefaultCell().setBackgroundColor(BaseColor.BLACK);
addCell(新短语(“Bhavish Order Id:+orderDetails.getBhavishOrderId(),f1));
addCell(新短语(“客户端名称:”+orderDetails.getClientName(),f1));
addCell(新短语(“订单日期:+orderDetails.getOrderDate(),f1));
上表.writeSelectedRows(0,-1,40734,cb);
upperTable.flushContent();
上表=新的PDFP表(2);
上表。设置总宽度(515);
upperTable.getDefaultCell().setPadding(6);
设置宽度(新浮点[]{70,30});
PdfPCell cell1=upperTable.getDefaultCell();
单元格1.设置顺序(矩形,无边框);
Barcode128 code128=新的Barcode128();
代码128.立根高度(10);
代码128.设置大小(5);
代码128.设置代码(“0123456789”);
addCell(新短语(“批次ID:+orderDetails.getBatchId(),f2));
upperTable.getDefaultCell().setRowspan(2);
addCell(代码128.createImageWithBarcode(cb,null,null));
upperTable.getDefaultCell().setRowspan(1);
addCell(新短语(“Epz/Nepz:+orderDetails.getEpzNepz(),f2));
文件。添加(上表);
upperTable.flushContent();
上表=新的PDFP表(3);
设置宽度(新浮点[]{40,30,30});
上表。设置总宽度(515);
upperTable.getDefaultCell().setPadding(6);
upperTable.getDefaultCell().setBackgroundColor(BaseColor.GRAY);
addCell(新短语(“订单详细信息-:”,f1));
addCell(新短语(“类型:”+orderDetails.getOrderType(),f1));
addCell(新短语(“On:”+createdDate,f1));
文件。添加(上表);
upperTable.flushContent();
PdfPTable=新的PdfPTable(6);
table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
表.设置宽度(新浮点[{19,2,29,20,2,29});
表2.5之前的设置间隔;
table.getDefaultCell().setPadding(6);
PdfPCell cell=table.getDefaultCell();
单元格顺序(矩形,无边框);
cell.setHorizontalAlignment(Element.ALIGN_MIDDLE);
表.addCell(新短语(“客户名称:”,f2));
表.addCell(新短语(“:”);
addCell(新短语(orderDetails.getClientName());
表.addCell(新短语(“紧急/正常:”,f2));
表.addCell(新短语(“:”);
addCell(新短语(orderDetails.getNormalUrgent());
表.addCell(新短语(“订单号:”,f2));
表.addCell(新短语(“:”);
addCell(新短语(orderDetails.getOrderNumber());
Set list1=orderDetails.getOrderIsbnDetails();
int ListISBN=list1.size();
表.addCell(新短语(“ISBN总计:”,f2));
表.addCell(新短语(“:”);
表.addCell(新短语(String.valueOf(ListISBN));
文件。添加(表);
table.flushContent();
int i=0;
对于(OrderIsbnDetails OrderIsbnDetails:list1){
i=i+1;
表1.设定宽度百分比(70.0f);
表1.设置宽度(新浮点[]{0.2f、1.0f、0.4f、1.0f});
// step 1: create the document
Document document = new Document();
// step 2: create a writer that
// a. listens to the document
// b. writes to an outputstream
PdfWriter.getInstance(document, os);
// step 3: open the document
document.open();
// step 4: add as much content you want
document.add(...);
// step 5: close the document
document.close();
// step 1: create the document
Document document = new Document();
// step 2: create a writer that
// a. listens to the document
// b. writes to an outputstream
PdfWriter.getInstance(document, os);
for (some iterator) {
    // step 3: open the document
    document.open();
    // step 4: add as much content you want
    document.add(...);
    // step 5: close the document
    document.close();
}
// step 1: create the document
Document document = new Document();
// step 2: create a writer that
// a. listens to the document
// b. writes to an outputstream
PdfWriter.getInstance(document, os);
// step 3: open the document
document.open();
// step 4: add as much content you want
for (some iterator) {
    document.add(...);
}
// step 5: close the document
document.close();
public class FormularCreator {

private static Document document;


public static void createFormular() throws IOException, DocumentException {

    document = new Document(PageSize.A4, 70, 50, 50, 50);