Last updated October 2, 2011. Created by bmdhussain on July 2, 2010.
Edited by JuliaKM. Log in to edit this page.

Check whether uploaded pdf document is encrypted or password protected. Scribd is not allowing to upload password protected and encrypted documents. This might be useful to someone who wants to validate whether the uploaded pdf documents are encrypted or not.

Library File needed.

FPDI Version 1.3.3
Before starting, you have to do a small tweak in the library file pdf_parser.php
Replace the already available error function with the below given code.
This file is Licensed under the Apache License, Version 2.0 (the "License"); Please check whether you can use or modify the file or not.

<?php
function error($msg) {
        $this->errormsg = '<b>PDF-Parser Error:</b> '.$msg;
                return false;
        }

Small snippet.

<?php
/**
* Implementation of hook_form_alter()
* @param <type> $form
* @param <type> $form_state
* @param <type> $form_id
*/
function pdftest_form_alter(&$form, $form_state, $form_id) {
  if($form_id == 'ipaper_node_form') {
    $form['#validate'][] = 'pdftest_is_encrypted';
  }
}
/**
* Check whether pdf is encrypted or password protected.
* @param <type> $form
* @param <type> $form_state
*/
function pdftest_is_encrypted($form,&$form_state) {
     include_once 'sites/all/libraries/fpdi/pdf_parser.php';
     foreach($form_state['values']['files'] as $value) {
       //Check whether file type is pdf and confirm the file is selected to remove.
        if($value['filemime'] == 'application/pdf' && $value['remove'] != 1) {
          $pdf = new pdf_parser($value['filepath']);
          if(stristr($pdf->errormsg,'File is encrypted')) {
              form_set_error('field_attachment', t('Uploaded PDF Document '.$value['filename'].' is encrypted and can not be uploaded. '.l('Guide to troubleshooting failed uploads.','http://support.scribd.com/forums/33627/entries/24412')));
          }
        }
     }
}

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.