Available for: UI for ASP.NET MVC | UI for ASP.NET AJAX | UI for Blazor | UI for WPF | UI for WinForms | UI for Silverlight | UI for Xamarin | UI for WinUI | UI for ASP.NET Core | UI for .NET MAUI

New to Telerik Document Processing? Download free 30-day trial

Settings

PdfFormatProvider provides you with the ability to import/export PDF documents. Additionally, you can take advantage of the import/export settings that give you modification options.

Import Settings

You can specify the import settings you wish through the ImportSettings property of PdfFormatProvider.The available import settings are listed below:

ReadingMode

Gets or sets the mode for loading the document pages content on import.

  • ReadAllAtOnce: All document pages content will be loaded on import. This is the default behavior.
  • OnDemand: The document pages content will be loaded on demand. This mode is made for using with PdfViewers and only the currently visible page will be loaded.

Currently, the OnDemand mode should be applied for use with viewers only.

This property is available since R2 2020.

CopyStream

Gets or sets whether to copy the document stream on import. When false and ReadingMode is OnDemand, the original stream must be kept open while the document is in use. When true, the original stream can be disposed after import, regardless of the reading mode.

UserPasswordNeeded

The event is fired when a user password is needed to open the document. The password can be specified in the PasswordNeededEventArgs.Password property.

Example 1 shows how you can create a PdfImportSettings object and assign it to a PdfFormatProvider.

Example 1: Import settings with UserPasswordNeeded

PdfFormatProvider provider = new PdfFormatProvider(); 
PdfImportSettings settings = new PdfImportSettings(); 
settings.UserPasswordNeeded += (s, a) => 
{ 
    a.Password = "Us3rP4ssw0rd"; 
}; 
 
provider.ImportSettings = settings; 

OwnerPasswordNeeded

The event is fired when an owner password is needed to open the document. The password can be specified in the PasswordNeededEventArgs.Password property.

Example 2: Import settings with OwnerPasswordNeeded

PdfFormatProvider provider = new PdfFormatProvider(); 
PdfImportSettings settings = new PdfImportSettings(); 
settings.OwnerPasswordNeeded += (s, a) => 
{ 
    a.Password = "Own3erP4ssw0rd"; 
}; 
 
provider.ImportSettings = settings; 

DuplicatedEmbeddedFileNameResolving

The event is fired when trying to resolve conflicts between the embedded file names with the same names.

Example 3: Import settings with DuplicatedEmbeddedFileNameResolving

        PdfFormatProvider provider = new PdfFormatProvider(); 
        PdfImportSettings importSettings = new PdfImportSettings(); 
        importSettings.DuplicatedEmbeddedFileNameResolving += (s, a) => 
        { 
            string myNewName = "2_" + a.Name; 
            if (!a.UsedNames.Contains(myNewName)) 
            { 
                a.NewName = myNewName; 
            } 
        }; 
 
        provider.ImportSettings = importSettings;    

Export Settings

In order to modify the way content is exported, you can set the ExportSettings property of PdfFormatProvider. These are the modification options you can use:

StripJavaScriptActions

As of Q4 2024 RadPdfProcessing provides support for Javascript Actions. The StripJavaScriptActions property specifies if the PDF document should strip JavaScript actions on export.

ShouldEmbedFonts (obsolete)

This property controls if the fonts will be embedded in the file. The default value is true because by the PDF Standard the fonts should be embedded in the file. This means that by default the fonts are added which allows proper viewing on any device. If the fonts are not embedded and the file is viewed on a device that does not have the used fronts the font might be substituted. If the font is embedded in the PDF file, it ensures the most predictable and dependable results.

As of Q2 2024 the ShouldEmbedFonts property is obsolete. Use the FontEmbeddingType property instead.

FontEmbeddingType

The property controls what part of the fonts will be embedded in the file offering the following options:

  • None - Does not embed fonts.
  • Full - Fully embeds fonts.
  • Subset - Embeds only the used characters subset of the fonts. This is the default approach.

The subset export option is currently implemented only for TrueType fonts (.ttf).

The receiver of a PDF document must have the same fonts that were originally used to create it. If a different font is substituted, its character set, glyph shapes, and metrics may differ from those in the original font. This substitution can produce unexpected and unwanted results, such as lines of text extending into margins or overlapping with graphics. A PDF file can refer by name to fonts that are not embedded in the PDF file. In this case, a PDF consumer can use those fonts if they are available in its environment. This approach suffers from the uncertainties noted above.

IsEncrypted

This property specifies if the document should be encrypted. The default value is False. You can specify the encryption algorithm by setting the EncryptionType property. The supported values are AES256 and RC4

All passwords for revision 6 (AES-256) shall be based on Unicode. Preprocessing of a user-provided password consists first of normalizing its representation by applying the "SASLPrep" profile (Internet RFC 4013) of the "stringprep" algorithm (Internet RFC 3454) to the supplied password using the Normalize and BiDi options.

This setting is ignored when ComplianceLevel differs from None as PDF/A compliant documents do not allow encryption.

UserPassword

The password to be used if the document is encrypted. The default password is an empty string.

OwnerPassword

The password that governs permissions for operations such as printing, copying and modifying the document. The default password is an empty string.

UserAccessPermissions

This property specifies three types of user access permissions: PrintingPermissionType, ChangingPermissionType, and CopyingPermissionType. These settings are exported only if the PdfExportSettings.IsEncrypted property is set to true. Each has an available set of values, represented by the respective enumerations:

  • PrintingPermissionType: Sets the permissions for document printing. Possible values:

    • None: Specify no printing is allowed.
    • LowResolution: Specify low resolution (150 dpi) printing is allowed.
    • HighResolution: Specify printing on the highest resolution is allowed.
  • ChangingPermissionType: Sets the permissions for making changes to the document. Possible values:

    • None: Specify no document changes are allowed.
    • DocumentAssembly: Specify inserting, deleting, and rotating page changes are allowed.
    • FormFieldFillingOrSigning: Specify filling in form fields and signing existing signature fields changes are allowed.
    • FormFieldFillingOrSigningAndCommenting: Specify commenting, filling in form fields, and signing existing signature fields changes are allowed.
    • AnyExceptExtractingPages: Specify any changes except extracting pages are allowed.
  • CopyingPermissionType: Sets the permissions for document copying. Possible values:

    • None: Specify no copying is allowed.
    • Copying: Specify copying is allowed.
    • TextAccess: Specify that text access for screen reader devices for copying is allowed.
    • NumberingFieldsPrecisionLevel: Represents precision level when updating numbering fields. When the Normal option is selected the fields are updated once, not taking into account if their new values would have shifted the already measured layout. In such cases, the results could be outdated. This is the MS Word-like behavior. If you need more accurate results, use NumberingFieldsPrecisionLevel.High where the fields are updated until their values become more accurate. This precision level is more accurate than NumberingFieldsPrecisionLevel.Normal but requires more resources.

Example 4 shows how you can create a PdfExportSettings object with settings that specify an OwnerPassword and UserAccessPermissions.

Note that the UserAccessPermissions are exported only if the PdfExportSettings.IsEncrypted property is set to true.

Example 4: Export settings

PdfFormatProvider provider = new PdfFormatProvider(); 
PdfExportSettings settings = new PdfExportSettings();  
settings.IsEncrypted = true; 
settings.OwnerPassword = "0wn3rP4ssw0rd"; 
// The following permissions are exported only if the settings.IsEncrypted property is set to true 
UserAccessPermissions permissions = new UserAccessPermissions 
{ 
    Printing = PrintingPermissionType.HighResolution, 
    Changing = ChangingPermissionType.AnyExceptExtractingPages, 
    Copying = CopyingPermissionType.TextAccess, 
}; 
 
settings.UserAccessPermissions = permissions; 
provider.ExportSettings = settings; 

ImageQuality

The ImageQuality property specifies the quality with which images are exported to PDF. More information about how it works is available in this article.

.NET Standard specification does not define APIs for converting images or scaling their quality. That is why to allow the library to export images different than Jpeg and Jpeg2000 or ImageQuality different than High, you will need to provide an implementation of the JpegImageConverterBase abstract class. This implementation should be passed to the JpegImageConverter property of the of FixedExtensibilityManager. For more information check the Cross-Platform Support help article.

ImageCompression

Sets the desired compression for the images when exporting. You can set one of the following values:

  • ImageFilterTypes.Default: The image compression will be preserved as it is in the original document.
  • ImageFilterTypes.None: The images won't be encoded.
  • ImageFilterTypes.FlateDecode: The images will be encoded with a FlateDecode filter. Compresses data using the zlib/deflate compression method.
  • ImageFilterTypes.DCTDecode: The images will be encoded with a DCTDecode filter. Compresses data using a DCT (discrete cosine transform) technique based on the JPEG standard.

Example 5 shows how you can create a PdfExportSettings object with settings for the image properties.

Example 5: Image settings

PdfFormatProvider provider = new PdfFormatProvider(); 
PdfExportSettings settings = new PdfExportSettings(); 
settings.ImageCompression = new ImageFilterTypes[] { ImageFilterTypes.FlateDecode }; 
settings.ImageQuality = ImageQuality.Medium; 

provider.ExportSettings = settings;

StreamCompression

Gets or sets the content stream compression type. Possible Values are:

  • None: The content streams won't be encoded.
  • FlateDecode: Compresses data using the zlib/deflate compression method.

ComplianceLevel

Specifies the PDF/A compliance level. It can have one of the following values:

  • None: Specify no compliance level.
  • PdfA1B: Specify PDF/A-1b compliance level.
  • PdfA2B: Specify PDF/A-2b compliance level.
  • PdfA2U: Specify PDF/A-2u compliance level.
  • PdfA3B: Specify PDF/A-3b compliance level.
  • PdfA3U: Specify PDF/A-3u compliance level.

The default value is None. For more information on PDF/A compliance, check the PDF/A Compliance article.

Example 6 shows how you can create a PdfExportSettings object and assign it to a PdfFormatProvider.

Example 6: Export settings

PdfFormatProvider provider = new PdfFormatProvider(); 
PdfExportSettings settings = new PdfExportSettings();  
settings.ComplianceLevel = PdfComplianceLevel.PdfA2B; 
provider.ExportSettings = settings; 

See Also

In this article