关闭PdfStamper时java.io.EOFException

时间:2017-03-16 06:23:10

标签: java itext

`        
            int page_isert_count  = 2;
            String[] file_names   = fileNames.split(",");
            PdfReader pdfReader   = new PdfReader(pdf_file); 
            PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileOutputStream(pdf_file));

            for (int index = 0; index < file_names.length; index++) {
                content = null;
                if(xPrint == 1){
                    x_image = Image.getInstance(Sharedpath+"/x/inbox/"+file_names[index]);
                }
                if(xPrint == 2){
                    if(Id < 0){
                        x_image = Image.getInstance(Sharedpath+filePath+file_names[index]);
                    }else{
                        x_image = Image.getInstance(Sharedpath+"/info/"+Id+"/"+file_names[index]);
                    }
                }
                scalwidht = x_image.getScaledWidth();
                System.out.println("scalewidth==========="+scalwidht);
                scalheight = x_image.getScaledHeight();
                System.out.println("scaleheight==========="+scalheight);
                pdfStamper.insertPage(page_isert_count, new Rectangle(scalwidht,scalheight));
                content = pdfStamper.getOverContent(page_isert_count);
                x_image.scaleToFit(scalwidht,scalheight);
                x_image.setAbsolutePosition(0f,0f);
                content.addImage(x_image);
                page_isert_count =page_isert_count+1;
            }

            pdfStamper.close();
            pdfReader.close();`

java.io.EOFException的         at com.itextpdf.text.pdf.RandomAccessFileOrArray.readFully(RandomAccessFileOrArray.java:261)         at com.itextpdf.text.pdf.RandomAccessFileOrArray.readFully(RandomAccessFileOrArray.java:253)         at com.itextpdf.text.pdf.PdfReader.getStreamBytesRaw(PdfReader.java:2344)         at com.itextpdf.text.pdf.PdfReader.getStreamBytesRaw(PdfReader.java:2381)         在com.itextpdf.text.pdf.PRStream.toPdf(PRStream.java:215)         at com.itextpdf.text.pdf.PdfIndirectObject.writeTo(PdfIndirectObject.java:157)         at com.itextpdf.text.pdf.PdfWriter $ PdfBody.add(PdfWriter.java:396)         at com.itextpdf.text.pdf.PdfWriter.addToBody(PdfWriter.java:847)         at com.itextpdf.text.pdf.PdfStamperImp.close(PdfStamperImp.java:304)         at com.itextpdf.text.pdf.PdfStamper.close(PdfStamper.java:189)

0 个答案:

没有答案