Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iText pdfReader Not Releasing File in ColdFusion 2018

I am upgrading to ColdFusion 2018. iText routines that I use to convert and rotate PDFs, the pdfReader puts locks on the file that do not release when the page is done.

I have tried adding a close() method to my code. (It was not needed on the pdfReader in Release 11.)

<cfscript>

reader = createObject("java", "com.lowagie.text.pdf.PdfReader").init( "test.pdf" );

reader.close();

inStream = createObject("java", "java.io.FileReader").init("test2.pdf");

inStream.close();

</cfscript>

I would expect to be able to rename or delete both files when the supplied script is ran, but only the inStream file (test2.pdf) can be. The reader file (test.pdf) is locked by the system.

like image 684
Michael Miller Avatar asked Dec 08 '25 09:12

Michael Miller


1 Answers

Using the suggestions above, I think the following solution will work.

<cfscript>

    fkeys = createObject("java", "java.io.FileInputStream");
    lKeyStoreFileStream = createObject("java", "java.io.BufferedInputStream").init(fkeys.init("test.pdf"));    

    reader = createObject("java", "com.lowagie.text.pdf.PdfReader").init( lKeyStoreFileStream );

    lKeyStoreFileStream.close();
    fkeys.close();

    reader.close();

</cfscript> 
like image 136
Michael Miller Avatar answered Dec 09 '25 21:12

Michael Miller



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!