Jump to content

Extract attached files from pdf


Go to solution Solved by bdr529,

Recommended Posts

  • 1 month later...
#include <String.au3>
#include <array.au3>
#Include "ZLIB.au3" ; https://www.autoitscript.com/forum/topic/128962-zlib-deflateinflategzip-udf/page/2/#comments

Extract_Embedded_Files_from_PDF_Documents()
    
func Extract_Embedded_Files_from_PDF_Documents()
    dim $fileopendialog = FileOpenDialog("","", "Pdf(*.pdf)")
    if @error then return seterror (1,"","")
    dim $file = FileOpen($fileopendialog,16)
    dim $chars_binary=fileread($file)
    FileClose($file)
    dim $chars_string=BinaryToString($chars_binary)
    dim $array_0[0][2]
    dim $array_1[0][2]
    dim $stringsplit=stringsplit($chars_string,"endobj",1+2)
    for $a=0 to ubound($stringsplit)-1
        $stringsplit[$a]=stringreplace($stringsplit[$a],chr(10),"",1)
        if stringleft($stringsplit[$a],2)="3 " then
            dim $_StringBetween_obj=_StringBetween($stringsplit[$a],"3 0 obj","")
            if not @error Then
                dim $_StringBetween_stream=_StringBetween($_StringBetween_obj[0],"stream"&@lf,@lf&"endstream")
                Dim $Decompressed = _ZLIB_Uncompress($_StringBetween_stream[0])
                $chars_string=BinaryToString($Decompressed)
                dim $_StringBetween=_StringBetween($chars_string,"<<",">>")
                for $b=0 to ubound($_StringBetween)-1
                    dim $cell_0,$cell_1
                    $_StringBetween[$b]=stringreplace($_StringBetween[$b],chr(10),"")
                    if stringleft($_StringBetween[$b],4)="/F (" then
                        dim $_StringBetween_1=_StringBetween($_StringBetween[$b],"(",")")
                        if not @error then $cell_1=$_StringBetween_1[0]
                        dim $_StringBetween_0=_StringBetween($_StringBetween[$b],"<</F "," 0 R")
                        if not @error then $cell_0=$_StringBetween_0[0]
                        dim $aFill[1][2] = [[$cell_0, $cell_1]]
                        _arrayadd($array_1,$aFill)                  
                    endif
                next
            endif       
        endif
        dim $_StringBetween_obj=_StringBetween($stringsplit[$a]," 0 obj"&chr(10)&"<<"&chr(10)&"/DL ","")
        if not @error Then
            dim $checksum=_StringBetween($stringsplit[$a],"/CheckSum (",")"&@lf)
            dim $_StringBetween_stream=_StringBetween($_StringBetween_obj[0],"stream"&@lf,@lf&"endstream")
            if not @error Then
                dim $StringToBinary=StringToBinary ($_StringBetween_stream[0])
                Dim $Decompressed = _ZLIB_Uncompress($StringToBinary)
                $chars_string=BinaryToString($Decompressed)
                dim $StringInStr=StringInStr($stringsplit[$a]," ")
                dim $stringleft=stringleft($stringsplit[$a],$StringInStr-1)
                $stringleft=StringStripWS($stringleft,8)
                dim $aFill[1][2] = [[$stringleft, $chars_string]]
                _arrayadd($array_0,$aFill)
            endif
        endif
    next
    dim $dircreate=$fileopendialog&".Extract_Embedded_Files"
    dim $filecreate=false
    for $i=0 to ubound($array_0)-1
        for $a=0 to ubound($array_1)-1
            if $array_0[$i][0]=$array_1[$a][0] then
                if not FileExists($dircreate) then dircreate($dircreate)
                dim $filewrite = FileOpen($dircreate&"\"&$array_1[$a][1],2+16)
                filewrite($filewrite,$array_0[$i][1])
                fileclose($filewrite)
                $filecreate=true
                continueloop
            endif
        next
    next
    if $filecreate=true then shellexecute($dircreate)
endfunc

 

To community goes all my regards and thanks

Link to comment
Share on other sites

at first: thank you for work. second: no, it didnt work. one document returned 

 ==> Subscript used on non-accessible variable.:
Dim $Decompressed = _ZLIB_Uncompress($_StringBetween_stream[0])
Dim $Decompressed = _ZLIB_Uncompress($_StringBetween_stream^ ERROR 

and the other document seems to be ok but nothing happend.

greets

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...