Example #1
0
        public void WordToPDF(String from, String to)
        {
            try
            {
                Document doc = new Document(from);
                //保存为PDF文件,此处的SaveFormat支持很多种格式,如图片,epub,rtf 等等

                //权限这块的设置成不可复制
                PdfSaveOptions saveOptions = new PdfSaveOptions();
                // Create encryption details and set owner password.
                PdfEncryptionDetails encryptionDetails = new PdfEncryptionDetails(string.Empty, "password", PdfEncryptionAlgorithm.RC4_128);
                // Start by disallowing all permissions.
                encryptionDetails.Permissions = PdfPermissions.DisallowAll;
                // Extend permissions to allow editing or modifying annotations.
                encryptionDetails.Permissions = PdfPermissions.ModifyAnnotations | PdfPermissions.DocumentAssembly;
                saveOptions.EncryptionDetails = encryptionDetails;
                // Render the document to PDF format with the specified permissions.
                doc.Save(to, saveOptions);

                //doc.Save(to, SaveFormat.Pdf);
                Console.WriteLine("成功!");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Console.WriteLine("强行报错!");
            }
        }
        public void SetPdfEncryptionPermissions()
        {
            //ExStart
            //ExFor:PdfEncryptionDetails.#ctor
            //ExFor:PdfSaveOptions.EncryptionDetails
            //ExFor:PdfEncryptionDetails.Permissions
            //ExFor:PdfEncryptionAlgorithm
            //ExFor:PdfPermissions
            //ExFor:PdfEncryptionDetails
            //ExSummary:Demonstrates how to set permissions on a PDF document generated by Aspose.Words.
            Document doc = new Document(MyDir + "Rendering.doc");

            PdfSaveOptions saveOptions = new PdfSaveOptions();

            // Create encryption details and set owner password.
            PdfEncryptionDetails encryptionDetails = new PdfEncryptionDetails(string.Empty, "password", PdfEncryptionAlgorithm.RC4_128);

            // Start by disallowing all permissions.
            encryptionDetails.Permissions = PdfPermissions.DisallowAll;

            // Extend permissions to allow editing or modifying annotations.
            encryptionDetails.Permissions = PdfPermissions.ModifyAnnotations | PdfPermissions.DocumentAssembly;
            saveOptions.EncryptionDetails = encryptionDetails;

            // Render the document to PDF format with the specified permissions.
            doc.Save(MyDir + @"\Artifacts\Rendering.SpecifyPermissions.pdf", saveOptions);
            //ExEnd
        }
Example #3
0
        public static void Run()
        {
            // ExStart:UsePDFSaveOptions
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_LoadSaveConvert();

            // Call the diagram constructor to load diagram from a VSDX file
            Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx");

            // Options when saving a diagram into the PDF format
            PdfSaveOptions options = new PdfSaveOptions();

            // Discard saving background pages of the Visio diagram
            options.SaveForegroundPagesOnly = true;

            // Specify the quality of JPEG compression for images (if JPEG compression is used). Default is 95.
            options.JpegQuality = 100;

            // Specify default font name
            options.DefaultFont = "Arial";

            // Conformance level for generated PDF document.
            options.Compliance = PdfCompliance.Pdf15;

            // Load the certificate from disk.
            // The other constructor overloads can be used to load certificates from different locations.
            X509Certificate2 cert = new X509Certificate2(dataDir + "certificate.pfx", "feyb4lgcfbme");

            // Sets a digital signature details. If not set, then no signing will be performed.
            options.DigitalSignatureDetails = new PdfDigitalSignatureDetails(cert, "Test Signing", "Aspose Office", DateTime.Now, PdfDigitalSignatureHashAlgorithm.Sha512);

            // Set encription details
            PdfEncryptionDetails encriptionDetails = new PdfEncryptionDetails("user password", "Owner Password", PdfEncryptionAlgorithm.RC4_128);

            options.EncryptionDetails = encriptionDetails;
            // Sets the number of pages to render in PDF.
            options.PageCount = 2;
            // Sets the 0-based index of the first page to render. Default is 0.
            options.PageIndex = 0;

            // Set page size
            PageSize pgSize = new PageSize(PaperSizeFormat.A1);

            options.PageSize = pgSize;
            // Save in any supported file format
            diagram.Save(dataDir + "UsePDFSaveOptions_out.pdf", options);
            // ExEnd:UsePDFSaveOptions
        }
        public static void Run()
        {
            // ExStart:UsePDFSaveOptions
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_LoadSaveConvert();

            // Call the diagram constructor to load diagram from a VSDX file
            Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx");

            // Options when saving a diagram into the PDF format
            PdfSaveOptions options = new PdfSaveOptions();

            // Discard saving background pages of the Visio diagram
            options.SaveForegroundPagesOnly = true;

            // Specify the quality of JPEG compression for images (if JPEG compression is used). Default is 95.
            options.JpegQuality = 100;

            // Specify default font name
            options.DefaultFont = "Arial";

            // Conformance level for generated PDF document.
            options.Compliance = PdfCompliance.Pdf15;

            // Load the certificate from disk.
            // The other constructor overloads can be used to load certificates from different locations.
            X509Certificate2 cert = new X509Certificate2(dataDir + "certificate.pfx", "feyb4lgcfbme");
            // Sets a digital signature details. If not set, then no signing will be performed.
            options.DigitalSignatureDetails = new PdfDigitalSignatureDetails(cert, "Test Signing", "Aspose Office", DateTime.Now, PdfDigitalSignatureHashAlgorithm.Sha512);

            // Set encription details
            PdfEncryptionDetails encriptionDetails = new PdfEncryptionDetails("user password", "Owner Password", PdfEncryptionAlgorithm.RC4_128);
            options.EncryptionDetails = encriptionDetails;
            // Sets the number of pages to render in PDF.
            options.PageCount = 2;
            // Sets the 0-based index of the first page to render. Default is 0.
            options.PageIndex = 0;

            // Set page size
            PageSize pgSize = new PageSize(PaperSizeFormat.A1);
            options.PageSize = pgSize;
            // Save in any supported file format
            diagram.Save(dataDir + "UsePDFSaveOptions_out.pdf", options);
            // ExEnd:UsePDFSaveOptions
        }
        public void WorkWithPdfEncryptionDetails()
        {
            // ExStart
            // ExFor: PdfEncryptionDetails
            // ExFor: PdfEncryptionDetails.#ctor(String,String,PdfEncryptionAlgorithm)
            // ExFor: PdfEncryptionDetails.EncryptionAlgorithm
            // ExFor: PdfEncryptionDetails.OwnerPassword
            // ExFor: PdfEncryptionDetails.Permissions
            // ExFor: PdfEncryptionDetails.UserPassword
            // ExFor: PdfPermissions
            // ExFor: PdfEncryptionAlgorithm
            // ExSummary: Shows how to use specify PDF encryption details while saving a project as PDF file.
            var project = new Project(DataDir + "CreateProject2.mpp");

            // lets specify encryption details
            var encryptionDetails = new PdfEncryptionDetails(
                // specify user password
                "userPassword",
                // specify owner password
                "ownerPassword",
                // specify encryption algorithm
                PdfEncryptionAlgorithm.RC4_128);

            // specify permissions
            encryptionDetails.Permissions = PdfPermissions.ModifyContents | PdfPermissions.ModifyAnnotations;

            // show user and owner passwords
            Console.WriteLine("User Password: "******"Owner Password: "******"Encryption Algorithm: " + encryptionDetails.EncryptionAlgorithm);
            Console.WriteLine("Permissions: " + encryptionDetails.Permissions);

            var options = new PdfSaveOptions
            {
                EncryptionDetails = encryptionDetails
            };

            // save the project with specified encryption details
            project.Save(OutDir + "WorkWithPdfEncryptionDetails_out.pdf", options);

            // ExEnd
        }
Example #6
0
        public void ExeclToPDF(String from, String to)
        {
            try
            {
                Aspose.Cells.Workbook       xls           = new Aspose.Cells.Workbook(from);
                Aspose.Cells.PdfSaveOptions xlsSaveOption = new Aspose.Cells.PdfSaveOptions();
                xlsSaveOption.SecurityOptions = new Aspose.Cells.Rendering.PdfSecurity.PdfSecurityOptions();
                #region pdf 加密
                //Set the user password
                //PDF加密功能
                //xlsSaveOption.SecurityOptions.UserPassword = "******";
                //Set the owner password
                //xlsSaveOption.SecurityOptions.OwnerPassword = "******";
                #endregion
                //Disable extracting content permission
                xlsSaveOption.SecurityOptions.ExtractContentPermission = false;
                //Disable print permission
                xlsSaveOption.SecurityOptions.PrintPermission = false;
                xlsSaveOption.AllColumnsInOnePagePerSheet     = true;

                //权限这块的设置成不可复制
                PdfSaveOptions saveOptions = new PdfSaveOptions();
                // Create encryption details and set owner password.
                PdfEncryptionDetails encryptionDetails = new PdfEncryptionDetails(string.Empty, "password", PdfEncryptionAlgorithm.RC4_128);
                // Start by disallowing all permissions.
                encryptionDetails.Permissions = PdfPermissions.DisallowAll;
                // Extend permissions to allow editing or modifying annotations.
                encryptionDetails.Permissions = PdfPermissions.ModifyAnnotations | PdfPermissions.DocumentAssembly;
                saveOptions.EncryptionDetails = encryptionDetails;
                // Render the document to PDF format with the specified permissions.
                //doc.Save(to, saveOptions);

                xls.Save(to, xlsSaveOption);

                Console.WriteLine("转换成功!");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Console.WriteLine("强行报错!");
            }
        }
Example #7
0
        protected void DealDoc(Document doc)
        {
            if (m_waterMarkText != null)
            {
                InsertWatermarkText(doc);
            }
            else if (m_waterMarkMultiText != null)
            {
                InsertWatermarkMultiText(doc);
            }
            PdfSaveOptions saveOption = new PdfSaveOptions();

            saveOption.SaveFormat = Aspose.Words.SaveFormat.Pdf;
            PdfEncryptionDetails encryptionDetails = new PdfEncryptionDetails(string.Empty, "PasswordHere", PdfEncryptionAlgorithm.RC4_128);

            encryptionDetails.Permissions = (PdfPermissions)PdfPermission;

            saveOption.EncryptionDetails = encryptionDetails;
            m_pdfSaveOptions             = saveOption;
            var ms = new MemoryStream();
        }
        public static void LoadEncryptedPdfUsingPlugin()
        {
            Document        doc     = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            builder.Writeln("Hello world! This is an encrypted PDF document.");

            // Configure a SaveOptions object to encrypt this PDF document while saving it to the local file system.
            PdfEncryptionDetails encryptionDetails =
                new PdfEncryptionDetails("MyPassword", string.Empty, PdfEncryptionAlgorithm.RC4_128);

            Assert.AreEqual(PdfPermissions.DisallowAll, encryptionDetails.Permissions);

            PdfSaveOptions saveOptions = new PdfSaveOptions();

            saveOptions.EncryptionDetails = encryptionDetails;

            doc.Save(ArtifactsDir + "PDF2Word.LoadEncryptedPdfUsingPlugin.pdf", saveOptions);

            Document pdfDoc = new Document();

            // To load a password encrypted document, we need to pass a LoadOptions object
            // with the correct password stored in its "Password" property.
            LoadOptions loadOptions = new LoadOptions();

            loadOptions.Password = "******";

            Aspose.Words.Pdf2Word.PdfDocumentReaderPlugin pdf2Word = new Aspose.Words.Pdf2Word.PdfDocumentReaderPlugin();
            using (FileStream stream =
                       new FileStream(ArtifactsDir + "PDF2Word.LoadEncryptedPdfUsingPlugin.pdf", FileMode.Open))
            {
                // Pass the LoadOptions object into the Pdf2Word plugin's "Read" method
                // the same way we would pass it into a document's "Load" method.
                pdf2Word.Read(stream, new LoadOptions("MyPassword"), pdfDoc);
            }

            Assert.AreEqual("Hello world! This is an encrypted PDF document.",
                            pdfDoc.GetText().Trim());
        }
        public void WorkWithEncryptionDetails()
        {
            // ExStart
            // ExFor: PdfSaveOptions.EncryptionDetails
            // ExSummary: Shows how to set a encryption details of PDF document. If not set, then no encryption will be performed.
            var project = new Project(DataDir + "EstimatedMilestoneTasks.mpp");

            var encryptionDetails = new PdfEncryptionDetails("userPassword", "ownerPassword", PdfEncryptionAlgorithm.RC4_128);

            var options = new PdfSaveOptions();

            // set a encryption details of PDF document
            options.EncryptionDetails = encryptionDetails;

            // tune additional properties
            // set the <see cref="P:Aspose.Tasks.Saving.SaveOptions.PresentationFormat" /> in which the document will be saved.
            options.PresentationFormat = PresentationFormat.GanttChart;

            project.Save(OutDir + "WorkWithEncryptionDetails_out.pdf", options);

            // ExEnd
        }
        public void SetPdfEncryptionPermissions()
        {
            //ExStart
            //ExFor:PdfEncryptionDetails.#ctor
            //ExFor:PdfSaveOptions.EncryptionDetails
            //ExFor:PdfEncryptionDetails.Permissions
            //ExFor:PdfEncryptionAlgorithm
            //ExFor:PdfPermissions
            //ExFor:PdfEncryptionDetails
            //ExSummary:Demonstrates how to set permissions on a PDF document generated by Aspose.Words.
            Document doc = new Document(MyDir + "Rendering.doc");

            PdfSaveOptions saveOptions = new PdfSaveOptions();

            // Create encryption details and set owner password.
            PdfEncryptionDetails encryptionDetails = new PdfEncryptionDetails(string.Empty, "password", PdfEncryptionAlgorithm.RC4_128);

            // Start by disallowing all permissions.
            encryptionDetails.Permissions = PdfPermissions.DisallowAll;

            // Extend permissions to allow editing or modifying annotations.
            encryptionDetails.Permissions = PdfPermissions.ModifyAnnotations | PdfPermissions.DocumentAssembly;
            saveOptions.EncryptionDetails = encryptionDetails;

            // Render the document to PDF format with the specified permissions.
            doc.Save(MyDir + "Rendering.SpecifyPermissions Out.pdf", saveOptions);
            //ExEnd
        }