Screenshot in PDF einfügen

  • Hi all,

    da es doch nicht so funktioniert, wie ich es mir vorgestellt hatte und ich sowieso schon wieder viel zu lange damit rumspiele, schreib ich jetz mal was :)

    Ich möchte einen Screenshot eines Formular einer MS Access Datenbank machen und diesen in ein PDF einfügen.

    Screenshot erzeugen, speichern und einfügen funktioniert auch, allerdings ist dann die Skalierung total im ***. Hab nun rausgefunden, dass wenn ich den Screenshot vorher um 90° drehe, dann einfüge und wieder zurückdrehe, die Skalierung einwandfrei ist. Gibts da nicht eine andere Möglichkeit?

    Das Script bis jetzt:

    Spoiler anzeigen
    [autoit]


    #include <date.au3>
    #include <GDIPlus.au3>
    #include <MPDF_UDF.au3>
    #include <screencapture.au3>

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

    WinActivate("PDF-Formular")
    screencap()

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

    Func screencap()

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

    If FileExists(@ScriptDir & "\Image2PDF.pdf") Then FileDelete(@ScriptDir & "\Image2PDF.pdf")

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

    $now = StringReplace(_Now(), ":", "_")
    $now = StringReplace($now, ".", "_")
    $now = StringReplace($now, " ", "_")
    $now = StringReplace($now, ",", "_")
    $rnd = Random(1, 9999, 1)
    $var = @DesktopDir & "\Screens\DB_" & @UserName & "_" & $now & "_" & $rnd & ".jpg"

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

    $pic = _ScreenCapture_Capture("")
    _ScreenCapture_SaveImage($var, $pic)

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

    ;bild drehen
    ;~ _GDIPlus_Startup()
    ;~ $hImage = _GDIPlus_ImageLoadFromFile($var)
    ;~ $sCLSID = _GDIPlus_EncodersGetCLSID("JPG")
    ;~ $tData = DllStructCreate("int Data")
    ;~ DllStructSetData($tData, "Data", $GDIP_EVTTRANSFORMROTATE90)
    ;~ $tParams = _GDIPlus_ParamInit(1)
    ;~ _GDIPlus_ParamAdd($tParams, $GDIP_EPGTRANSFORMATION, 1, $GDIP_EPTLONG, DllStructGetPtr($tData, "Data"))
    ;~ _GDIPlus_ImageSaveToFileEx($hImage, $var, $sCLSID, DllStructGetPtr($tParams))
    ;~ _GDIPlus_Shutdown()

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

    ;PDF erstellen
    Local $aImgs = $var

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

    ;set the properties for the pdf
    _SetTitle("Image2PDF")
    _SetSubject("Convert image(s) to pdf")
    _SetKeywords("pdf, AutoIt")
    _OpenAfter(True);open after generation
    _SetUnit($PDF_UNIT_CM)
    _SetPaperSize("a3")
    _SetZoomMode($PDF_ZOOM_CUSTOM, 90)

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

    _SetOrientation($PDF_ORIENTATION_LANDSCAPE)
    ;~ _SetOrientation($PDF_ORIENTATION_PORTRAIT)

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

    _SetLayoutMode($PDF_LAYOUT_DEFAULT)
    ;~ _SetLayoutMode($PDF_LAYOUT_CONTINOUS)

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

    ;initialize the pdf
    _InitPDF(@ScriptDir & "\Image2PDF.pdf")

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

    ;=== load resources used in pdf ===
    _LoadResImage("img", $aImgs)

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

    ;load each image on it's own page
    _BeginPage()
    ;scale image to paper size!
    ;~ _InsertImage("img", 0, 0, _GetPageWidth(), _GetPageHeight())
    _InsertImage("img", 0, 0, _GetPageWidth() / _GetUnit(), _GetPageHeight() / _GetUnit())
    _EndPage()

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

    ;then, finally, write the buffer to disk
    _ClosePDFFile()

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

    ;~ FileDelete($var)
    EndFunc ;==>screencap

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

    Wär super, wenn einer (oder zwei) etwas tolles wüssten :)

    Danke & Gruß
    x0r

    Simon nörgelt, Simon nervt - aber Simon verbessert die Welt. Glaubt er.

    Einmal editiert, zuletzt von x0r (22. Juli 2013 um 10:42)

  • Hi UEZ,

    dein Programm ist echt spitzenklasse. :thumbup:

    Allerdings wird das Screenshot im Querformat in ein Hochformat-PDF eingefügt.

    Kann ich das Format des PDFs irgendwie ändern?

    Gruß
    x0r

    Simon nörgelt, Simon nervt - aber Simon verbessert die Welt. Glaubt er.

  • Ja, einfach

    [autoit]


    If $bW > $bH Then
    _SetPaperSize("CUSTOM", 841.890, 595.276) ; A4 landscape
    _SetOrientation($PDF_ORIENTATION_LANDSCAPE)
    Else
    _SetPaperSize("CUSTOM", 595.276, 841.890) ; A4 portrait
    _SetOrientation($PDF_ORIENTATION_PORTRAIT)
    EndIf

    [/autoit]

    Werde auch den Screenshooter bei Gelegenheit anpassen, so dass Bilder im Querformat auch als Querformat im PDF Format gespeichert werden.

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

    Einmal editiert, zuletzt von UEZ (20. Juli 2013 um 17:31)

  • Fragt mich nicht warum, aber so funktionierts annehmbar!!!

    Spoiler anzeigen
    [autoit][/autoit] [autoit][/autoit] [autoit]

    #AutoIt3Wrapper_UseX64=n
    #include <array.au3>
    #include <date.au3>
    #include <GDIPlus.au3>
    #include <MPDF_UDF.au3>
    #include <screencapture.au3>
    #include <imagesearch.au3>

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

    screencap()

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

    Func screencap()

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

    If FileExists(@ScriptDir & "\Image2PDF.pdf") Then FileDelete(@ScriptDir & "\Image2PDF.pdf")

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

    $var = @DesktopDir & "\Screens\" & @UserName & ".jpeg"
    $var2 = @DesktopDir & "\Screens\" & @UserName & "2.jpeg"

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

    $pic = _ScreenCapture_Capture("")
    _ScreenCapture_SaveImage($var, $pic)

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

    _rotate90($var, $var2)

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

    ;PDF erstellen
    Local $aImgs = $var2

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

    _SetTitle("Test")
    _SetSubject("Test")
    _SetKeywords("pdf, Test")
    _OpenAfter(True);open after generation
    _SetUnit($PDF_UNIT_CM)
    _SetPaperSize("A4")
    _SetZoomMode($PDF_ZOOM_CUSTOM, 90)

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

    _InitPDF(@ScriptDir & "\Image2PDF.pdf")

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

    _SetPaperSize("CUSTOM", 1920, 1920) ; A4 landscape
    _SetOrientation($PDF_ORIENTATION_LANDSCAPE)

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

    _SetLayoutMode($PDF_LAYOUT_CONTINOUS)

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

    _LoadResImage("img", $aImgs)

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

    _BeginPage()

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

    _InsertImage("img", 0, 0, _GetPageWidth() / _GetUnit(), _GetPageHeight() / _GetUnit())
    _EndPage()

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

    _ClosePDFFile()

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

    EndFunc ;==>screencap

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

    Func _Rotate90($ZielImage, $ZielPfad)
    _GDIPlus_Startup()

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

    $hImage2 = _GDIPlus_BitmapCreateFromFile($ZielImage)
    $Width = _GDIPlus_ImageGetWidth($hImage2)
    $Height = _GDIPlus_ImageGetHeight($hImage2)
    $hBitmap1 = _ScreenCapture_Capture("", 0, 0, $Height, $Width)
    $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap1)
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage1)

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

    $hMatrix = _GDIPlus_MatrixCreate()
    _GDIPlus_MatrixTranslate($hMatrix, $Height * 2, -$Width)
    _GDIPlus_MatrixRotate($hMatrix, 90, "False")
    _GDIPlus_GraphicsSetTransform($hGraphic, $hMatrix)
    _GDIPlus_GraphicsDrawImage($hGraphic, $hImage2, $Width, $Height)

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

    $result = _GDIPlus_ImageSaveToFile($hImage1, $ZielPfad)

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

    _GDIPlus_MatrixDispose($hMatrix)
    _GDIPlus_ImageDispose($hImage1)
    _GDIPlus_ImageDispose($hImage2)
    _WinAPI_DeleteObject($hBitmap1)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    Return $result
    EndFunc ;==>_Rotate90

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

    Danke an alle Beteiligten für die Tips :)

    Gruß
    x0r

    Simon nörgelt, Simon nervt - aber Simon verbessert die Welt. Glaubt er.