Jump to content

Create a PDF with own style


Recommended Posts

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

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

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

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

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

 

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.

Link to comment
Share on other sites

Easier way:

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

mLipok

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor 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 APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

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 * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

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) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

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 *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"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: 2023-04-24

Link to comment
Share on other sites

5 hours ago, FrancescoDiMuro said:

The file PDF becomes unreadable...

Post your testing code snippet.

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor 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 APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

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 * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

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) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

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 *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"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: 2023-04-24

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Link to comment
Share on other sites

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

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Link to comment
Share on other sites

@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

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

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:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor 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 APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

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 * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

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) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

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 *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"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: 2023-04-24

Link to comment
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
 Share

×
×
  • Create New...