in PDF Datei Zusatzinfos speichern

  • Hallo,

    Folgendes Problem:

    Ich habe eine PDF Datei gescannt!
    Diese PDF möchte ich gerne später mit Such-Stichwörtern wiederfinden.

    Wenn mann eine pdf Datei rechts anklickt, erhält man bei den
    Eigenschaften\PDF den Punkt Stichwörter.

    Meine Frage:

    Wäre es irgendwie möglich direkt beim Speichern der Datei...also
    C:\Daten\Mein Doc.pdf
    diese Schlüsselwörter mit zu integrieren?

    Liebe Grüße
    Ilse ;)

  • suche mal nach "Metadaten von PDF ändern" ...
    ich weiß, dass man das mit Adobe Acrobat machen kann!
    programme die das eventuell auch können sind z.B. BeCyPDFMetaEdit, Hexonic PDF Metadata Editor!

    gruß gmmg

  • eine integrierte funktion gibt es da meines wissens nicht!
    ich hätte versucht das ganze über eines der genannten tools mit autoit zu automatisieren!
    vielleicht hat ja jemand noch ne andere lösung ...

    gruß gmmg

  • Mit Autoit gibt es hier ein Beispiel:
    http://www.autoitscript.com/forum/topic/13…sting-pdf-file/

    Es werden im Beispiel ausschließlich vorhandene Eigenschaften bedient.
    Um das zu ändern, ist die If-Abfrage in der Funktion

    [autoit]

    Func _PDF_SetProperties($sFile, $aOld, $aNew)

    [/autoit]

    anzupassen.

    Die Keywords werden mit \r\n in einzelne Zeilen aufgeteilt.

    Hier das Beispiel:

    Spoiler anzeigen
    [autoit]

    ; quelle: http://www.autoitscript.com/forum/topic/13…sting-pdf-file/

    [/autoit] [autoit][/autoit] [autoit]

    #include <Array.au3>;just for display the arrays

    [/autoit] [autoit][/autoit] [autoit]

    _Test()

    [/autoit] [autoit][/autoit] [autoit]

    Func _Test()
    Local $sFile = @ScriptDir & "\DeinPDFDokument.pdf"
    Local $aOldData = _PDF_GetProperties($sFile)
    _ArrayDisplay($aOldData)

    [/autoit] [autoit][/autoit] [autoit]

    Local $aNewData[6][2] = [["Title", "New Title"],["Producer", "New Producer"],["Author", "New Author"],["Creator", "New Creator"],["Subject", "New Subject"],["Keywords", "New keywords"]]

    [/autoit] [autoit][/autoit] [autoit]

    Local $sNewFile = _PDF_SetProperties($sFile, $aOldData, $aNewData)
    Local $aCheck = _PDF_GetProperties($sNewFile)
    _ArrayDisplay($aCheck)
    EndFunc ;==>_Test

    [/autoit] [autoit][/autoit] [autoit]

    Func _PDF_GetProperties($sFile)
    Local $a_Prop[6][2] = [["Title", ""],["Producer", ""],["Author", ""],["Creator", ""],["Subject", ""],["Keywords", ""]]
    Local $hFile = FileOpen($sFile)
    Local $sTxt = FileRead($hFile)
    FileClose($hFile)
    Local $title = StringRegExp($sTxt, "(?i)(/Title) {0,1}\((.*?)\)", 1)
    If @error = 1 Then
    $a_Prop[0][1] = "no match"
    Else
    $a_Prop[0][1] = $title[1]
    EndIf
    Local $producer = StringRegExp($sTxt, "(?i)(/Producer) {0,1}\((.*?)\)", 1)
    If @error = 1 Then
    $a_Prop[1][1] = "no match"
    Else
    $a_Prop[1][1] = $producer[1]
    EndIf
    Local $author = StringRegExp($sTxt, "(?i)(/Author) {0,1}\((.*?)\)", 1)
    If @error = 1 Then
    $a_Prop[2][1] = "no match"
    Else
    $a_Prop[2][1] = $author[1]
    EndIf
    Local $creator = StringRegExp($sTxt, "(?i)(/Creator) {0,1}\((.*?)\)", 1)
    If @error = 1 Then
    $a_Prop[3][1] = "no match"
    Else
    $a_Prop[3][1] = $creator[1]
    EndIf
    Local $subject = StringRegExp($sTxt, "(?i)(/Subject) {0,1}\((.*?)\)", 1)
    If @error = 1 Then
    $a_Prop[4][1] = "no match"
    Else
    $a_Prop[4][1] = $subject[1]
    EndIf
    Local $keywords = StringRegExp($sTxt, "(?i)(/Keywords) {0,1}\((.*?)\)", 1)
    If @error = 1 Then
    $a_Prop[5][1] = "no match"
    Else
    $a_Prop[5][1] = $keywords[1]
    EndIf
    Return $a_Prop
    EndFunc ;==>_PDF_GetProperties

    [/autoit] [autoit][/autoit] [autoit]

    Func _PDF_SetProperties($sFile, $aOld, $aNew)
    Local $hFile = FileOpen($sFile)
    Local $sTxt = FileRead($hFile)
    FileClose($hFile)
    For $i = 0 To UBound($aOld) - 1
    If $aOld[$i][1] <> "no match" Or $aOld[$i][1] <> "" Then
    $sTxt = StringRegExpReplace($sTxt, "(?i)(/" & $aOld[$i][0] & ") {0,1}\((.*?)\)", "/" & $aOld[$i][0] & " (" & $aNew[$i][1] &") ", 1)
    EndIf
    Next
    Local $sFileName = StringRegExpReplace($sFile, ".*\\(.*).{4}", "$1")
    Local $sNewFile = StringReplace($sFile, $sFileName, $sFileName & "_mod.pdf")
    Local $hNew = FileOpen($sNewFile, 18)
    FileWrite($hNew, $sTxt)
    FileClose($hNew)
    Return $sNewFile
    EndFunc ;==>_PDF_SetProperties

    [/autoit]

    Kommt das Deinen Vorstellungen nahe?

  • Hallo,

    danke für deine Hilfe.
    Ich konnte mich gestern leider nicht mehr melden.

    Ich habe das Script mal ausprobiert.
    1. Man kann neue Daten im Script erfassen.
    2. Es wird auch eine neue PDF erzeugt

    Aber die Daten die geändert wurden sind in der neuen pdf nicht enthalten.

    Spoiler anzeigen
    [autoit]


    ; quelle: http://www.autoitscript.com/forum/topic/13…sting-pdf-file/

    [/autoit] [autoit][/autoit] [autoit]

    #include <Array.au3>;just for display the arrays

    [/autoit] [autoit][/autoit] [autoit]

    _Test()

    [/autoit] [autoit][/autoit] [autoit]

    Func _Test()
    Local $sFile = @ScriptDir & "\Meine-PDF.pdf"
    Local $aOldData = _PDF_GetProperties($sFile)
    _ArrayDisplay($aOldData)

    [/autoit] [autoit][/autoit] [autoit]

    Local $aNewData[6][2] = [["Title", "New Title"],["Producer", "New Producer"],["Author", "New Author"],["Creator", "New Creator"],["Subject", "New Subject"],["Keywords", "New keywords"]]

    [/autoit] [autoit][/autoit] [autoit]

    Local $sNewFile = _PDF_SetProperties($sFile, $aOldData, $aNewData)
    Local $aCheck = _PDF_GetProperties($sNewFile)
    _ArrayDisplay($aCheck)
    EndFunc ;==>_Test

    [/autoit] [autoit][/autoit] [autoit]

    Func _PDF_GetProperties($sFile)
    Local $a_Prop[6][2] = [["Title", ""],["Producer", ""],["Author", ""],["Creator", ""],["Subject", ""],["Keywords", ""]]
    Local $hFile = FileOpen($sFile)
    Local $sTxt = FileRead($hFile)
    FileClose($hFile)
    Local $title = StringRegExp($sTxt, "(?i)(/Title) {0,1}\((.*?)\)", 1)
    If @error = 1 Then
    $a_Prop[0][1] = "Ilse PDF Datei"
    Else
    $a_Prop[0][1] = $title[1]
    EndIf
    Local $producer = StringRegExp($sTxt, "(?i)(/Producer) {0,1}\((.*?)\)", 1)
    If @error = 1 Then
    $a_Prop[1][1] = "no match"
    Else
    $a_Prop[1][1] = $producer[1]
    EndIf
    Local $author = StringRegExp($sTxt, "(?i)(/Author) {0,1}\((.*?)\)", 1)
    If @error = 1 Then
    $a_Prop[2][1] = "no match"
    Else
    $a_Prop[2][1] = $author[1]
    EndIf
    Local $creator = StringRegExp($sTxt, "(?i)(/Creator) {0,1}\((.*?)\)", 1)
    If @error = 1 Then
    $a_Prop[3][1] = "no match"
    Else
    $a_Prop[3][1] = $creator[1]
    EndIf
    Local $subject = StringRegExp($sTxt, "(?i)(/Subject) {0,1}\((.*?)\)", 1)
    If @error = 1 Then
    $a_Prop[4][1] = "no match"
    Else
    $a_Prop[4][1] = $subject[1]
    EndIf
    Local $keywords = StringRegExp($sTxt, "(?i)(/Keywords) {0,1}\((.*?)\)", 1)
    If @error = 1 Then
    $a_Prop[5][1] = "no match"
    Else
    $a_Prop[5][1] = $keywords[1]
    EndIf
    Return $a_Prop
    EndFunc ;==>_PDF_GetProperties

    [/autoit] [autoit][/autoit] [autoit]

    Func _PDF_SetProperties($sFile, $aOld, $aNew)
    Local $hFile = FileOpen($sFile)
    Local $sTxt = FileRead($hFile)
    FileClose($hFile)
    For $i = 0 To UBound($aOld) - 1
    If $aOld[$i][1] <> "no match" Or $aOld[$i][1] <> "" Then
    $sTxt = StringRegExpReplace($sTxt, "(?i)(/" & $aOld[$i][0] & ") {0,1}\((.*?)\)", "/" & $aOld[$i][0] & " (" & $aNew[$i][1] &") ", 1)
    EndIf
    Next
    Local $sFileName = StringRegExpReplace($sFile, ".*\\(.*).{4}", "$1")
    Local $sNewFile = StringReplace($sFile, $sFileName, $sFileName & "_mod.pdf")
    Local $hNew = FileOpen($sNewFile, 18)
    FileWrite($hNew, $sTxt)
    FileClose($hNew)
    Return $sNewFile
    EndFunc ;==>_PDF_SetProperties

    [/autoit]

    Ich habe Zeile 8 und Zeile 26 geändert.
    Im Scriptdir Verzeichnis befindet sich meine -pdf.pdf

    Falls es geht,
    kann man es nicht so anpassen, dass keine Kopie gemacht wird
    sondern die Daten direkt in die PDF kommen?

    Ich scanne eine PDF und da müssen die Suchwörter...rein.


    Liebe Grüße
    Ilse ;)


    EDIT:

    Ich habe mal folgendes probiert:

    Ich öffne die Eigenschaften der PDF Datei
    Dann klicke ich auf PDF

    Und dann starte ich diesen Code

    [autoit]


    ControlSetText("Eigen","","[CLASS:Edit; INSTANCE:4]","Rechnung Gebühr")

    [/autoit]

    PROBLEM: Ich kann nicht speichern!!!!

    Einmal editiert, zuletzt von Ilse (11. Februar 2014 um 11:24)

  • War denn der Titel bereits im UrsprungPDF gesetzt?
    Das Beispiel basiert darauf, dass bereits vorhandene Eigenschaften neu gesetzt werden.
    Mit dem Eintrag in Zeile 26 fällst Du in der Funktion (If-Abfrage) raus. Deshalb kann hier nichts geschrieben werden.

    Um in selbiger Datei zu bleiben sind die Zeilen 72-76 anzupassen. Hier einfach den ursprünglichen Dateinamen verwenden und die Datei schreiben.

  • Hallo qwert23,

    schön dass du dich meldest.

    Hab da irgendwie einen Denkfehler.

    Also:

    1. Ich scanne eine Datei.pdf
    2. Wenn ich die Datei z.B. mit Acrobat (Eigenschaften)öffne, dann sind alle Felder leer. Also Titel, Autor Schlüsselwörter...

    3. Ich passe im Script die Daten an: Datei.pdf, Tiel, Keywords...
    4. Ich Sehe die Daten im ArrayDisplay

    Es wird eine _mod.pdf angelegt aber ohne Daten

    Spoiler anzeigen
    [autoit]


    ; quelle: http://www.autoitscript.com/forum/topic/13…sting-pdf-file/

    [/autoit] [autoit][/autoit] [autoit]

    #include <Array.au3>;just for display the arrays

    [/autoit] [autoit][/autoit] [autoit]

    _Test()

    [/autoit] [autoit][/autoit] [autoit]

    Func _Test()
    Local $sFile = @ScriptDir & "\Rechnung.pdf"
    Local $aOldData = _PDF_GetProperties($sFile)
    _ArrayDisplay($aOldData)

    [/autoit] [autoit][/autoit] [autoit]

    Local $aNewData[6][2] = [["Title", "New Title"],["Producer", "New Producer"],["Author", "New Author"],["Creator", "New Creator"],["Subject", "New Subject"],["Keywords", "New keywords"]]

    [/autoit] [autoit][/autoit] [autoit]

    Local $sNewFile = _PDF_SetProperties($sFile, $aOldData, $aNewData)
    Local $aCheck = _PDF_GetProperties($sNewFile)
    _ArrayDisplay($aCheck)
    EndFunc ;==>_Test

    [/autoit] [autoit][/autoit] [autoit]

    Func _PDF_GetProperties($sFile)
    Local $a_Prop[6][2] = [["Title", ""],["Producer", ""],["Author", ""],["Creator", ""],["Subject", ""],["Keywords", ""]]
    Local $hFile = FileOpen($sFile)
    Local $sTxt = FileRead($hFile)
    FileClose($hFile)
    Local $title = StringRegExp($sTxt, "(?i)(/Title) {0,1}\((.*?)\)", 1)
    If @error = 1 Then
    $a_Prop[0][1] = "Ilse PDF Datei"
    Else
    $a_Prop[0][1] = $title[1]
    EndIf
    Local $producer = StringRegExp($sTxt, "(?i)(/Producer) {0,1}\((.*?)\)", 1)
    If @error = 1 Then
    $a_Prop[1][1] = "Ilse"
    Else
    $a_Prop[1][1] = $producer[1]
    EndIf
    Local $author = StringRegExp($sTxt, "(?i)(/Author) {0,1}\((.*?)\)", 1)
    If @error = 1 Then
    $a_Prop[2][1] = "no match"
    Else
    $a_Prop[2][1] = $author[1]
    EndIf
    Local $creator = StringRegExp($sTxt, "(?i)(/Creator) {0,1}\((.*?)\)", 1)
    If @error = 1 Then
    $a_Prop[3][1] = "no match"
    Else
    $a_Prop[3][1] = $creator[1]
    EndIf
    Local $subject = StringRegExp($sTxt, "(?i)(/Subject) {0,1}\((.*?)\)", 1)
    If @error = 1 Then
    $a_Prop[4][1] = "no match"
    Else
    $a_Prop[4][1] = $subject[1]
    EndIf
    Local $keywords = StringRegExp($sTxt, "(?i)(/Keywords) {0,1}\((.*?)\)", 1)
    If @error = 1 Then
    $a_Prop[5][1] = "Gebühr Bescheid Rechnung"
    Else
    $a_Prop[5][1] = $keywords[1]
    EndIf
    Return $a_Prop
    EndFunc ;==>_PDF_GetProperties

    [/autoit] [autoit][/autoit] [autoit]

    Func _PDF_SetProperties($sFile, $aOld, $aNew)
    Local $hFile = FileOpen($sFile)
    Local $sTxt = FileRead($hFile)
    FileClose($hFile)
    For $i = 0 To UBound($aOld) - 1
    If $aOld[$i][1] <> "no match" Or $aOld[$i][1] <> "" Then
    $sTxt = StringRegExpReplace($sTxt, "(?i)(/" & $aOld[$i][0] & ") {0,1}\((.*?)\)", "/" & $aOld[$i][0] & " (" & $aNew[$i][1] &") ", 1)
    EndIf
    Next
    Local $sFileName = StringRegExpReplace($sFile, ".*\\(.*).{4}", "$1")
    Local $sNewFile = StringReplace($sFile, $sFileName, $sFileName & "_mod.pdf")
    Local $hNew = FileOpen($sNewFile, 18)
    FileWrite($hNew, $sTxt)
    FileClose($hNew)
    Return $sNewFile
    EndFunc ;==>_PDF_SetProperties

    [/autoit]


    EDIT Zeile 72 - 76

    [autoit]


    Local $sFileName = StringRegExpReplace($sFile, ".*\\(.*).{4}", "$1")
    Local $sNewFile = StringReplace($sFile, $sFileName, $sFileName & "_mod.pdf")
    Local $hNew = FileOpen($sNewFile, 18)
    FileWrite($hNew, $sTxt)
    FileClose($hNew)

    [/autoit]

    Meine PDF ist leer und hat keine Daten!
    Kannst du mir vielleicht ein Beispiel machen!


    Liebe Grüße
    Ilse ;)

  • Ilse

    also bei mir funktioniert das!

    Spoiler anzeigen
    [autoit]


    #include <Array.au3>;just for display the arrays

    [/autoit] [autoit][/autoit] [autoit]

    _Test()

    [/autoit] [autoit][/autoit] [autoit]

    Func _Test()
    Local $sFile = @ScriptDir & "\Test.pdf"

    [/autoit] [autoit][/autoit] [autoit]

    Local $aOldData = _PDF_GetProperties($sFile)
    _ArrayDisplay($aOldData)

    [/autoit] [autoit][/autoit] [autoit]

    Local $aNewData[6][2] = [["Title", "New Title"],["Producer", "New Producer"],["Author", "New Author"],["Creator", "New Creator"],["Subject", "New Subject"],["Keywords", "New keywords"]]

    [/autoit] [autoit][/autoit] [autoit]

    Local $sNewFile = _PDF_SetProperties($sFile, $aOldData, $aNewData)
    Local $aCheck = _PDF_GetProperties($sNewFile)
    _ArrayDisplay($aCheck)
    EndFunc ;==>_Test

    [/autoit] [autoit][/autoit] [autoit]

    Func _PDF_GetProperties($sFile)
    Local $a_Prop[6][2] = [["Title", ""],["Producer", ""],["Author", ""],["Creator", ""],["Subject", ""],["Keywords", ""]]
    Local $hFile = FileOpen($sFile)
    Local $sTxt = FileRead($hFile)
    FileClose($hFile)
    Local $title = StringRegExp($sTxt, "(?i)(/Title) {0,1}\((.*?)\)", 1)
    If @error = 1 Then
    $a_Prop[0][1] = "no match"
    Else
    $a_Prop[0][1] = $title[1]
    EndIf
    Local $producer = StringRegExp($sTxt, "(?i)(/Producer) {0,1}\((.*?)\)", 1)
    If @error = 1 Then
    $a_Prop[1][1] = "no match"
    Else
    $a_Prop[1][1] = $producer[1]
    EndIf
    Local $author = StringRegExp($sTxt, "(?i)(/Author) {0,1}\((.*?)\)", 1)
    If @error = 1 Then
    $a_Prop[2][1] = "no match"
    Else
    $a_Prop[2][1] = $author[1]
    EndIf
    Local $creator = StringRegExp($sTxt, "(?i)(/Creator) {0,1}\((.*?)\)", 1)
    If @error = 1 Then
    $a_Prop[3][1] = "no match"
    Else
    $a_Prop[3][1] = $creator[1]
    EndIf
    Local $subject = StringRegExp($sTxt, "(?i)(/Subject) {0,1}\((.*?)\)", 1)
    If @error = 1 Then
    $a_Prop[4][1] = "no match"
    Else
    $a_Prop[4][1] = $subject[1]
    EndIf
    Local $keywords = StringRegExp($sTxt, "(?i)(/Keywords) {0,1}\((.*?)\)", 1)
    If @error = 1 Then
    $a_Prop[5][1] = "no match"
    Else
    $a_Prop[5][1] = $keywords[1]
    EndIf
    Return $a_Prop
    EndFunc ;==>_PDF_GetProperties

    [/autoit] [autoit][/autoit] [autoit]

    Func _PDF_SetProperties($sFile, $aOld, $aNew)
    Local $hFile = FileOpen($sFile)
    Local $sTxt = FileRead($hFile)
    FileClose($hFile)
    For $i = 0 To UBound($aOld) - 1
    If $aOld[$i][1] <> "no match" Or $aOld[$i][1] <> "" Then
    $sTxt = StringRegExpReplace($sTxt, "(?i)(/" & $aOld[$i][0] & ") {0,1}\((.*?)\)", "/" & $aOld[$i][0] & " (" & $aNew[$i][1] &") ", 1)
    EndIf
    Next
    Local $sFileName = StringRegExpReplace($sFile, ".*\\(.*).{4}", "$1")
    Local $sNewFile = StringReplace($sFile, $sFileName, $sFileName & "_mod.pdf")
    Local $hNew = FileOpen($sNewFile, 18)
    FileWrite($hNew, $sTxt)
    FileClose($hNew)
    Return $sNewFile
    EndFunc ;==>_PDF_SetProperties

    [/autoit] [autoit][/autoit] [autoit][/autoit]

    die generierte pdf heißt dann in meinem test "Test_mod.pdf.pdf"

    hab die test pdf mal angehangen ...

    gruß gmmg