Haru Free PDF Library
Security, Encryption, Compression

Functions

HPDF_STATUS HPDF_SetPassword (HPDF_Doc pdf, const char *owner_password, const char *user_password)
 Sets a password for the document. If the password is set, document contents is encrypted. More...
 
HPDF_STATUS HPDF_SetPermission (HPDF_Doc pdf, HPDF_UINT permission)
 Set the permission flags for the document. More...
 
HPDF_STATUS HPDF_SetEncryptionMode (HPDF_Doc pdf, HPDF_EncryptMode mode, HPDF_UINT key_len)
 Set the encryption mode. As the side effect, ups the version of PDF to 1.4 when the mode is set to HPDF_ENCRYPT_R3. More...
 
HPDF_STATUS HPDF_SetCompressionMode (HPDF_Doc pdf, HPDF_UINT mode)
 Set compression mode. More...
 

Detailed Description

Routines for document security, encription and compression.

Function Documentation

◆ HPDF_SetCompressionMode()

HPDF_STATUS HPDF_SetCompressionMode ( HPDF_Doc  pdf,
HPDF_UINT  mode 
)

Set compression mode.

Parameters
pdfDocument object handle.
modeOne or more of the following values, combined together using binary OR:
Mode Description
HPDF_COMP_NONE No compression
HPDF_COMP_TEXT Compress the contents stream of the page
HPDF_COMP_IMAGE Compress the streams of the image objects.
HPDF_COMP_METADATA Other stream datas (fonts, cmaps and so on) are compressed.
HPDF_COMP_ALL All stream datas are compressed
(combination of HPDF_COMP_TEXT, HPDF_COMP_IMAGE and HPDF_COMP_METADATA).
Returns
HPDF_OK on success, otherwise returns error code and calls error handler.
Error codes
Examples
character_map.c, chfont_demo.c, encoding_list.c, image_demo.c, jpeg_demo.c, jpfont_demo.c, png_demo.c, raw_image_demo.c, text_demo.c, and ttfont_demo_jp.c.

◆ HPDF_SetEncryptionMode()

HPDF_STATUS HPDF_SetEncryptionMode ( HPDF_Doc  pdf,
HPDF_EncryptMode  mode,
HPDF_UINT  key_len 
)

Set the encryption mode. As the side effect, ups the version of PDF to 1.4 when the mode is set to HPDF_ENCRYPT_R3.

Parameters
pdfDocument object handle.
modeOne of the following values:
Mode Description
HPDF_ENCRYPT_R2 Use "Revision 2" algorithm.
key_len automatically set to 5 (40 bits).
HPDF_ENCRYPT_R3 Use "Revision 3" algorithm.
key_len can be 5 (40 bits) to 16 (128bits).
Parameters
key_lenSpecify byte length of encryption key. Only valid for HPDF_ENCRYPT_R3, length between 5 (40 bits) and 16 (128 bits) can be specified.
Returns
HPDF_OK on success, otherwise returns error code and calls error handler.
Error codes
Examples
permission.c.

◆ HPDF_SetPassword()

HPDF_STATUS HPDF_SetPassword ( HPDF_Doc  pdf,
const char *  owner_password,
const char *  user_password 
)

Sets a password for the document. If the password is set, document contents is encrypted.

Parameters
pdfDocument object handle.
owner_passwordOwner password of the document. The owner can change document permission. NULL, zero-length string and the same value as user password are not allowed.
user_passwordUser password of the document. The user_password may be set to NULL or zero-length string.
Returns
HPDF_OK on success, otherwise returns error code and calls error handler.
Error codes
Examples
encryption.c, and permission.c.

◆ HPDF_SetPermission()

HPDF_STATUS HPDF_SetPermission ( HPDF_Doc  pdf,
HPDF_UINT  permission 
)

Set the permission flags for the document.

Parameters
pdfDocument object handle.
permissionOne or more of the following values, combined together using binary OR:
Permission Description
HPDF_ENABLE_READ User can read the document.
HPDF_ENABLE_PRINT User can print the document.
HPDF_ENABLE_EDIT_ALL User can edit the contents of the document other than annotations and form fields.
HPDF_ENABLE_COPY User can copy the text and the graphics of the document.
HPDF_ENABLE_EDIT User can add or modify the annotations and form fields of the document.
Returns
HPDF_OK on success, otherwise returns error code and calls error handler.
Error codes
Examples
permission.c.