Example #1
0
        protected static IDevice GetOutputDevice(ConversionApplicationOptions options, string filePath)
        {
            T ApplyPageSizeIfAny <T>(T renderingOptions)
                where T : RenderingOptions
            {
                if (options.PageSize != null)
                {
                    renderingOptions.PageSetup.AnyPage.Size = options.PageSize;
                }
                return(renderingOptions);
            }

            if (FileFormat.PDF == options.OutputFormat)
            {
                var pdfOptions = new Aspose.Html.Rendering.Pdf.PdfRenderingOptions();
                if (!string.IsNullOrEmpty(options.UserPassword) && !string.IsNullOrEmpty(options.OwnerPassword))
                {
                    const PdfPermissions allPermissions = PdfPermissions.PrintDocument | PdfPermissions.ModifyContent |
                                                          PdfPermissions.ExtractContent | PdfPermissions.ModifyTextAnnotations |
                                                          PdfPermissions.FillForm | PdfPermissions.ExtractContentWithDisabilities |
                                                          PdfPermissions.AssembleDocument | PdfPermissions.PrintingQuality;

                    pdfOptions.Encryption = new Aspose.Html.Rendering.Pdf.Encryption.PdfEncryptionInfo(
                        options.UserPassword,
                        options.OwnerPassword,
                        allPermissions,
                        PdfEncryptionAlgorithm.RC4_128);
                }
                pdfOptions.BackgroundColor = options.BackgroundColor;
                return(new PdfDevice(pdfOptions, filePath));
            }

            if (FileFormat.XPS == options.OutputFormat)
            {
                var xpsOptions = new XpsRenderingOptions();
                xpsOptions = ApplyPageSizeIfAny(xpsOptions);
                return(new XpsDevice(ApplyPageSizeIfAny(xpsOptions), filePath));
            }


            if (FileFormat.JPEG == options.OutputFormat ||
                FileFormat.PNG == options.OutputFormat ||
                FileFormat.BMP == options.OutputFormat ||
                FileFormat.TIFF == options.OutputFormat ||
                FileFormat.GIF == options.OutputFormat)
            {
                var imageOptions = new ImageRenderingOptions(options.OutputFormat.ToImageFormat());
                imageOptions.BackgroundColor = options.BackgroundColor;
                imageOptions = ApplyPageSizeIfAny(imageOptions);
                return(new ImageDevice(imageOptions, filePath));
            }


            throw new ArgumentException("The output format is not supported.", "OutputFormat");
        }
Example #2
0
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        string         userPassword  = "******";
        string         ownerPassword = "";
        PdfPermissions permissions   = PdfPermissions.None;

        var document = DocumentModel.Load("Reading.docx");

        var options = new PdfSaveOptions()
        {
            DocumentOpenPassword = userPassword,
            PermissionsPassword  = ownerPassword,
            Permissions          = permissions
        };

        document.Save("PDF Encryption.pdf", options);
    }
Example #3
0
        private static PdfPublicKeyEncryptionHandler createEncryptionHandler()
        {
            // TODO:
            // Change the constants, or the sample won't work.

            string keyStoreOwner = "key-store-owner.p12";
            string passwordOwner = "password";

            string keyStoreUser = "******";
            string passwordUser = "******";

            // You can also use an X509Certificate2 certificate to construct the handler
            PdfPublicKeyEncryptionHandler handler = new PdfPublicKeyEncryptionHandler(keyStoreOwner, passwordOwner);

            // Add another recipient with non-owner permissions
            PdfPermissions permissions = new PdfPermissions();

            permissions.Flags = PdfPermissionFlags.FillFormFields | PdfPermissionFlags.PrintDocument;
            handler.AddRecipient(keyStoreUser, passwordUser, permissions);

            return(handler);
        }