Tuesday, June 17, 2014

Protect, Unprotect, Modify Protection of Word Documents in Cloud Using PHP

Microsoft Word password protection is a security feature used to protect documents with a user provided password. Most people use Microsoft Word but sometimes you don’t want everyone to be able to read or modify your documents. There are two options for securing your Word files: either set a password to open the document, or set a password to stop anyone from modifying the document. When a document is protected, the user can make only limited changes, such as adding annotations, making revisions, or completing a form. Even if a document is protected with a password, Aspose.Words does not require the password to open, modify or remove protection from the document. When you use Aspose.Words to protect a document, you have the option of keeping the existing password or specifying a new password. If you need to make sure the document is really protected from changes, consider digitally signing the document. Aspose.Words supports detecting digital signatures for DOC, OOXML and ODT documents. Start a free trial today – all you need is to sign up with Aspose for Cloud service. Once you have signed up, you are ready to try powerful file processing features offered by Aspose for Cloud.
Below are some examples shows how to use protection feature in PHP applications

Protect a Word Document

use Aspose\Cloud\Common\AsposeApp;
use Aspose\Cloud\Common\Product;
use Aspose\Cloud\Common\Utils;
use Aspose\Cloud\Words\Document;

/**** Section 1 ****/
Product::$baseProductUri = 'http://api.aspose.com/v1.1';
AsposeApp::$appSID = "xxxxxxxxxxxxxxxxxxxxxxxx";
AsposeApp::$appKey = "xxxxxxxxxxxxxxxxxxxxxxxx";
AsposeApp::$outPutLocation = getcwd() . "/output/";
/**** End Section 1 ****/

/**** Section 2 ****/
$fileName = "Test.docx";
$password = "123456";
$protectionType = "AllowOnlyComments";

$doc = new Document($fileName);
$result = $doc->protectDocument($password, $protectionType);
/**** End Section 2 ****/


Unprotect a Word Document

use Aspose\Cloud\Common\AsposeApp;
use Aspose\Cloud\Common\Product;
use Aspose\Cloud\Common\Utils;
use Aspose\Cloud\Words\Document;

/**** Section 1 ****/
Product::$baseProductUri = 'http://api.aspose.com/v1.1';
AsposeApp::$appSID = "xxxxxxxxxxxxxxxxxxxxxxxx";
AsposeApp::$appKey = "xxxxxxxxxxxxxxxxxxxxxxxx";
AsposeApp::$outPutLocation = getcwd() . "/output/";
/**** End Section 1 ****/

/**** Section 2 ****/
$fileName = "Test.docx";
$password = "123456";
$protectionType = "NoProtection";

$doc = new Document($fileName);
$result = $doc->unprotectDocument($password, $protectionType);
/**** End Section 2 ****/


Modify Protection of the Word Document 

use Aspose\Cloud\Common\AsposeApp;
use Aspose\Cloud\Common\Product;
use Aspose\Cloud\Common\Utils;
use Aspose\Cloud\Words\Document;

/**** Section 1 ****/
Product::$baseProductUri = 'http://api.aspose.com/v1.1';
AsposeApp::$appSID = "xxxxxxxxxxxxxxxxxxxxxxxx";
AsposeApp::$appKey = "xxxxxxxxxxxxxxxxxxxxxxxx";
AsposeApp::$outPutLocation = getcwd() . "/output/";
/**** End Section 1 ****/

/**** Section 2 ****/
$fileName = "Test.docx";
$oldPassword = "123456";
$newPassword = "123456789";
$protectionType = "AllowOnlyFormFields";

$doc = new Document($fileName);
$result = $doc->updateProtection($oldPassword, $newPassword, $protectionType);
/**** End Section 2 ****/


Overview: Aspose for Cloud

Aspose for Cloud is a cloud-based document generation, conversion and automation platform for developers that offer a unique suite of APIs to work with Word documents, Excel spreadsheets, PowerPoint presentations, PDFs, and email formats and protocols. It supports all features for file processing, document scanning, barcodes creation and recognition, and allows extracting text or images too. You can also work with SaaSpose APIs using REST SDKs that can be called from .NET, Java, PHP and Ruby etc.

No comments:

Post a Comment