You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Ayaka Shota (JIRA)" <ji...@apache.org> on 2011/03/28 10:50:05 UTC

[jira] [Closed] (PDFBOX-991) org.apache.pdfbox.cos.COSDocument finalize, did not close a PDF Document

     [ https://issues.apache.org/jira/browse/PDFBOX-991?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ayaka Shota closed PDFBOX-991.
------------------------------


There isn't any wrong with the code. Its the front code of using CopyDoc that is causing this error. CopyDoc doIt() will cause that problem. So have to create own function to copy one PDF file to another PDF file.

> org.apache.pdfbox.cos.COSDocument finalize, did not close a PDF Document
> ------------------------------------------------------------------------
>
>                 Key: PDFBOX-991
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-991
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 1.4.0
>         Environment: Eclipse Version: 3.4.1, Java SDK 1.6, Windows 7 32-bit 
>            Reporter: Ayaka Shota
>
> The error below keeps occurring when I run several PDF files.
> [Error]Mar 28, 2011 10:18:24 AM org.apache.pdfbox.cos.COSDocument finalize
> WARNING: Warning: You did not close a PDF Document
> Mar 28, 2011 10:18:24 AM org.apache.pdfbox.cos.COSDocument finalize
> WARNING: Warning: You did not close a PDF Document
> Mar 28, 2011 10:18:24 AM org.apache.pdfbox.cos.COSDocument finalize
> WARNING: Warning: You did not close a PDF Document
> Mar 28, 2011 10:18:24 AM org.apache.pdfbox.cos.COSDocument finalize
> WARNING: Warning: You did not close a PDF Document
> Mar 28, 2011 10:18:24 AM org.apache.pdfbox.cos.COSDocument finalize
> WARNING: Warning: You did not close a PDF Document
> Mar 28, 2011 10:18:24 AM org.apache.pdfbox.cos.COSDocument finalize
> WARNING: Warning: You did not close a PDF Document[/Error]
> Here's my code:
> public void methodForPDF() throws SQLException
> {
>      //fullFilePath is always changing and this method is called by another method for several times.
>      PDDocument doc = null;
>      PDActionURI uri = null;
>      ResultSet resultSet = null;
>      Statement statement = null;
>      int newURI = 0, type = 0;
>      String newuri = "";
>      String oldLink ="", line="", oldId="";
>      int pos = 0;
>      CharSequence char0 = "abc";
>      File f = new File(fullFilePath);
>      try
>      {
>            statement = dbConnection.createStatement(); 
>            doc = PDDocument.load(fullFilePath, false);
> 		    
>            List allPages = doc.getDocumentCatalog().getAllPages();
>            for( int i=0; i<allPages.size(); i++ )
>            {
> 	 PDPage page = (PDPage)allPages.get( i );
> 	 List annotations = page.getAnnotations();
> 	 for( int j=0; j<annotations.size(); j++ )
> 	 {
> 	        PDAnnotation annot = (PDAnnotation)annotations.get( j );
> 	        if( annot instanceof PDAnnotationLink )
>                         {
>                                PDAnnotationLink link = (PDAnnotationLink)annot;
>                                PDAction action = link.getAction();
>                                if( action instanceof PDActionURI )
>                                {
>                                      uri = (PDActionURI)action;
>     	                     String oldURI = uri.getURI();
>     	                     if(oldURI.contains(char0))
>     	                     { 
>     	                            
>     	                            line = oldURI;
>     	                            pos = line.lastIndexOf("=");
>     	                            oldLink = line.substring(0, pos+1);
>     	                        
>     	                            line = line.replace(oldLink, newWebformUrl+"?"+newArtName);
>     	                            pos = line.lastIndexOf("=");
>     	                            oldId = line.substring(pos+1, line.length());
>     	                        
> 		            resultSet = statement.executeQuery("SELECT newid, type "
> 			          + "FROM prrm.temp_migration_lookup WHERE oldid = " + oldId);
> 		                            
> 		            if (null != resultSet) {
> 			  while (resultSet.next()) {
> 			         newURI = resultSet.getInt("newid");
> 			         type = resultSet.getInt("type");
> 			   }
> 		             }
> 			                     
> 		            newuri = newURI + "";
>    		            String newurl = line.replace(oldId,newuri);
>    		            newurl = newurl + "?type=" + type;
>    		            //System.out.println( "Page " + (i+1) +": Replacing " + oldURI + " with " + newurl );
>    		            uri.setURI( newurl );
>     	                      }
> 		           
> 		   }
> 	           }
> 	 }
>             }
> 		            
>             doc.save(fullFilePath);
>             resultSet.close();
>             statement.close();
>             doc.close();
>            System.out.println("1: Close 1 File");
> 		            
>      } catch (IOException e) {
>           e.printStackTrace();
>      } catch (COSVisitorException e) {
>           // TODO Auto-generated catch block
>           e.printStackTrace();
>      }
>      finally
>      {
>            if( doc != null )
>            {
>                   try {
>                      doc.close();
>                      doc = null;
>                      System.out.println("2: Close 1 File");
> 	  } catch (IOException e) {
> 	       // TODO Auto-generated catch block
>                        e.printStackTrace();
> 	  }
>             }
>        }
>  }
> Here's the results of the run:
> 1: Close 1 File
> 2: Close 1 File
> Done 1 PDF file
> 1: Close 1 File
> 2: Close 1 File
> Done 1 PDF file
> 1: Close 1 File
> 2: Close 1 File
> Done 1 PDF file
> 1: Close 1 File
> 2: Close 1 File
> Done 1 PDF file
> 1: Close 1 File
> 2: Close 1 File
> Done 1 PDF file
> Mar 28, 2011 10:56:41 AM org.apache.pdfbox.cos.COSDocument finalize
> WARNING: Warning: You did not close a PDF Document
> Mar 28, 2011 10:56:41 AM org.apache.pdfbox.cos.COSDocument finalize
> WARNING: Warning: You did not close a PDF Document
> Mar 28, 2011 10:56:41 AM org.apache.pdfbox.cos.COSDocument finalize
> WARNING: Warning: You did not close a PDF Document
> Mar 28, 2011 10:56:41 AM org.apache.pdfbox.cos.COSDocument finalize
> WARNING: Warning: You did not close a PDF Document
> Mar 28, 2011 10:56:41 AM org.apache.pdfbox.cos.COSDocument finalize
> WARNING: Warning: You did not close a PDF Document
> Mar 28, 2011 10:56:41 AM org.apache.pdfbox.cos.COSDocument finalize
> WARNING: Warning: You did not close a PDF Document
> 1: Close 1 File
> 2: Close 1 File
> Done 1 PDF file

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira