Encrypt Unprotected PDF with Password using iText in Java

password-encryption-java-itext

In this tutorial we will learn how to use iText API to add password in PDF and how to encrypt existing PDF to write and read data respectively.  While creating password protected PDF, we need to add user password, owner password, permission and encryption type. To encrypt existing PDF with password, iText provides PdfStamper.setEncryption which accepts same arguments as PdfWriter.setEncryption


/**
*
* @author mahsin
*/
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import com.itextpdf.text.pdf.PdfWriter;
public class Main {
public static void main(String[] args) throws FileNotFoundException, DocumentException, IOException {
       PdfReader reader = new PdfReader("C:/PasswordNOTGivenPDF.pdf");
       PdfStamper stamper = new PdfStamper(reader, new FileOutputStream("C:/PDFwithPassword.pdf"));
       stamper.setEncryption("password".getBytes(), "owner_password".getBytes(),PdfWriter.ALLOW_COPY, PdfWriter.ENCRYPTION_AES_256);
       stamper.close();
       reader.close();
       System.out.println("Successfully Done");
}
}
Advertisements

শুরু থেকে সুইফট প্রোগ্রামিং : পর্ব ১

swift-programming-language-part-1

2014 সালে অ্যাপল সুইফট একটি ব্র্যান্ড নতুন প্রোগ্রামিং ভাষা প্রবর্তনের সঙ্গে বিস্ময় দ্বারা ডেভেলপার কমিউনিটি নিয়ে. সুইফট একটি দীর্ঘ পথ আসা হয়েছে, এবং এটা বিশ্বাস করা কঠিন যে ভাষা এই বছর তার তৃতীয় বার্ষিকী উদযাপন করা হয় কঠিন. কয়েক মাস আগে, অ্যাপল সুইফট 3, ভাষার জন্য একটি মাইলফলক মুক্তি. এই সিরিজে, আমি আপনি সুইফট 3 মৌলিক শেখাবো.

সুইফট পরিচিত মতানুযায়ী যদি আপনি উদ্দেশ্য সি ব্যবহার করেছেন iOS বা MacOS অ্যাপ্লিকেশন বিকাশ, কিন্তু গুরুত্বপূর্ণ পার্থক্য একটি সংখ্যা আছে. আমি কি উপায়ে সুইফট উদ্দেশ্য সি থেকে পৃথক এবং কেন যারা পার্থক্য একটি ভাল জিনিস আপনি দেখিয়ে এই সিরিজ বন্ধ পদাঘাত করব. চল শুরু করি.

Heroku-toolbelt installation error in mac OS X Solution

toolbelt

After install heroku toolbelt in mac OS X terminal sometimes it’s showed given error

Terminal Command: 

$ heroku --version
/usr/local/heroku/lib/heroku/jsplugin.rb:108: warning: Insecure world writable dir /usr/local in PATH, mode 040777
heroku-cli: Adding dependencies...
     Get https://cli-assets.heroku.com/node/v5.7.0/node-v5.7.0-darwin-x64.tar.gz: dial tcp: lookup cli-assets.heroku.com on 192.168.192.10:53: cannot unmarshal DNS message
done
heroku-cli: Installing core plugins...
     

     fork/exec bin/node: no such file or directory
heroku-cli: Installing core plugins (retrying)...
     Error installing package. 
     
     Try running again with GODE_DEBUG=info to see more output.

Heroku-toolbelt Mac OS X Ruby On Rails

My OS X version is OS X EI captain so I was follow this instruction To disable System Integrity Protection to solve this problem:

  1.   Boot into the Recovery HD by restarting whilst holding ⌘R.
  2.   Open Terminal (from the Utilities menu).
  3.   Run the following command in Terminal: csrutil disable
  4.   Restart. And change permission to in /usr folder.

Finally Now I am using heroku cmnd properly in my Mac OS.

heroku

How I completely uninstall android studio from my Macbook Pro

studio-hero

Recently I downloaded android studio on my Macbook Pro and I messed up with it every time I can not run emulator gave me some error like HXAM is lost so I decided to remove the whole android studio and re install it by following way at my mac book pro.

maxresdefault

I executed those command form my terminal

rm -Rf /Applications/Android\ Studio.app
rm -Rf ~/Library/Preferences/AndroidStudio*
rm ~/Library/Preferences/com.google.android.studio.plist
rm -Rf ~/Library/Application\ Support/AndroidStudio*
rm -Rf ~/Library/Logs/AndroidStudio*
rm -Rf ~/Library/Caches/AndroidStudio*

I deleted all projects from following command:

rm -Rf ~/AndroidStudioProjects

to remove gradle related files (caches & wrapper) I follow

rm -Rf ~/.gradle

Using the below command to delete all Android Virtual Devices(AVDs) and *.keystore. note: this folder is used by others Android IDE as well, so be careful if we use other IDE we will not remove this folder

rm -Rf ~/.android

to deleting Android SDK tools

rm -Rf ~/Library/Android*

Are PHP Variables passed by value or by reference?

hqdefault

It’s by value according to the PHP Documentation.

By default, function arguments are passed by value (so that if the value of the argument within the function is changed, it does not get changed outside of the function). To allow a function to modify its arguments, they must be passed by reference.

To have an argument to a function always passed by reference, prepend an ampersand (&) to the argument name in the function definition.

<?php
function changeValue(&$var)
{
    $var++;
}

$result=5;
changeValue($result);

echo $result; // $result is 6 here
?>

Continue reading

Nested namespaces in PHP

namespacesIt’s true that “Namespace declarations cannot be nested”.Namespacing is used to avoid conflicting definitions and introduce more flexibility and organization in your code.The brackets surrounding the namespace code block are completely optional.If we want to translate namespace code to run able in php. We can write like:

namespace Foo\Bar;

class X{
    // Your properties
}
class Y {
// Your properties
}

If  need more information you can see this link well written by Elias Zerrouq with example http://code.tutsplus.com/tutorials/namespacing-in-php–net-27203

Mockup

MockUPIn manufacturing and design, a mockup, or mock-up, is a scale or full-size model of a design or device, used for teaching, demonstration, design evaluation, promotion, and other purposes. A mockup is called a prototype if it provides at least part of the functionality of a system and enables testing of a design.

Software Engineering

The most common use of Mockups in software development is to create user interfaces that shows the end user what the software will look like without having to build the software or the underlying functionality. Software UI mockups can range from very simple hand drawn screen layouts, through realistic bitmaps, to semi functional user interfaces developed in a software development tool.

Mockups are often used to create Unit tests – there they are usually called Mock objects. The main reasons to create such mockups is to be able to test one part of a software system (a unit) without having to use dependent modules. The function of these dependencies is then “faked” using mock objects.

This is especially important if the functions that are simulated like this are difficult to obtain (for example because it involves complex computation) or if the result is non-deterministic, such as the readout of a sensor.

Mockup Software can also be used for micro level evaluation, for example to check a single function, and derive results from the tests to enhance the products power and usability on the whole.