Il y a aussi la solution sur la base de MPDF_UDF de Mihai Iancu qui gère les accents.
Code : Tout sélectionner
#include "MPDF_UDF_FR.au3"
;------------- création array -----------------------------------------
$entete = StringSplit("ligne 1,ligne 2,ligne 3,ligne 4,ligne 5,ligne 6,ligne 7", ",", 2)
;----------------------------------------------------------------------
$sText = "Le métro new-yorkais, véritable laboratoire de "
$sText &= "bactéries. Des centaines d'espèces de bactéries et de "
$sText &= "microbes parfois mystérieux vivent dans le métro "
$sText &= "new-yorkais, la plupart inoffensifs, mais on y trouve "
$sText &= "aussi des fragments associés à l'anthrax et à la peste "
$sText &= "bubonique, selon une étude publiée la semaine dernière."
;----------------------------------------------------------------------
_SetTitle("Demo PDF in AutoIt")
_SetSubject("Demo PDF in AutoIt, without any ActiveX or DLL...")
_SetKeywords("pdf, demo, AutoIt")
_OpenAfter(True)
_SetUnit($PDF_UNIT_CM)
_SetPaperSize("A4")
_SetZoomMode($PDF_ZOOM_CUSTOM, 90)
_SetOrientation($PDF_ORIENTATION_PORTRAIT)
_SetLayoutMode($PDF_LAYOUT_CONTINOUS)
_InitPDF(@ScriptDir & "\test_simple.pdf")
_LoadFontStandard("_Helv", $PDF_FONT_STD_HELVETICA, $PDF_FONT_BOLD)
_LoadFontStandard("_aria", $PDF_FONT_STD_ARIAL, $PDF_FONT_BOLD)
_LoadFontTT("_Calibri", $PDF_FONT_CALIBRI)
_LoadFontTT("_Calibri1", $PDF_FONT_CALIBRI, $PDF_FONT_BOLDITALIC)
_LoadResImage("azerty", @ScriptDir & "\Tulips.jpg");chemin à vérifier
;----------------------------------------------------------------------
_BeginPage()
_SetColourFill(0xffDD00)
_DrawText(3, 28, "Insertion d'une image.", "_Calibri", 30, $PDF_ALIGN_LEFT)
_InsertRenderedText(0, 5, "Bonjour le monde", "_aria", 60, 100, $PDF_ALIGN_LEFT, 0x99AA00, 0x0000FF)
_InsertRenderedText(4, 18, "Insertion d'une image", "_Helv", 20,100, $PDF_ALIGN_CENTER,0xFF0000,0xFFFF00)
_DrawText(5, 15, "Inséré une image dans le pdf", "_Helv", 20, $PDF_ALIGN_CENTER,10)
_Draw_Rectangle(2,22,10,5, 1, 5, 0x00BFFF,0.1)
_DrawText(3, 25, "Insertion d'un texte", "_Helv", 14, $PDF_ALIGN_LEFT)
_Draw_Rectangle( 13 , 21 , 6 , 6,$PDF_STYLE_FILLED,"",0x0040FF)
_InsertImage("azerty", 13.19, 26.85,5.7)
_Paragraph($sText,2,13, 6,"_Calibri", 12) ;avec _LoadFontTT()
_SetColourFill(0xffff00)
_DrawCircle( 16 , 11 , 2)
_DrawLine(0, 14,21, 14, $PDF_STYLE_STROKED,2, 1, 0x0000FF)
_ArrayToPdf($entete, "_Calibri1", 10, 0.5, 1.5, 4, 9, 0x0000FF , "" , 0xFFFFFF)
_EndPage()
_ClosePDFFile()
; #FUNCTION# ====================================================================================================================
; Name ..........: _ArrayToPdf
; Description ...: Import un array 1D ou 2D dans un PDF
; Syntax ........: _ArrayToPdf($aArray, $AliasFont, $iX, $iY[, $iW = 0[, $iH = 0[, $sizeFont = 10[, $lTxtColor = 0x000000[,
; $lBorderColor = 0x000000[, $LineHeader = 0x79F3FD[, $LineEven = 0xFFFFD5[, $LineOdd = 0xFFFFFF[,
; $FormatNumber[,$TextScaling = 1]]]]]]]]]])
; Parameters ....: $aArray - An array of unknowns.La première valeur est $aArray[0]
; $AliasFont - valeur Alias Font par la création des Fonts.
; $iX - coordonnée X du coin inférieur gauche de l'array.
; $iY - coordonnée Y du coin inférieur gauche de l'array.
; $iW - [optional] Largeur Array. Si 0 calcul par rapport à la page Default is 0.
; $iH - [optional] Hauteur Array. Si 0 calcul par rapport à $iW Default is 0.
; $sizeFont - [optional] Taille Font. Default is 10.
; $lTxtColor - [optional] Couleur texte. Default is 0x000000.(noir)
; $lBorderColor - [optional] Couleur bordure. Default is 0x000000.(noir)
; $LineHeader - [optional] Couleur entête. Default is 0x79F3FD.(bleu clair)
; $LineEven - [optional] Couleur ligne pair. Default is 0xFFFFD5.(jaune clair)
; $LineOdd - [optional] Couleur ligne impair. Default is 0xFFFFFF.(blanc)
; $FormatNumber - [optional] Format nombre E.g. 4.3 (0231,120). Default is 0 (none)
; $TextScaling - [optional] Mise à l'échelle des valeurs dans les cells = 1, autrement = 0. Default is 1.
; Return values .: None
; Author ........: taietel
; ===============================================================================================================================
Func _ArrayToPdf($aArray, $AliasFont, $iX, $iY, $iW = 0, $iH = 0, $sizeFont = 10, $lTxtColor = 0x000000, $lBorderColor = 0x000000, $LineHeader = 0x79F3FD, $LineEven = 0xFFFFD5, $LineOdd = 0xFFFFFF, $FormatNumber = 0, $TextScaling = 1)
If Not IsArray($aArray) Then Return SetError(1, 0, 1)
$iRows = UBound($aArray)
$iCols = UBound($aArray, 2)
If $iCols = 0 Then ;si Array 1D
$aArrayclone = $aArray
ReDim $aArrayclone[$iRows][1]
$iRows = UBound($aArrayclone)
$iCols = UBound($aArrayclone, 2)
For $i = 0 To $iRows - 1
$aArrayclone[$i][0] = $aArray[$i]
Next
$aArray = $aArrayclone ;convertir en Array 2D
EndIf
If $sizeFont = "" Then $sizeFont = 10
If $iW = "" Then $iW = 0 ;largeur automatique
If $iH = "" Then $iH = 0 ;hauteur automatique
If $lTxtColor = "" Then $lTxtColor = 0x000000 ;noir
If $lBorderColor = "" Then $lBorderColor = 0x000000 ;noir
If $LineHeader = "" Then $LineHeader = 0x79F3FD ;bleu clair
If $LineEven = "" Then $LineEven = 0xFFFFD5 ;jaune clair
If $LineOdd = "" Then $LineOdd = 0xFFFFFF ;blanc
If StringInStr($FormatNumber,".") <> 0 Then ;format nombres
$fFormat = StringSplit($FormatNumber,".")
If $fFormat[0] > 2 Then Return SetError(1,0,1)
Local $iDecimal = $fFormat[2]
Local $inbNumber = $fFormat[1] + $fFormat[2] + 1
EndIf
Local $iPgW = Round(_GetPageWidth() / _GetUnit(), 1)
Local $iPgH = Round(_GetPageHeight() / _GetUnit(), 1)
If $iW = 0 Then $iW = $iPgW - $iX - 2
If $iH = 0 Then $iH = $iPgH - $iY - 2
_SetColourStroke($lBorderColor)
_Draw_Rectangle($iX, $iY, $iW, $iH, $PDF_STYLE_STROKED, 0, $lBorderColor, 0.1)
_SetColourStroke(0)
Local $iColW = $iW / $iCols
Local $iRowH = $iH / $iRows
Local $lRGB
For $i = 0 To $iRows - 1
For $j = 0 To $iCols - 1
If $i = 0 Then
$lRGB = $LineHeader ; fond cell entete
Else
If Mod($i, 2) = 0 Then ;fond ligne pair ou impair
$lRGB = $LineOdd
Else
$lRGB = $LineEven
EndIf
EndIf
_SetColourStroke($lBorderColor)
_Draw_Rectangle($iX + $j * $iColW, $iY + $iH - ($i + 1) * $iRowH, $iColW, $iRowH, $PDF_STYLE_STROKED, 0, $lRGB, 0.01)
_SetColourStroke(0)
Local $sText = $aArray[$i][$j]
If $FormatNumber <> 0 And Number($sText) <> 0 And StringLeft($sText,1) = "-" Then $sText = StringFormat("%0" & $inbNumber + 1 & ".0" & $iDecimal & "f", $sText)
If $FormatNumber <> 0 And Number($sText) <> 0 And StringLeft($sText,1) <> "-" Then $sText = StringFormat("%0" & $inbNumber & ".0" & $iDecimal & "f", $sText)
Local $sLength = Round(_GetTextLength($sText, $AliasFont, $sizeFont), 1)
$lScale = Ceiling(0.75 * $iColW * 100 / $sLength)
_SetColourFill($lTxtColor)
If $TextScaling = 1 Then _SetTextHorizontalScaling($lScale);normalise largeur contenu
_DrawText($iX + $j * $iColW + ($iColW * 9.5) / 10, $iY + $iH - ($i + 1) * $iRowH + ($iRowH - 10 / _GetUnit()) / 2, $sText, $AliasFont, $sizeFont, $PDF_ALIGN_RIGHT, 0)
_SetTextHorizontalScaling(100)
_SetColourFill(0)
Next
Next
EndFunc ;==>_ArrayToPdf
J'avais utilisé cet UDF, il y a quelques années, pour réaliser des factures. La mise en page était fastidieuse mais le résultat et l'automatisation efficace !