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 04:34:05 UTC

[jira] [Updated] (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 updated PDFBOX-991:
-------------------------------

    Description: 
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();
		            
     } catch (IOException e) {
          e.printStackTrace();
     } catch (COSVisitorException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
     }
     finally
     {
           if( doc != null )
           {
                  try {
                     doc.close();
                     doc = null;
	  } catch (IOException e) {
	       // TODO Auto-generated catch block
                       e.printStackTrace();
	  }
            }
       }
 }

  was:
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
{
     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();
		            
     } catch (IOException e) {
          e.printStackTrace();
     } catch (COSVisitorException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
     }
     finally
     {
           if( doc != null )
           {
                  try {
                     doc.close();
                     doc = null;
	  } catch (IOException e) {
	       // TODO Auto-generated catch block
                       e.printStackTrace();
	  }
            }
       }
 }


> 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();
> 		            
>      } catch (IOException e) {
>           e.printStackTrace();
>      } catch (COSVisitorException e) {
>           // TODO Auto-generated catch block
>           e.printStackTrace();
>      }
>      finally
>      {
>            if( doc != null )
>            {
>                   try {
>                      doc.close();
>                      doc = null;
> 	  } catch (IOException e) {
> 	       // TODO Auto-generated catch block
>                        e.printStackTrace();
> 	  }
>             }
>        }
>  }

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