         
         _filename = _filename.sanitizedPDFFilenameString
         
-        let tmpPath = NSString(string: NSTemporaryDirectory()).appendingPathComponent(_filename)
+        // Define storage path
         
-        pdfPath = tmpPath
+        var storageDirectory: String
+        if let inDirectory = inDirectory {
+            storageDirectory = inDirectory
+        } else {
+            storageDirectory = NSTemporaryDirectory()
+        }
+        
+        let storagePath = NSString(string: storageDirectory).appendingPathComponent(_filename)
+        
+        pdfPath = storagePath
         
         // Define PDF context
         

                               size: defaultPageSize.size)
        }
        
        UIGraphicsBeginPDFContextToFile(tmpPath, pagesSize, pdfMetadata)
        
        // Perform draw pages
        

        pages.append(page)
    }
    
    open func generate(inDirectory: String? = nil) {
        
        if let filename = filename {
            _filename = filename
