Sign in to follow this  
Followers 0

Custom PDF Page Sizes

2 posts in this topic

Hello all

     I am trying to create img2pdf program using The >MPDF UDF. The base of my code is dirived from the img2pdf example. I can make the image itself the a custom size but not the page itself. Any ideas?

#include "..\MPDF_UDF.au3"


Func _SelectImages()
    Local $var = FileOpenDialog("Select images", @ScriptDir & "\", "Images (*.jpg;*.bmp;*gif;*png;*tif;*ico)", 4)
    If @error Then
        MsgBox(4096, "", "No File(s) chosen")
        Local $aImgs = StringSplit($var, "|", 3)
        Dim $cHeight[1]
        $cHeight[0] = 0
        Dim $cWidth[1]
        $cWidth[0] = 0
        For $i = 1 To UBound($aImgs) - 1
            $oGdi = _GDIPlus_ImageLoadFromFile($aImgs[0] & "\" & $aImgs[$i])
            If @error Then
                MsgBox(0, "Error", @error)
            _ArrayAdd($cWidth, _GDIPlus_ImageGetWidth($oGdi))
            _ArrayAdd($cHeight, _GDIPlus_ImageGetHeight($oGdi))
        _OpenAfter(True);open after generation
        _SetZoomMode($PDF_ZOOM_CUSTOM, 90)

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

        If UBound($aImgs) <> 1 Then
            ;=== load resources used in pdf ===
            For $i = 1 To UBound($aImgs) - 1
                _LoadResImage("img" & $i, $aImgs[0] & "\" & $aImgs[$i])
            ;load each image on it's own page
            For $i = 1 To UBound($aImgs) - 1
                _InsertImage("img" & $i, 0, 0,$cWidth[$i], $cHeight[$i])
            _LoadResImage("taietel", $aImgs[0])
            ;scale image to paper size!
            _InsertImage("taietel", 0, 0, _GetPageWidth() / _GetUnit(), _GetPageHeight() / _GetUnit())
        ;then, finally, write the buffer to disk
EndFunc   ;==>_SelectImages

ps I have included the my source the udf and the images I am using to test it.

1 person likes this

Share this post

Link to post
Share on other sites

#2 ·  Posted (edited)

Take a peek at my meager cobblings with the same script (apoligies to taietel).

I can get any papersize I need.

Edit: I inculded mppdf.au3 because I added papersizes to it.

Marked with ;>>>>>>>>>>>>>>>>>>>

Edited by lorenkinzel

Share this post

Link to post
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
Sign in to follow this  
Followers 0

  • Similar Content

    • Mag91
      By Mag91
      Hey Community,
      cause im too new in the Auto it world i will try it with the your help. hopefully.
      I woud like to know how i can handle my Problem.
      I have a Excel Data with 362 random numbers.
      For Example:
      1166642335374 1172899897343
      this numbers are a part of the filepath ...example
      as u can see its the first number of the Excel data. After the first 4 numbers it shoud make a "_" than another 5 "_"
      This is my first question. How can i handle this to make it Shell execute.
      Second question:
      If i am in the path.
      For Example:
      the code shoud search for specific PDF Files.
      They are named like: 0050569E364B1ED79B900F73E62660EC.pdf
      the first 15 letters are always the same
      when he found this data he has to copy it on a Folder on the Desktop.
      (There can also be 2 or 3 pdfs in one Folder with this letters)
      Please give me some help :-)
    • Mag91
      By Mag91
      Hey Everybody,
      as you know im on a very low autoit-level.
      My question is: How can i read all PDFs from a Folder wich is open and copy them to a Folder on a Desktop.
      The Folder wich contains the PDFs is variable Z:\Projektls\"*"*"*EVERYTIME ANOTHER ENDING"*"*"*"*"
      There can be 1 PDF or even 15 PDFs.
      i tried it with _FileListToArray and _FileCopy but i Need some help to understand this language
    • Skeletor
      By Skeletor
      Hi Guys,
      I've been reading this post ...
      When I came accross the examples, non of them had what I was looking for.
      I basically want to "snapshot" my GUI's multiple tabs and send them into the pdf.
      A little nudge from you guys would be great.
      Im really stuck with this one, therefore I have no code.
      Lets discuss or point me in a right direction... thanks alot

    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning
      I was looking around the forum if there were some customizable solutions about creating a PDF from "0" to something like a report...
      What I'd like to do is something with a header ( 2 logos and a title ), with a table which contains data read from a file
      At the moment, I was working with HTML, since I know it and it's very simple to do a table with some data inside...
      But know, I'm a bit stuck about the exporting the HTML page to PDF... And, here too, if someone knows how to do it, please, I'm here listening
      Thanks guys
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning guys
      I'd like to know if there is a way to convert a PDF in CSV or, eventually, in TXT, in order to read from it, like a database...
      I have a PDF and I think ( I dind't search a lot on the forum ) with AutoIt, but I'd like work with Excel styles...
      Does anyone know a good program which convert PDF to CSV? 
      PS: the PDF file is 5 MB, and it contains 439 pages...
      Thanks everyone for the help