#include "MPDF_UDF.au3" _SelectImages() Func _SelectImages() Local $file = @ScriptDir & "\Image2PDF.pdf" Local $var = FileOpenDialog("Select images", @ScriptDir & "\", "Images (*.jpg;*.bmp;*gif;*png;*tif;*ico)", 4) If @error Then MsgBox(4096,"","No File(s) chosen") Else Local $aImgs = StringSplit($var, "|", 3) ;set the properties for the pdf _SetTitle("Image2PDF") _SetSubject("Convert image(s) to pdf") _SetKeywords("pdf, AutoIt") _OpenAfter(False);open after generation _SetUnit($PDF_UNIT_CM) _SetPaperSize("a4") _SetZoomMode($PDF_ZOOM_CUSTOM,90) _SetOrientation($PDF_ORIENTATION_PORTRAIT) _SetLayoutMode($PDF_LAYOUT_CONTINOUS) ;initialize the pdf _InitPDF($file) If UBound($aImgs)<>1 Then ;=== load resources used in pdf === For $i=1 To UBound($aImgs)-1 _LoadResImage("img"&$i, $aImgs[0] & "\" & $aImgs[$i]) Next ;load each image on it's own page For $i = 1 To UBound($aImgs)-1 _BeginPage() ;scale image to paper size! _InsertImage("img"&$i, 0, 0, _GetPageWidth()/_GetUnit(), _GetPageHeight()/_GetUnit()) _EndPage() Next _ClosePDFFile() ;_ArrayDisplay($image_array) Write_image_Multi($File) Else _LoadResImage("taietel", $aImgs[0]) _BeginPage() ;scale image to paper size! _InsertImage("taietel", 0, 0, _GetPageWidth()/_GetUnit(), _GetPageHeight()/_GetUnit()) _EndPage() _ClosePDFFile() ;_ArrayDisplay($image_array) Write_image($file,$image_array[1]) EndIf EndIf EndFunc Func Write_image_Multi($File) Local $OpenedFile, $File_Bin, $Openedimage, $Image_Bin for $i = 1 to UBound($image_array)-1 $OpenedFile = FileOpen($File, 16) $File_Bin = FileRead($OpenedFile) FileClose($OpenedFile) $stream_position = Ceiling((StringInStr(string($File_Bin),"73747265616D0D0A",0,$i+($i-1))-2)/2) $Openedimage = FileOpen($image_array[$i], 16) $Image_Bin = "" $Image_Bin = FileRead($Openedimage) FileClose($Openedimage) $OpenedFile = FileOpen($File, 17) FileSetPos($OpenedFile,$stream_position + 7, 0) FileWrite($OpenedFile, $Image_Bin) FileClose($OpenedFile) FileDelete($image_array[$i]) Next EndFunc Func Write_image($File,$Image) Local $OpenedFile = FileOpen($File, 16) Local $File_Bin = FileRead($OpenedFile) FileClose($OpenedFile) $stream_position = Ceiling((StringInStr(string($File_Bin),"73747265616D")-2)/2) Local $Openedimage = FileOpen($Image, 16) Local $Image_Bin = FileRead($Openedimage) FileClose($Openedimage) $OpenedFile = FileOpen($File, 17) FileSetPos($OpenedFile,$stream_position + 7, 0) FileWrite($OpenedFile, $Image_Bin) FileClose($OpenedFile) FileDelete($Image) EndFunc