mirror of
				https://github.com/Frooodle/Stirling-PDF.git
				synced 2025-10-25 11:17:28 +02:00 
			
		
		
		
	[fix]: check for encryption in PageNumbers (#1949)
[fix]: check for empty password encryption on load Co-authored-by: maxi322 <maxi322@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									df901db1f8
								
							
						
					
					
						commit
						1c6e5df77d
					
				| @ -67,15 +67,6 @@ public class SplitPdfByChaptersController { | ||||
|         } | ||||
|         PDDocument sourceDocument = Loader.loadPDF(file.getBytes()); | ||||
| 
 | ||||
|         // checks if the document is encrypted by an empty user password | ||||
|         if (sourceDocument.isEncrypted()) { | ||||
|             try { | ||||
|                 sourceDocument.setAllSecurityToBeRemoved(true); | ||||
|                 logger.info("Removing security from the source document "); | ||||
|             } catch (Exception e) { | ||||
|                 logger.warn("Cannot decrypt the pdf"); | ||||
|             } | ||||
|         } | ||||
|         PDDocumentOutline outline = sourceDocument.getDocumentCatalog().getDocumentOutline(); | ||||
| 
 | ||||
|         if (outline == null) { | ||||
|  | ||||
| @ -7,6 +7,8 @@ import java.io.InputStream; | ||||
| 
 | ||||
| import org.apache.pdfbox.Loader; | ||||
| import org.apache.pdfbox.pdmodel.PDDocument; | ||||
| import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Component; | ||||
| import org.springframework.web.multipart.MultipartFile; | ||||
| @ -18,6 +20,8 @@ import stirling.software.SPDF.model.api.PDFFile; | ||||
| @Component | ||||
| public class CustomPDDocumentFactory { | ||||
| 
 | ||||
|     private static final Logger logger = LoggerFactory.getLogger(CustomPDDocumentFactory.class); | ||||
| 
 | ||||
|     private final PdfMetadataService pdfMetadataService; | ||||
| 
 | ||||
|     @Autowired | ||||
| @ -71,6 +75,7 @@ public class CustomPDDocumentFactory { | ||||
|     public PDDocument load(byte[] input) throws IOException { | ||||
|         PDDocument document = Loader.loadPDF(input); | ||||
|         pdfMetadataService.setDefaultMetadata(document); | ||||
|         removezeropassword(document); | ||||
|         return document; | ||||
|     } | ||||
| 
 | ||||
| @ -96,5 +101,17 @@ public class CustomPDDocumentFactory { | ||||
|         return document; | ||||
|     } | ||||
| 
 | ||||
|     private PDDocument removezeropassword(PDDocument document) throws IOException { | ||||
|         if (document.isEncrypted()) { | ||||
|             try { | ||||
|                 logger.info("Removing security from the source document"); | ||||
|                 document.setAllSecurityToBeRemoved(true); | ||||
|             } catch (Exception e) { | ||||
|                 logger.warn("Cannot decrypt the pdf"); | ||||
|             } | ||||
|         } | ||||
|         return document; | ||||
|     } | ||||
| 
 | ||||
|     // Add other load methods as needed, following the same pattern | ||||
| } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user