Talk:Atir Tahir: Difference between revisions
Move pseudo task advertising to users talk page
(Atir Tahir moved page Talk:Atir Tahir to User:Atir Tahir) |
Thundergnat (talk | contribs) (Move pseudo task advertising to users talk page) |
||
Line 1:
== Secure your documents programmatically ==
Things are going '''digital'''. There are outstanding products/tools to pull you into the paperless era. We share information across the companies or anywhere in the form of different file formats. It could be a Spreadsheet, PDF or any other MS Office formats. But the biggest threat is security. Let's understand this with a use-case.
If you have a Word file or PDF and you want to secure it with a password before sharing it to the team, what will you do? Of course, you will protect it using MS Word (using a built-in feature). '''But what if you don't have MS Office or Adobe PDF installed on your machine?'''
There are few APIs/tools that provide facility to secure a lot of file formats. Have a look at the GroupDocs.Merger APIs for Java and .NET platform:
'''.NET Code Snippet'''
<lang C#>string sourceFile = (@"D:/Data/sample.pdf");
string password = "iamironman";
Stream openFile = new FileStream(sourceFile, FileMode.Open);
DocumentResult result = new DocumentHandler().AddPassword(openFile, password);
Stream documentStream = result.Stream;
var fileStream = File.Create(@"D:/Data/Output.pdf");
documentStream.CopyTo(fileStream);
documentStream.Close();</lang>
'''Java Code Snippet'''
<lang java>String sourceFile = "source file";
String password = "spidy";
AddPasswordOptions options = new AddPasswordOptions(FileFormat.Docx, password);
InputStream documentExample = new FileInputStream(sourceFile);
DocumentResult result = new DocumentHandler().addPassword(documentExample, options);
OutputStream documentStream = result.getStream();
ByteArrayOutputStream byteArrayStream = (ByteArrayOutputStream) documentStream;
byte[] bytes = byteArrayStream.toByteArray();
FileOutputStream fos = new FileOutputStream(CommonUtilities.outputPath + fileName);
fos.write(bytes, 0, bytes.length);
fos.close();</lang>
|