pdfprotect

pdfprotect protects pdf files against printing and copying content of a pdf file

Syntax

  • out=pdfprotect(inputfile)example
  • out=pdfprotect(inputfile,Name,Value)example

Description

This function protects pdf files against printing and copying content.

Also, when needed, can add a watermark diagonally on all pages of the manuscript.

Please note that the output pdf file will be encrypted, so it is better to save the original document for backup purposes.

pdfprotect assumes that the user installed miniconda (a Python distribution) with all the default options. If this is not the case, the user should edit the path to Python executable inside MATLAB code of this function according to the custom setup.

example

out =pdfprotect(inputfile) Example with all default values.

example

out =pdfprotect(inputfile, Name, Value) Example with watermark option.

Examples

expand all

  • Example with all default values.
  • %% Example with all default values.
    % encrypt and protect a file revoking all authorizations to copy and
    % print.
    % Create pdf file tmptmpENC.pdf 
    % create .m file==> transform to mlx ==> export to pdf
    FileName='addFSDA2path.m';
    FileNameMLX='tmptmp.mlx';
    matlab.internal.liveeditor.openAndSave(which(FileName),FileNameMLX);
    % Create file tmptmp.pdf
    export(FileNameMLX);
    % Extract file name without extension
    [~,NameWithoutExtension]=fileparts(FileNameMLX);
    % delete temporary mlx file
    delete(FileNameMLX);
    % Call to pdfprotect with all default options
    % encrypt and protect a file revoking all authorizations to copy and
    % print.
    pdfprotect(NameWithoutExtension);
    disp('File named "tmptmpENC.pdf" has been created')
    disp('in the current folder. In this file editing and printing is disabled')
    disp('Original input file tmptmp.pdf, on the other hand, is not protected')

  • Example with watermark option.
  • Encrypt and protect a file revoking all authorizations to copy and print and add a custom watermark to each page of the manuscript.

    % Create pdf file tmptmpENC.pdf 
    % create .m file==> transform to mlx ==> export to pdf
    FileName='addFSDA2path.m';
    FileNameMLX='tmptmp.mlx';
    matlab.internal.liveeditor.openAndSave(which(FileName),FileNameMLX);
    % Create file tmptmp.pdf
    export(FileNameMLX);
    % Extract file name without extension
    [~,NameWithoutExtension]=fileparts(FileNameMLX);
    % delete temporary mlx file
    delete(FileNameMLX);
    % Call to pdfprotect with all default options
    % encrypt and protect a file revoking all authorizations to copy and
    % print.
    pdfprotect(NameWithoutExtension,'watermark','Secret');
    disp('File named "tmptmpENC.pdf" has been created')
    disp('in the current folder. In this file editing and printing is disabled')
    disp('and a watermark with text "Secret" has been added')
    disp('Original input file tmptmp.pdf, on the other hand, is not protected')
    File named "tmptmpENC.pdf" has been created
    in the current folder. In this file editing and printing is disabled
    Original input file tmptmp.pdf, on the other hand, is not protected
    

    Related Examples

    expand all

  • Example with watermark and print option.
  • %% Example with watermark and print option.
    % Encrypt and protect a file revoking copy and paste authorizations but
    % allow manuscript printing and add a custom watermark to each page of 
    % the manuscript.
    % Create pdf file tmptmpENC.pdf 
    % create .m file==> transform to mlx ==> export to pdf
    FileName='addFSDA2path.m';
    FileNameMLX='tmptmp.mlx';
    matlab.internal.liveeditor.openAndSave(which(FileName),FileNameMLX);
    % Create file tmptmp.pdf
    export(FileNameMLX);
    % Extract file name without extension
    [~,NameWithoutExtension]=fileparts(FileNameMLX);
    % delete temporary mlx file
    delete(FileNameMLX);
    % Call to pdfprotect with all default options
    % encrypt and protect a file revoking all authorizations to copy and
    % print.
    pdfprotect(NameWithoutExtension,'watermark','FSDA_Toolbox','print',true);
    disp('Files named "tmptmpENC.pdf" has been created')
    disp('in the current folder. In this file editing is disabled')
    disp('printing is allowed and a watermark with text "FSDA_Toolbox" has been added')
    disp('Original input file tmptmp.pdf, on the other hand, is not protected')
    File named "tmptmpENC.pdf" has been created
    in the current folder. In this file editing and printing is disabled
    and a watermark with text "Secret" has been added
    Original input file tmptmp.pdf, on the other hand, is not protected
    

  • Example with personalized passwords and name of output file.
  • %% Example with personalized passwords and name of output file.
    % Encrypt and protect a file
    % revoking copy, paste and print authorizations add a custom watermark
    % to each page of the manuscript, specify the edit password and read
    % password as well. Also specify name of output file
    % Create pdf file tmptmpENC.pdf 
    % create .m file==> transform to mlx ==> export to pdf
    FileName='addFSDA2path.m';
    FileNameMLX='tmptmp.mlx';
    matlab.internal.liveeditor.openAndSave(which(FileName),FileNameMLX);
    % Create file tmptmp.pdf
    export(FileNameMLX);
    % Extract file name without extension
    [~,NameWithoutExtension]=fileparts(FileNameMLX);
    % delete temporary mlx file
    delete(FileNameMLX);
    % Call to pdfprotect with options passedit, 
    % passopen and outputfile
    pdfprotect(NameWithoutExtension,'outputfile', ...
    'mypdfENC', 'passedit','FSDA', 'passopen','easyguess')
    disp('File named "mypdfENC.pdf" has been created')
    disp('in the current folder. In this file editing is disabled')
    disp('printing is disabled. There is also a pwd to open the file.')
    disp('Original input file tmptmp.pdf, on the other hand, is not protected')
    ans =
    
         0
    
    File named "mypdfENC.pdf" has been created
    in the current folder. In this file editing is disabled
    printing is disabled. There is also a pwd to open the file.
    Original input file tmptmp.pdf, on the other hand, is not protected
    

    Input Arguments

    expand all

    inputfile — Input pdf file. String scalar | Character vector.

    Input pdf file specified as a char vector is the original file to be encrypted protected.

    Can be specified with or without extension.

    Data Types: char or string

    Name-Value Pair Arguments

    Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

    Example: 'edit', false , 'outputfile','myoutputfile.pdf' , 'passedit', 'MyPassword1' , 'passread', 'MyPassword2' , 'print', true , 'watermark', '(C)FSDA toolbox'

    edit —edit permission flag.boolean.

    This flag controls the user permission to edit and copy any content of the document, can be either true or false. The default value of edit is false, that is you cannot edit the file.

    Example: 'edit', false

    Data Types: boolean

    outputfile —name of the outputfile.string scalar | Character vector.

    Name of the pdf file to be encrypted, password protected and permission edited. Can be specified with or without extension.

    Default value is inpufileENC.pdf that is we append the suffix ENC to the inputfilename

    Example: 'outputfile','myoutputfile.pdf'

    Data Types: char or string

    passedit —owner encryption password.string scalar | Character vector.

    If the password is set you need to supply the password to modify and print the document.

    The default password is 'FSDA'.

    Example: 'passedit', 'MyPassword1'

    Data Types: char or string

    passopen —user password.string scalar | Character vector.

    If the password is set you need to supply the password to view the document.

    If this option is not specified the password to open the file is not set.

    Example: 'passread', 'MyPassword2'

    Data Types: char or string

    print —print permission flag.boolean.

    This flag controls the user permission to print the document, can be either true (allow) or false (deny).

    The default value of print is false.

    Example: 'print', true

    Data Types: boolean

    watermark —text of the watermark.string scalar | Character vector.

    The text that will be printed diagonally in grey and in a big size font (85 points) on each page of the manuscript. The default value fo the watermark is '' that is no watermark is added.

    Example: 'watermark', '(C)FSDA toolbox'

    Data Types: char or string

    Output Arguments

    expand all

    out —return status. Scalar

    Returns the status of calling the python pdf protectiong function, -1 indicates failure.

    References

    See Also

    This page has been automatically generated by our routine publishFS