1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
public class fichier extends Activity {
public static final int CODE_RETOUR = 0;
/** User password. */
public static byte[] USER = "20773779".getBytes();
/** Owner password. */
public static byte[] OWNER = "20773779".getBytes();
private static final int KeyCode = 0;
/**
* Creates a PDF file: hello.pdf
* @param args no arguments needed
*/
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Bundle bundle = getIntent().getExtras();
// String RESULT1 = bundle.getString("RESULT1");
// String RESULT2 = bundle.getString("RESULT2");
fichier metadata = new fichier();
/** The resulting PDF file. */
String RESULT1
= "mnt/sdcard/pdf/COLIVETFT.pdf";
/** The resulting PDF file. */
String RESULT2
= "mnt/sdcard/pdf/123456789COLIVETFT.pdf";
File file1 = new File(RESULT1);
if (file1.exists()) {
Toast.makeText(getApplicationContext(),"existe", Toast.LENGTH_SHORT).show();
}
try {
metadata.decryptPdf(RESULT1, RESULT2);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (DocumentException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
File file = new File(RESULT2);
if (file.exists()) {
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setPackage("com.adobe.reader");
intent.setDataAndType(path, "application/pdf");
// optionnel a toi de voir quel flag tu souhaites
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
startActivity(intent);
}
catch (ActivityNotFoundException e) {
Toast.makeText(fichier.this,
"No Application Available to View PDF",
Toast.LENGTH_SHORT).show();
}
}
}
/**
* Manipulates a PDF file src with the file dest as result
* @param src the original PDF
* @param dest the resulting PDF
* @throws IOException
* @throws DocumentException
*/
public void decryptPdf(String src, String dest) throws IOException, DocumentException {
PdfReader reader = new PdfReader(src, OWNER);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
stamper.close();
}
} |
Partager