Private Static voidParsepdffile (String file)throwsException {fileinputstream fis=Newfileinputstream (file); Pdfparser Pdfparser=Newpdfparser (FIS); Pdfparser.parse (); Cosdocument cosdocument=pdfparser.getdocument (); List<COSObject> objlist =cosdocument.getobjects (); for(Cosobject obj:objlist) {cosbase cosbase=Obj.getitem (Cosname.subtype); if(NULL! = Cosbase && cosbaseinstanceofcosname) {String StrName=cosbase.tostring (); if("Cosname{application/x-shockwave-flash}". Equals (StrName)) {Cosstream Cosstream=cosutils.getasstream (obj, cosdocument); InputStream InputStream=Cosstream.getunfilteredstream (); String Stroutfile= String.Format ("/tmp/%s.swf",NewDate (). GetTime ()); FileOutputStream FileOutputStream=NewFileOutputStream (Stroutfile); byte[] bytes =New byte[10240]; intIread; while(true) {Iread=inputstream.read (bytes); if(Iread <= 0) { Break; } fileoutputstream.write (Bytes,0, Iread); } fileoutputstream.close (); Inputstream.close (); } } }
Extracting a Flash file from a PDF file using PDFBox