FrancescoDiMuro

Create a PDF with own style

16 posts in this topic

#1 ·  Posted

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 :)
 


Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites



#2 ·  Posted

Hi @FrancescoDiMuro, You can use this UDF:

in the ZIP file there is also a folder with some examples of use (also to make tables).

For further example of use you can also have a look to this post where this udf is used to build a calendar.


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Can anyone help me with this UDF? 
There's no much help in the Examples...
Thanks :) 

EDIT:
Mainly, I'd like to know how to create a table...
I read data from a file formatted in this way:
Text1;Text2;Text3;Text4;
And, for each text, I need to create a cell with the corresponding text ( 1, 2, 3, 4... n)
So, I have the table...
If anyone else have used this library before, please help me.
Thanks again :) 

Edited by FrancescoDiMuro
Need some help...

Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites

#4 ·  Posted

I used something like this some time ago, but then I ported it to C because of speed.

Hope this helps.

 

#include "..\MPDF_UDF.au3"
#include <Array.au3>
;set the properties for the pdf
_SetTitle("Demo Table PDF in AutoIt")
_SetSubject("Demo Table PDF in AutoIt, with formating")
_SetKeywords("pdf, demo, table, AutoIt")
_OpenAfter(True);open after generation
_SetUnit($PDF_UNIT_CM)
_SetPaperSize("CUSTOM", 841.890, 595.276); A4 landscape
_SetZoomMode($PDF_ZOOM_FULLPAGE)
_SetOrientation($PDF_ORIENTATION_PORTRAIT)
_SetLayoutMode($PDF_LAYOUT_CONTINOUS)

Global $aCSV = _CSVReadToArray("Test.csv", ',')
;~ Global $aCSV = _CSVReadToArray("Table.txt", ';')
ReDim $aCSV[UBound($aCSV, 1)][UBound($aCSV, 2) - 1]

_Array2DTransposeAU3($aCSV)

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

;=== load used font(s) ===
;fonts: Garamond
_LoadFontTT("_CalibriB", $PDF_FONT_CALIBRI, $PDF_FONT_BOLD)
_LoadFontTT("_CalibriI", $PDF_FONT_CALIBRI, $PDF_FONT_ITALIC)
_LoadFontTT("_Calibri", $PDF_FONT_CALIBRI)

Global $MaxRowsPerPage = 30

_InsertTable($aCSV, 1.5, 1.5, 0, 0, $MaxRowsPerPage, 0x000000, 0x00000)
;~  $sTit = "Sample pdf table generated with AutoIt"
;~  _SetTextRenderingMode(1)
;~  _InsertRenderedText((_GetPageWidth()/_GetUnit())/2, _GetPageHeight()/_GetUnit()-1.5, $sTit, "_CalibriI", 32, 100, $PDF_ALIGN_CENTER, 0xbbbbbb, 0x202020)
;~ _SetTextRenderingMode(0)

_ClosePDFFile()

Func _InsertTable($aCSV, $iX, $iY, $iW = 0, $iH = 0, $iRowsPerPage = 30, $lTxtColor = 0x000000, $lBorderColor = 0xdddddd)
    Local $iCols = UBound($aCSV, 1)
    Local $iPages = Ceiling(UBound($aCSV, 2) / $iRowsPerPage)
    Local $iRest = Mod(UBound($aCSV, 2), $iRowsPerPage), $iSub = 1
    Local $iPgW = Round(_GetPageWidth() / _GetUnit(), 1)
    Local $iPgH = Round(_GetPageHeight() / _GetUnit(), 1)
    If $iW = 0 Then $iW = $iPgW - 2 * $iX
    If $iH = 0 Then $iH = $iPgH - 2 * $iY

    Local $iColW = $iW / $iCols
    Local $iRowH = $iH / $iRowsPerPage
    Local $lRGB
    For $k = 0 To $iPages - 1
        _BeginPage()
        _SetColourStroke($lBorderColor)
;~      _Draw_Rectangle($iX, $iY, $iW, $iH, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.01)
        _SetColourStroke(0)
        If $k = $iPages - 1 Then $iSub = $iRowsPerPage - $iRest + 1
        For $i = $k * $iRowsPerPage To ($k + 1) * $iRowsPerPage - $iSub
            For $j = 0 To $iCols - 1
                If $k = 0 Then
                    If $i = 0 Then
                        $lRGB = 0xbbbbbb
                    Else
                        $lRGB = 0xfefefe
                    EndIf
                Else
                    $lRGB = 0xfefefe
                EndIf
                _SetColourStroke($lBorderColor)
                _Draw_Rectangle($iX + $j * $iColW, $iY + $iH - ($i - $k * $iRowsPerPage + 1) * $iRowH, $iColW, $iRowH, $PDF_STYLE_STROKED, 0, $lRGB, 0.01)
                _SetColourStroke(0)
                Local $sText = $aCSV[$j][$i]
                Local $sLength = Round(_GetTextLength($sText, "_Calibri", 10), 1)
                $lScale = Ceiling(0.75 * $iColW * 100 / $sLength)
                _SetColourFill($lTxtColor)
;~              _SetTextHorizontalScaling(80)
                _DrawText($iX + $j * $iColW + $iColW / 10, $iY + $iH - ($i - $k * $iRowsPerPage + 1) * $iRowH + ($iRowH - 10 / _GetUnit()) / 2, $sText, "_Calibri", 10, $PDF_ALIGN_LEFT, 0)
;~          _SetTextHorizontalScaling(50)
                _SetColourFill(0)
            Next
        Next
        _EndPage()
    Next

EndFunc   ;==>_InsertTable


Func _CSVReadToArray($sFile, $sSeparator, $sQuote = '"')
    Local $hFile = FileOpen($sFile, 0)
    Local $sText = FileRead($hFile)
    FileClose($hFile)
;~  $sText = StringReplace($sText, "Intern", "Raumtemp")
    $sText = StringReplace($sText, "." & @YEAR, "." & "12")
    Local $aArray
    If StringRight($sText, 1) = @LF Then $sText = StringTrimRight($sText, 1)
    If StringRight($sText, 1) = @CR Then $sText = StringTrimRight($sText, 1)

    If StringInStr($sText, @LF) Then
        $aArray = StringSplit(StringStripCR($sText), @LF, 2)
    ElseIf StringInStr($sText, @CR) Then ;; @LF does not exist so split on the @CR
        $aArray = StringSplit($sText, @CR, 2)
    Else ;; unable to split the file
        If StringLen($sText) Then
            Dim $aArray[1] = [$sText]
        Else
            Return SetError(2, 0, 0)
        EndIf
    EndIf
    $aArray = _Array1DTo2D($aArray, $sSeparator)
    ReDim $aArray[UBound($aArray, 1)][UBound($aArray, 2) - 1]
    Return $aArray
EndFunc   ;==>_CSVReadToArray

Func _Array1DTo2D($a1D, $sDelim = ";", $iSeveral = 0)
    ;funkey 17.02.2010
    Local $iUbound = UBound($a1D) - 1
    Local $iTemp = 0, $iColumn = 0
    For $i = 0 To $iUbound
        If $iSeveral Then
            $iTemp = UBound(StringRegExp($a1D[$i], $sDelim & "+", 3))
        Else
            $iTemp = UBound(StringSplit($a1D[$i], $sDelim, 3))
        EndIf
        If $iTemp > $iColumn Then $iColumn = $iTemp
    Next
    Local $a2D[UBound($a1D)][$iColumn + 1]
    Local $aTemp
    For $i = 0 To $iUbound
        If $iSeveral Then
            $aTemp = StringSplit(StringRegExpReplace($a1D[$i], $sDelim & "+", $sDelim), $sDelim, 3)
        Else
            $aTemp = StringSplit($a1D[$i], $sDelim, 3)
        EndIf
        For $j = 0 To UBound($aTemp) - 1
            $a2D[$i][$j] = $aTemp[$j]
        Next
    Next
    Return SetExtended($iColumn, $a2D)
EndFunc   ;==>_Array1DTo2D

Func _Array2DTransposeAU3(ByRef $ar_Array)
    If IsArray($ar_Array) Then
        Local $ar_ExcelValueTrans[UBound($ar_Array, 2)][UBound($ar_Array, 1)] ;ubound($s_i_ExcelValue,2)-1, ubound($s_i_ExcelValue,1)-1)
        For $j = 0 To UBound($ar_Array, 2) - 1
            For $numb = 0 To UBound($ar_Array, 1) - 1
                $ar_ExcelValueTrans[$j][$numb] = $ar_Array[$numb][$j]
            Next
        Next
        $ar_Array = $ar_ExcelValueTrans
    Else
        ;MsgBox(0, "", "No Array to transpose")
    EndIf
EndFunc   ;==>_Array2DTransposeAU3

 

1 person likes this

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post


Link to post
Share on other sites

#5 ·  Posted

Easier way:

  1. create HTML file
  2. use htm2pdf.exe to create PDF file.

mLipok

 


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

#6 ·  Posted

@funkey & @mLipok:
Good morning guys :)
I'll try your script asap... Thank you for your help :) 


Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites

#7 ·  Posted

@mLipok
The file PDF becomes unreadable... 
I can't do it thorugh htm2pdf...
Any other solution? 
Thanks :) 


Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites

#8 ·  Posted

5 hours ago, FrancescoDiMuro said:

The file PDF becomes unreadable...

Post your testing code snippet.

 


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

#9 ·  Posted

Does my script work for you?


Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post


Link to post
Share on other sites

#10 ·  Posted

nice example @funkey

it makes easy to print tables in full & multi page mode.

Here another example on how to put tables on the page  by passing data in an 1D or 2D array, with the possibility to positioning it where you want and with a desired dimension using the _InsertArrayTable() function.

I've also inserted a "graph paper" as background" so to be facilitated to position "stuff" on the page (as you can see the origin of the axis is on the bottom-left).

To remove the "graph paper" from the background, just comment out all lines  between _StartObject and _EndObject.

this demo uses as data  an array generated by the _GenerateMonth function that returns an 7x7 array containing a month af an year. Of course you can pass any array of your choice.

p.s. if you get this error: ERROR: _Iif() already defined
then just remove or rename the _Iif() function from the bottom of the script.
this occurs with older AutoIt versions

have fun.

#include "MPDF_UDF.au3" ; get it here https://www.autoitscript.com/forum/topic/118827-create-pdf-from-your-application/
#include <Date.au3>
#include <array.au3>

; ----- set the properties for the pdf -----
_SetTitle("Demo Table PDF in AutoIt")
_SetSubject("Demo Table PDF in AutoIt")
_SetKeywords("pdf, demo, table, AutoIt")
_OpenAfter(True);open after generation
_SetUnit($PDF_UNIT_CM)
_SetPaperSize("A4"); A4 vertical
_SetZoomMode($PDF_ZOOM_FULLPAGE)
_SetOrientation($PDF_ORIENTATION_PORTRAIT) ; set page vertical
_SetLayoutMode($PDF_LAYOUT_CONTINOUS)

;initialize the pdf (create the pdf file on disk)
_InitPDF(@ScriptDir & "\Example_Table.pdf")

; === load used font(s) ===
_LoadFontTT("_CalibriB", $PDF_FONT_CALIBRI, $PDF_FONT_BOLD)
_LoadFontTT("_CalibriI", $PDF_FONT_CALIBRI, $PDF_FONT_ITALIC)
_LoadFontTT("_Calibri", $PDF_FONT_CALIBRI)

; ----- draw graph paper on all pages ------------------------------------
; this "object" will be automatically inserted on each new page
;
_StartObject("GraphPaper", $PDF_OBJECT_ALLPAGES) ; $PDF_OBJECT_NOTFIRSTPAGE

For $i = 0 To 21 Step 0.1 ; vertical steps every 1 mm on the bottom border
    _DrawLine($i, 0, $i, 0.75, 2, 10, 0.03, 0xD0D0D0, 0, 0)
Next

For $i = 0 To 29.7 Step 0.1 ; horizontal steps every 1 mm on the left border
    _DrawLine(0, $i, 0.75, $i, 2, 10, 0.03, 0xD0D0D0, 0, 0)
Next

For $i = 0 To 21 ; vertical lines
    _DrawLine($i, 0, $i, 29.7, 2, 10, 0.03, 0xD0D0D0, 0, 0) ; vertical line every 1 cm along the page
    _DrawLine($i, 0, $i, 1, 2, 10, 0.03, 0x909090, 0, 0) ; mark steps every 1 cm on the bottom (a little darker)
    _DrawLine($i - 0.50, 0, $i - 0.50, 29.7, 2, 10, 0.02, 0xD0D0D0, 0, 0) ; vertical line every 1/2 cm
    _DrawLine($i - 0.25, 0, $i - 0.25, 29.7, 2, 10, 0.01, 0xF0F0F0, 0, 0) ; vertical line every 1/4 cm
    _DrawLine($i + 0.50, 0, $i + 0.50, 29.7, 2, 10, 0.02, 0xD0D0D0, 0, 0) ; vertical line every 1/2 cm
    _DrawLine($i + 0.25, 0, $i + 0.25, 29.7, 2, 10, 0.01, 0xF0F0F0, 0, 0) ; vertical line every 1/4 cm
    ; following code line writes the nr. of this cm
    _DrawText($i + 0.02, 1, $i, "_TimesT", 9, $PDF_ALIGN_LEFT, 0)
Next

For $i = 0 To 29.7 ; horizontal lines
    _DrawLine(0, $i, 21, $i, 2, 10, 0.03, 0xD0D0D0, 0, 0) ; horizontal line every 1 cm along the page
    _DrawLine(0, $i, 1, $i, 2, 10, 0.03, 0x909090, 0, 0) ; mark steps every 1 cm on the left (a little darker)
    _DrawLine(0, $i - 0.50, 21, $i - 0.50, 2, 10, 0.02, 0xD0D0D0, 0, 0) ; horizontal line every 1/2 cm
    _DrawLine(0, $i - 0.25, 21, $i - 0.25, 2, 10, 0.01, 0xF0F0F0, 0, 0) ; horizontal line every 1/4 cm
    _DrawLine(0, $i + 0.50, 21, $i + 0.50, 2, 10, 0.02, 0xD0D0D0, 0, 0) ; horizontal line every 1/2 cm
    _DrawLine(0, $i + 0.25, 21, $i + 0.25, 2, 10, 0.01, 0xF0F0F0, 0, 0) ; horizontal line every 1/4 cm
    ; following code line writes the nr. of this cm
    _DrawText(1, $i + 0.02, $i, "_TimesT", 9, $PDF_ALIGN_LEFT, 0)
Next
_EndObject()
; ------------------------------------------------------------------------

_BeginPage(); begin new page (above object is inserted automatically)
;

; insert the table on the pdf page (see header of function for parameters)
;
Local $iYear = 1962, $iMonth = 5 ; just for example
Local $aMyTable = _GenerateMonth($iYear, $iMonth) ; create an array containing wanted month
Local $fXpos = 3
Local $fYpos = 23
Local $fWidth = 8
Local $fHeight = 4
Local $dTxtColor = 0x00ff00
Local $dFillColor = 0xF0F0F0
Local $dBorderColor = 0xff0000
;
_InsertArrayTable($fXpos, $fYpos, $fWidth, $fHeight, $aMyTable, $dTxtColor, $dFillColor, $dBorderColor)
;
; draw a rectangle above the table
_SetColourStroke($dBorderColor)
_Draw_Rectangle($fXpos, $fYpos + $fHeight, $fWidth, .7, $PDF_STYLE_STROKED, 0, $dFillColor, 0.01) ; 0.01 is the thickness of the edge pane frame

; draw a string on the page (we put this screen in the rectangle above the table)
Local $sMyString = _DateToMonth($iMonth, $DMW_LOCALE_LONGNAME) & " " & $iYear
_InsertRenderedText($fXpos + .2, $fYpos + $fHeight + .25, $sMyString, "_CalibriI", 14, 100, $PDF_ALIGN_LEFT, $dTxtColor, $dBorderColor)

_EndPage()

_ClosePDFFile(); write the buffer to disk

; #FUNCTION# ====================================================================================================================
; Name ..........: _InsertArrayTable
; Description ...:
; Syntax ........: _InsertArrayTable($fX, $fY[, $fW = 0[, $fH = 0[, $aData = ""[, $dTxtColor = 0x000000[, $dFillColor = 0xF0F0F0[,
;                  $dBorderColor = 0xdddddd]]]]]])
; Parameters ....: $fX                  - X position (cm from the left side of the paper)
;                  $fY                  - y position (cm from the bottom side of the paper)
;                  $fW                  - wanted table total width in cm
;                  $fH                  - wanted table total height in cm
;                  $aData               - An 1D or 2D array containing data to be inserted in the table (a simple variable as well)
;                  $dTxtColor           - [optional] Text Color. Default is 0x000000.
;                  $dFillColor          - [optional] Background Color. Default is 0xF0F0F0.
;                  $dBorderColor        - [optional] Border Color. Default is 0xdddddd.
; Return values .: None
; Author ........: Chimp
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _InsertArrayTable($fX, $fY, $fW = 0, $fH = 0, $aData = "", $dTxtColor = 0x000000, $dFillColor = 0xF0F0F0, $dBorderColor = 0xdddddd)

    Local $aTemp[1][1]

    If Not IsArray($aData) Then
        $aTemp[0][0] = $aData
    ElseIf UBound($aData, 0) > 2 Then
        Return SetError(1) ; max 2 dimensions
    ElseIf UBound($aData, 0) = 1 Then; 1d array becomes a 2d array
        ReDim $aTemp[1][UBound($aData)]
        For $i = 0 To UBound($aData) - 1
            $aTemp[0][$i] = $aData[$i]
        Next
    ElseIf UBound($aData, 0) = 2 Then
        $aTemp = $aData
    EndIf

    $iCols = UBound($aTemp, 2) ; number of columns in the table
    $iRows = UBound($aTemp, 1) ; number of rows in the table

    Local $fPgW = Round(_GetPageWidth() / _GetUnit(), 1)
    Local $fPgH = Round(_GetPageHeight() / _GetUnit(), 1)
    If $fW = 0 Then $fW = $fPgW - $fX - 2
    If $fH = 0 Then $fH = $fPgH - $fY - 2

    Local $iColW = $fW / $iCols ; width of each single column
    Local $iRowH = $fH / $iRows ; heigth of each single row
    Local $sText

    ; _Draw_Rectangle($fX, $fY, $fW, $fH, $PDF_STYLE_STROKED, 0, $dFillColor, 0.01)

    For $i = 0 To $iRows - 1
        For $j = 0 To $iCols - 1
            _SetColourStroke($dBorderColor)
            _Draw_Rectangle($fX + $j * $iColW, $fY + $fH - ($i + 1) * $iRowH, $iColW, $iRowH, $PDF_STYLE_STROKED, 0, $dFillColor, 0.01) ; 0.01 is the thickness of the edge pane frame
            $sText = $aTemp[$i][$j]
            _InsertRenderedText($fX + $j * $iColW + $iColW / 10, $fY + $fH - ($i + 1) * $iRowH + ($iRowH - 10 / _GetUnit()) / 2, $sText, "_Calibri", 10, 100, $PDF_ALIGN_LEFT, $dTxtColor)
        Next
    Next
EndFunc   ;==>_InsertArrayTable

Func _GenerateMonth($iYear = @YEAR, $iMonth = @MON, $ISO = True)
    ; this function creates a month calendar into an 7x7 array
    Local $aMonth[7][7], $iDOW
    Local $iFirstDOW = $ISO ? _DateToDayOfWeekISO($iYear, $iMonth, 1) : _DateToDayOfWeek($iYear, $iMonth, 1)
    For $iDay = 1 To 7
        $aMonth[0][$iDay - 1] = $ISO ? _DateDayOfWeek(Mod($iDay, 7) + $ISO, $DMW_LOCALE_SHORTNAME) : _DateDayOfWeek($iDay, $DMW_LOCALE_SHORTNAME)
    Next
    For $iDay = 1 To _DateDaysInMonth($iYear, $iMonth)
        $iDOW = $ISO ? _DateToDayOfWeekISO($iYear, $iMonth, $iDay) : _DateToDayOfWeek($iYear, $iMonth, $iDay)
        $aMonth[Int(($iFirstDOW + $iDay - 2) / 7) + 1][$iDOW - 1] = $iDay
    Next
    Return $aMonth
EndFunc   ;==>_GenerateMonth


Func _Iif($fTest, $vTrueVal, $vFalseVal)
    If $fTest Then
        Return $vTrueVal
    Else
        Return $vFalseVal
    EndIf
EndFunc   ;==>_Iifx

 

2 people like this

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#11 ·  Posted

On 30/3/2017 at 1:51 AM, funkey said:

Does my script work for you?

Hey @funkey:)
Thanks for your code...

I didn't tried your code...
I talked with the Author of that UDF, and he told me that there are better ways to create a PDF...
I'm still trying them, but I won't give up right now, because that UDF seems ( because it is ) very complex for me...
If anyone has a suggest, please, reply to this topic :)
Thanks everyone for the help!


Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites

#12 ·  Posted

M new here

but my suggestion is to use excel udf to create excel file as per ur requirement and than use

_Excel_Export()

To get it in either pdf or xps file format

 

You can also keep a default excel template and update values instead of everytime working on formating part.

Hope this helps

Share this post


Link to post
Share on other sites

#13 ·  Posted

Great example @Chimp! Thanks!

With this script everyone can easily understand and see what is possible with this UDF!

 

 


Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post


Link to post
Share on other sites

#14 ·  Posted

Thanks @funkey :)

 

Good idea @n3wbie, using  _Excel_Export() can also be an handy way.

 

17 hours ago, FrancescoDiMuro said:

...... I talked with the Author of that UDF, and he told me that there are better ways to create a PDF ......

Hi @FrancescoDiMuro did you talked with @taietel ?
could you tell us what are the better ways he suggested ?? thanks. :)


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

@Chimp
I talked with @taietel, and he suggested to me to use PDFMake... The language is Javascript, and it's a good tool... But I didn't manage with that too...
I managed with a tool in Visual Studio named CrystalReports... It's designed for creating professional reports ( even if it's not simple at all :) )...


@n3wbie
Thanks for your suggestion! The fact is that I can use Excel UDF because, on the machine I'm going to run my scripts, Office is not installed... So, I would have worked with ADO... But they seems difficult, and I don't have time to spend on these things ( busy, not because I don't want to :) ).
By the way, thank you :)

For everyone, thanks :) 
 

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites

#16 ·  Posted

16 minutes ago, FrancescoDiMuro said:

The fact is that I can use Excel UDF because, on the machine I'm going to run my scripts, Office is not installed

Did you try OOCalc udf ?

Of course you could QuickPDF UDF but you should to know that this is commercial ActiveX product .

 


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

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

  • Similar Content

    • 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.
       
    • nacerbaaziz
      By nacerbaaziz
      Hi dear
      I want create retractable bar using autoit
      I tried creating slider, but there's a problem with screen reader for the blind, so is there another retractable tape?
      It is advisable to not accept dragging with the keybord only with  mouse
      note:
      This bar is needed in the process of raising and lowering the volume
      I hope that there is a solution to do that
      i waiting your responses.
      Thanks in advance to all members and administrators
    • 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 :-)
       
       
       
       
       
       
    • nacerbaaziz
      By nacerbaaziz
      Hi dears
      How are you?
      I have a question, to you please.
      How do I create an edit box for numbers only and does not accept letters? using autoit
      greetings to all
      I hope you help ME
      Thanks to all in advance