Hello,
I am using itext 5.0.6

I am creating a PDF and then want to close the handle (document) of that
PDF.  I have this code

After creating the PDF I cannot do file.delete() because there's still an
open handle.  I tried to close Document, PdfWriter and the FileOutputStream
that I feed to the PdfWriter, there was still a handle longering on the
file.. (I even tried to delete through windows explorer while the java
program was running, it won't let me delete it.

thanks,
Alessandro Ferrucci

       File filename = new File(USER_HOME, b.batchID + "_tmpoutput_" +
b.batchID.hashCode() + ".pdf");
        System.out.println("PRINTING PDF TO " + filename);
        FileOutputStream fos = null;
        PdfWriter writer = null;
        Document document = null;
        try
        {
            fos = new FileOutputStream(filename);
            document = new Document(PageSize.LETTER, 0, 0, 0, 0);

            writer = PdfWriter.getInstance(document, fos);
            document.open();
            PdfContentByte cb = writer.getDirectContent();
            BaseFont bf = BaseFont.createFont(BaseFont.COURIER_BOLD,
BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            cb.beginText();
            cb.setFontAndSize(bf, 32);
            cb.showTextAligned(cb.ALIGN_CENTER, "FOOBAR", 300, 680, 0);
            cb.showTextAligned(cb.ALIGN_CENTER, "FOOBAR", 300, 630, 0);
            cb.endText();

            BarcodeInter25 barcode = new BarcodeInter25();
            barcode.setCode(b.batchID);
            barcode.setFont(BaseFont.createFont(BaseFont.COURIER_BOLD,
BaseFont.CP1252, BaseFont.NOT_EMBEDDED));

            com.itextpdf.text.Image image =
barcode.createImageWithBarcode(cb, null, null);
            image.scaleAbsoluteWidth(180);
            image.scaleAbsoluteHeight(50);
            image.setAbsolutePosition(215, 10);

            cb.addImage(image);
            image.setRotationDegrees(180f);
            image.setAbsolutePosition(215, 730);
            cb.addImage(image);

            cb.beginText();
            cb.setFontAndSize(bf, 20);
            cb.showTextAligned(cb.ALIGN_CENTER, "BATCH ID: " + b.batchID,
300, 500, 0);
            cb.showTextAligned(cb.ALIGN_CENTER, "SCAN CYCLES: " +
b.scanCycle, 300, 450, 0);
            cb.showTextAligned(cb.ALIGN_CENTER, "# LABELS: " + numlabels,
300, 400, 0);
            cb.showTextAligned(cb.ALIGN_CENTER, "Batch Completed: " +
df.format(b.currentStatusDate), 300, 350, 0);
            cb.showTextAligned(cb.ALIGN_CENTER, "Sheet Printed: " +
df.format(new Date()), 300, 300, 0);
            cb.endText();
        }
        catch (Exception ex)
        {
            logger.error(ex.getMessage(), ex);
            return null;
        }
        finally
        {
            document.close();
//            try
//            {
//                fos.flush();
//                fos.close();
//            }
//            catch (IOException ex)
//            {
//                logger.error(ex.getMessage(), ex);
//            }
//            writer.close();

        }
-- 
Signed,
Alessandro Ferrucci
------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network 
management toolset available today.  Delivers lowest initial 
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to