Sign in to follow this  
Followers 0
libreau3

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"

_SelectImages()

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")
    Else
        Local $aImgs = StringSplit($var, "|", 3)
        Dim $cHeight[1]
        $cHeight[0] = 0
        Dim $cWidth[1]
        $cWidth[0] = 0
        _GDIPlus_Startup()
        For $i = 1 To UBound($aImgs) - 1
            $oGdi = _GDIPlus_ImageLoadFromFile($aImgs[0] & "\" & $aImgs[$i])
            If @error Then
                MsgBox(0, "Error", @error)
                Exit
            EndIf
            _ArrayAdd($cWidth, _GDIPlus_ImageGetWidth($oGdi))
            _ArrayAdd($cHeight, _GDIPlus_ImageGetHeight($oGdi))
        Next
        _GDIPlus_Shutdown()
        _OpenAfter(True);open after generation
        _SetUnit($PDF_UNIT_PT)
        _SetZoomMode($PDF_ZOOM_CUSTOM, 90)
        _SetLayoutMode($PDF_LAYOUT_CONTINOUS)

        ;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])
            Next
            ;load each image on it's own page
            For $i = 1 To UBound($aImgs) - 1
                _SetPaperSize("CUSTOM",$cWidth[$i],$cHeight[$i])
                _BeginPage()
                _InsertImage("img" & $i, 0, 0,$cWidth[$i], $cHeight[$i])
                _EndPage()
            Next
        Else
            _LoadResImage("taietel", $aImgs[0])
            _BeginPage()
            ;scale image to paper size!
            _InsertImage("taietel", 0, 0, _GetPageWidth() / _GetUnit(), _GetPageHeight() / _GetUnit())
            _EndPage()
        EndIf
        ;then, finally, write the buffer to disk
        _ClosePDFFile()
    EndIf
EndFunc   ;==>_SelectImages

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

Img2Pdf.zip

1 person likes this

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

image2pdf.zip

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

    • Iznogoud
      By Iznogoud
      Hi,
      I am trying to find more information on generating PDF files from AutoIT and found the UDF topic 
      Also found some info on creating .FDF file and use PDFTK for merging, but i can't find info about a custom based layout.
      What i trying to find out is, if it is possible to generate a variable layout. For an example i created a script which is based out 20 fields and every field can contain information. If one of those fields are not filled, it shouldn't be printed on the PDF either.
      To make it more difficult, the PDF should contain a heading, the first 10 fields and then a horizontal line across the PDF and then a new heading and then show the last 10 fields.
      But only the fields which are filled.
      Is this possible?
    • Gowrisankar
      By Gowrisankar
      Hello everyone,
      I'm working on a task where, a PDF file is opened (in IE browser) when I click a link in a website.
      I have to read the first page of the PDF to find particular strings. Can you please share some ideas?
    • mLipok
      By mLipok
      Here:
      https://github.com/nachbar/TRichViewToPdfUsingDebenu/blob/master/Unit1.cpp
      I found a code in C++ for file format conversion from RTF to PDF with using Debenu QuickPDF.
      I know how to use Debenu QuickPDF in AutoIt .
      My question is about RTF part of this code:
       
      HDC hdcNew = debenu->GetCanvasDC( RTFPRINTINGDOTSPERINCH * RTFPAGEWIDTHININCHES, RTFPRINTINGDOTSPERINCH * RTFPAGEHEIGHTININCHES); canvas = new TCanvas; canvas->Handle = hdcNew; RVReportHelper1->DrawPage( PageCounter, canvas, true, RTFPRINTINGDOTSPERINCH * RTFPAGEHEIGHTININCHES); // LastPageHeight);  
      First there is hdcNew declaration , and this is not the problem.
      My problem is in converting the following code snippet, to AutoIt
      canvas = new TCanvas; canvas->Handle = hdcNew; RVReportHelper1->DrawPage( PageCounter, canvas, true, RTFPRINTINGDOTSPERINCH * RTFPAGEHEIGHTININCHES); // LastPageHeight);
      If you remember, I created RTFPrinter sometime ago. But it was some time ago , and created by trial and error, rather than in-depth analysis.
      Also, it was just a modification of another script, not my own work from scratch.
      So now I'm looking for help how to adapt this code snippet to AutoIt.
      Any tips ?
       
      Regards,
      mLIpok
       
    • Kiran_L
      By Kiran_L
      Hi guys,
       
      I am trying to read a pdf file with unstructured data. I dontot know how to handle pdf activities in AutoIt,
      Can you help me with any UDF to open the PDF and read the doc.
       
      Thanks for your time.
       
    • 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
      D:\Projekte\1166_64233_5374
      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:
      D:\Projekte\1166_64233_5374
      the code shoud search for specific PDF Files.
      They are named like: 0050569E364B1ED79B900F73E62660EC.pdf
      the first 15 letters are always the same
      0050569E364B1ED
      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 :-)