Jump to content

Create PDF from your application


taietel
 Share

Recommended Posts

HI all,

Thanks for the modifications with french letters...

To day, I have two new problems :

1 / it's impossible to create a pdf with the landscqpe orientation.

See code under :

------------ begin ------------------

#include "include/MPDF_UDF.au3"
_OpenAfter(True);open after generation
_SetUnit($PDF_UNIT_CM)
_SetPaperSize("A4")
_SetZoomMode($PDF_ZOOM_CUSTOM, 90)
_SetOrientation($PDF_ORIENTATION_LANDSCAPE)
_SetLayoutMode($PDF_LAYOUT_CONTINOUS)
;initialize the pdf
_InitPDF(@ScriptDir & "\test.pdf")
_LoadFontTT("_Arial", $PDF_FONT_ARIAL)
_LoadFontTT("_TimesT", $PDF_FONT_TIMES)
_LoadFontTT("_Calibri", $PDF_FONT_CALIBRI)
_LoadFontTT("_Garamond", $PDF_FONT_GARAMOND)
_BeginPage()
_DrawText(6, 20, "édition extrême", "_TimesT", 24, $PDF_ALIGN_RIGHT)
_EndPage()
;then, finally, write the buffer to disk
_ClosePDFFile()

----------- END ----------------------

2/ With "nitro reader 2.5.0.45, I get this message when opening the file :

"The requested page number is invalid and does not exist in this document"

I have no problem with acrobat... (but I use Nitro as my main reader !)

Thank you for the answer.

post-70051-0-43026000-1350499674_thumb.j

Edited by novembrezoulou
Link to comment
Share on other sites

  • 4 months later...

I found some problems using _Txt2PDF function, so I wrote this modified function that may works better:

Func __Txt2PDF($sText, $sFontAlias, $iMarginX = 2, $iMarginY = 1.5, $iLineHeight = 0.5)
Local $iUnit = _GetUnit()
Local $iPaperHeight = _GetPageHeight() / $iUnit
Local $iPaperWidth = _GetPageWidth() / $iUnit
Local $iHeight = $iPaperHeight - (2 * $iMarginY)
Local $iWidth = $iPaperWidth - (2 * $iMarginX)
Local $iLinesPerPage = Floor($iHeight / $iLineHeight)
Local $aLines = StringSplit($sText & @CRLF, @CRLF, 1)
Local $iNrPages = Ceiling($aLines[0] / $iLinesPerPage)
Local $sLength, $iCurrent, $iX, $iY
For $iPage = 1 To $iNrPages
_BeginPage()
_DrawText($iPaperWidth - 1.5, 1, $iPage, $sFontAlias, 10, $PDF_ALIGN_CENTER)
For $iLine = 1 To $iLinesPerPage
$iCurrent = $iLine + ($iPage - 1) * $iLinesPerPage
If $iCurrent > $aLines[0] Then
ExitLoop
EndIf
$iX = $iMarginX
$iY = $iMarginY + $iHeight - ($iLineHeight * $iLine)
$sLength = Round(_GetTextLength($aLines[$iCurrent], $sFontAlias, 10))
If $sLength > $iWidth - 1 Then
_SetTextHorizontalScaling(Ceiling($iWidth * 100 / $sLength))
_DrawText($iX, $iY, $aLines[$iCurrent], $sFontAlias, 10, $PDF_ALIGN_LEFT)
_SetTextHorizontalScaling(100)
Else
_DrawText($iX, $iY, $aLines[$iCurrent], $sFontAlias, 10, $PDF_ALIGN_LEFT)
EndIf
Next
_EndPage()
Next
EndFunc ;==>__Txt2PDF
Edited by Lupo73

SFTPEx, AutoCompleteInput_DateTimeStandard(), _ImageWriteResize()_GUIGraduallyHide(): some AutoIt functions.

Lupo PenSuite: all-in-one and completely free selection of portable programs and games.

DropIt: a personal assistant to automatically manage your files.

ArcThemALL!: application to multi-archive your files and folders.

Link to comment
Share on other sites

It didn't seem to work when I tried converting the current script to a PDF file.

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

It works fine for me, do you have any error with it? Is the output wrongly formatted or totally unreadable?

Note that I tested it with _SetUnit($PDF_UNIT_CM)

Edited by Lupo73

SFTPEx, AutoCompleteInput_DateTimeStandard(), _ImageWriteResize()_GUIGraduallyHide(): some AutoIt functions.

Lupo PenSuite: all-in-one and completely free selection of portable programs and games.

DropIt: a personal assistant to automatically manage your files.

ArcThemALL!: application to multi-archive your files and folders.

Link to comment
Share on other sites

Yeh I had, your output is just the location of the filepath in the PDF. The old function works as intended.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

My function receives a string in $sText instead of a file path, in this way can works also directly writing a text, without read it from a file. Is this the only problem?

SFTPEx, AutoCompleteInput_DateTimeStandard(), _ImageWriteResize()_GUIGraduallyHide(): some AutoIt functions.

Lupo PenSuite: all-in-one and completely free selection of portable programs and games.

DropIt: a personal assistant to automatically manage your files.

ArcThemALL!: application to multi-archive your files and folders.

Link to comment
Share on other sites

Oh OK.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

  • 2 weeks later...

HI all,

Thanks for the modifications with french letters...

To day, I have two new problems :

1 / it's impossible to create a pdf with the landscqpe orientation.

See code under :

------------ begin ------------------

#include "include/MPDF_UDF.au3"
_OpenAfter(True);open after generation
_SetUnit($PDF_UNIT_CM)
_SetPaperSize("A4")
_SetZoomMode($PDF_ZOOM_CUSTOM, 90)
_SetOrientation($PDF_ORIENTATION_LANDSCAPE)
_SetLayoutMode($PDF_LAYOUT_CONTINOUS)
;initialize the pdf
_InitPDF(@ScriptDir & "\test.pdf")
_LoadFontTT("_Arial", $PDF_FONT_ARIAL)
_LoadFontTT("_TimesT", $PDF_FONT_TIMES)
_LoadFontTT("_Calibri", $PDF_FONT_CALIBRI)
_LoadFontTT("_Garamond", $PDF_FONT_GARAMOND)
_BeginPage()
_DrawText(6, 20, "édition extrême", "_TimesT", 24, $PDF_ALIGN_RIGHT)
_EndPage()
;then, finally, write the buffer to disk
_ClosePDFFile()

----------- END ----------------------

2/ With "nitro reader 2.5.0.45, I get this message when opening the file :

"The requested page number is invalid and does not exist in this document"

I have no problem with acrobat... (but I use Nitro as my main reader !)

Thank you for the answer.

I got the same problem but using acrobat. Finally I used a custom document size copying the code of another user in this thread. Use this:

_SetPaperSize("CUSTOM", 841.890, 595.276); A4 landscape
_SetOrientation($PDF_ORIENTATION_PORTRAIT)

I'm using this great udf more than ever. Thanks again for sharing it with us. How can we add a new ttf font (like Code128 to create barcodes inside the created pdf)??

Thanks again.

Edited by adolfito121
Link to comment
Share on other sites

I have found a way of putting my own Code128 codebars inside the created pdf's without inserting them as an image.

All credits go for andybiochem for his Code128 Generator example:

This is andybiochem's code:

;Code 128 Barcode Generator - Andy M 2008

#include [color=#000000][font=Consolas, 'Courier New', Courier, 'Nimbus Mono L', monospace][size=2][background=rgb(248, 248, 248)]<array.au3>[/background][/size][/font][/color]
#include [color=#000000][font=Consolas, 'Courier New', Courier, 'Nimbus Mono L', monospace][size=2][background=rgb(248, 248, 248)]<file.au3>[/background][/size][/font][/color]

Opt("GUIOnEventMode", 1)


;*************************************************************************************
; Declare Vars
;*************************************************************************************

Global $array[104]
Global $CodeArray
Global $data
Global $L[1]


;*************************************************************************************
; Assign Code 128 Pattern array
;*************************************************************************************
; Items are "[Value]¬[Bcode]¬[Ccode]¬[1/0 Pattern]"

$array[1] = "0¬ ¬00¬11011001100"
$array[2] = "1¬!¬01¬11001101100"
$array[3] = '2¬"¬02¬11001100110'
$array[4] = "3¬#¬03¬10010011000"
$array[5] = "4¬$¬04¬10010001100"
$array[6] = "5¬%¬05¬10001001100"
$array[7] = "6¬&¬06¬10011001000"
$array[8] = "7¬'¬07¬10011000100"
$array[9] = "8¬(¬08¬10001100100"
$array[10] = "9¬)¬09¬11001001000"
$array[11] = "10¬*¬10¬11001000100"
$array[12] = "11¬+¬11¬11000100100"
$array[13] = "12¬,¬12¬10110011100"
$array[14] = "13¬-¬13¬10011011100"
$array[15] = "14¬.¬14¬10011001110"
$array[16] = "15¬/¬15¬10111001100"
$array[17] = "16¬0¬16¬10011101100"
$array[18] = "17¬1¬17¬10011100110"
$array[19] = "18¬2¬18¬11001110010"
$array[20] = "19¬3¬19¬11001011100"
$array[21] = "20¬4¬20¬11001001110"
$array[22] = "21¬5¬21¬11011100100"
$array[23] = "22¬6¬22¬11001110100"
$array[24] = "23¬7¬23¬11101101110"
$array[25] = "24¬8¬24¬11101001100"
$array[26] = "25¬9¬25¬11100101100"
$array[27] = "26¬:¬26¬11100100110"
$array[28] = "27¬;¬27¬11101100100"
$array[29] = "28¬<¬28¬11100110100"
$array[30] = "29¬=¬29¬11100110010"
$array[31] = "30¬>¬30¬11011011000"
$array[32] = "31¬?¬31¬11011000110"
$array[33] = "32¬@¬32¬11000110110"
$array[34] = "33¬A¬33¬10100011000"
$array[35] = "34¬B¬34¬10001011000"
$array[36] = "35¬C¬35¬10001000110"
$array[37] = "36¬D¬36¬10110001000"
$array[38] = "37¬E¬37¬10001101000"
$array[39] = "38¬F¬38¬10001100010"
$array[40] = "39¬G¬39¬11010001000"
$array[41] = "40¬H¬40¬11000101000"
$array[42] = "41¬I¬41¬11000100010"
$array[43] = "42¬J¬42¬10110111000"
$array[44] = "43¬K¬43¬10110001110"
$array[45] = "44¬L¬44¬10001101110"
$array[46] = "45¬M¬45¬10111011000"
$array[47] = "46¬N¬46¬10111000110"
$array[48] = "47¬O¬47¬10001110110"
$array[49] = "48¬P¬48¬11101110110"
$array[50] = "49¬Q¬49¬11010001110"
$array[51] = "50¬R¬50¬11000101110"
$array[52] = "51¬S¬51¬11011101000"
$array[53] = "52¬T¬52¬11011100010"
$array[54] = "53¬U¬53¬11011101110"
$array[55] = "54¬V¬54¬11101011000"
$array[56] = "55¬W¬55¬11101000110"
$array[57] = "56¬X¬56¬11100010110"
$array[58] = "57¬Y¬57¬11101101000"
$array[59] = "58¬Z¬58¬11101100010"
$array[60] = "59¬[¬59¬11100011010"
$array[61] = "60¬\¬60¬11101111010"
$array[62] = "61¬]¬61¬11001000010"
$array[63] = "62¬^¬62¬11110001010"
$array[64] = "63¬_¬63¬10100110000"
$array[65] = "64¬`¬64¬10100001100"
$array[66] = "65¬a¬65¬10010110000"
$array[67] = "66¬b¬66¬10010000110"
$array[68] = "67¬c¬67¬10000101100"
$array[69] = "68¬d¬68¬10000100110"
$array[70] = "69¬e¬69¬10110010000"
$array[71] = "70¬f¬70¬10110000100"
$array[72] = "71¬g¬71¬10011010000"
$array[73] = "72¬h¬72¬10011000010"
$array[74] = "73¬i¬73¬10000110100"
$array[75] = "74¬j¬74¬10000110010"
$array[76] = "75¬k¬75¬11000010010"
$array[77] = "76¬l¬76¬11001010000"
$array[78] = "77¬m¬77¬11110111010"
$array[79] = "78¬n¬78¬11000010100"
$array[80] = "79¬o¬79¬10001111010"
$array[81] = "80¬p¬80¬10100111100"
$array[82] = "81¬q¬81¬10010111100"
$array[83] = "82¬r¬82¬10010011110"
$array[84] = "83¬s¬83¬10111100100"
$array[85] = "84¬t¬84¬10011110100"
$array[86] = "85¬u¬85¬10011110010"
$array[87] = "86¬v¬86¬11110100100"
$array[88] = "87¬w¬87¬11110010100"
$array[89] = "88¬x¬88¬11110010010"
$array[90] = "89¬y¬89¬11011011110"
$array[91] = "90¬z¬90¬11011110110"
$array[92] = "91¬{¬91¬11110110110"
$array[93] = "92¬|¬92¬10101111000"
$array[94] = "93¬}¬93¬10100011110"
$array[95] = "94¬~¬94¬10001011110"
$array[96] = "95¬del¬95¬10111101000"
$array[97] = "96¬Fnc3¬96¬10111100010"
$array[98] = "97¬Fnc2¬97¬11110101000"
$array[99] = "98¬Shift¬98¬11110100010"
$array[100] = "99¬Code C¬99¬10111011110"
$array[101] = "100¬Fnc 4¬Code B¬10111101110"
$array[102] = "101¬Code A¬Code A¬11101011110"
$array[103] = "102¬Fnc 1¬Fnc 1¬11110101110"



;*************************************************************************************
; GUI
;*************************************************************************************

GUICreate("Code 128 (B/C) Barcode Generator - AndyBiochem 2008", 613, 286)
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")

$Input = GUICtrlCreateInput("", 8, 8, 321, 25)
GUICtrlSetFont(-1,12)

GUICtrlCreateButton("Generate Barcode", 344, 8, 257, 25)
GUICtrlSetOnEvent(-1,"MakeBarcode")

GUICtrlCreateLabel("", 8, 48, 596, 225)
GUICtrlSetBkColor(-1, 0xFFFFFF)







GUISetState(@SW_SHOW)
;#####################################################################################
; LOOP
;#####################################################################################
While 1

Sleep(100)

WEnd
;#####################################################################################
; END LOOP
;#####################################################################################



Func MakeBarcode()
;*************************************************************************************
; Delete previous barcode
;*************************************************************************************

for $i = 1 to (UBound($L) - 1)
GUICtrlDelete($L[$i])
Next



;*************************************************************************************
; Generate Pattern
;*************************************************************************************

$Barcode = IdentifyCodeSwitches(GUICtrlRead($Input))



;*************************************************************************************
; Draw new Barcode
;*************************************************************************************

Dim $L[StringLen($Barcode) + 1]

$i = 1

While $i <= StringLen($barcode)

$col = StringMid($barcode,$i,1)

if $col = 1 Then
$L[$i] = GUICtrlCreateLabel("",50 + ($i * 2),100,2,100)
GUICtrlSetBkColor(-1,0x000000)

Else
$L[$i] = GUICtrlCreateLabel("",50 + ($i * 2),100,2,100)
GUICtrlSetBkColor(-1,0xFFFFFF)

EndIf
$i += 1
WEnd

EndFunc



Func IdentifyCodeSwitches($code)
;*************************************************************************************
; Identify where code switches should be
;*************************************************************************************

$i = 1
$CodeType = "B" ;always start with code type B
$len = StringLen($Code)

While $i <= $len

Select
Case $CodeType = "B"
if StringRegExp(StringMid($Code,$i,6),"([0-9][0-9]){3}") = 1 Then
$Code = StringMid($Code,1,$i - 1) & "¬C¬" & StringMid($Code,$i)
$CodeType = "C"
$i += 6 + 3

Else
$CodeType = "B"
$i += 1
EndIf
Case $CodeType = "C"
if StringRegExp(StringMid($Code,$i,2),"([0-9][0-9])") <> 1 Then
$Code = StringMid($Code,1,$i - 1) & "¬B¬" & StringMid($Code,$i)
$CodeType = "B"
$i += 2 + 3

Else
$CodeType = "C"
$i += 2
EndIf
EndSelect

$len = StringLen($Code)

WEnd



;*************************************************************************************
; Add start code B, if not already started C
;*************************************************************************************

if StringMid($Code,1,3) <> "¬C¬" then $Code = "¬B¬" & $Code



;*************************************************************************************
; Split to array, re-assemble code switches
;*************************************************************************************

$CodeArray = StringSplit($code,"")

for $i = 1 to (UBound($CodeArray) - 3)

Select
case $CodeArray[$i] & $CodeArray[$i+1] & $CodeArray[$i+2] = "¬B¬"
$CodeArray[$i] = "[B]"
$CodeArray[$i+1] = ""
$CodeArray[$i+2] = ""

case $CodeArray[$i] & $CodeArray[$i+1] & $CodeArray[$i+2] = "¬C¬"
$CodeArray[$i] = "[C]"
$CodeArray[$i+1] = ""
$CodeArray[$i+2] = ""
EndSelect

Next



;*************************************************************************************
; Remove empty items
;*************************************************************************************

for $i = (UBound($CodeArray) - 1) to 1 step -1
if $CodeArray[$i] = "" then _ArrayDelete($CodeArray,$i)
Next



;*************************************************************************************
; Concatenate C number pairs
;*************************************************************************************

$i = 1

While $i <= (UBound($CodeArray) - 1)

if $CodeArray[$i] = "[C]" Then
$i += 1
do
if $CodeArray[$i] = "" then
$i += 1

Else
$CodeArray[$i] &= $CodeArray[$i + 1]
$CodeArray[$i + 1] = ""
$i += 1

EndIf
Until $i = (UBound($CodeArray) - 1) Or $CodeArray[$i] = "[B]" or $CodeArray[$i + 1] = "[B]"
EndIf

$i += 1

WEnd



;*************************************************************************************
; Remove empty items
;*************************************************************************************

for $i = (UBound($CodeArray) - 1) to 1 step -1
if $CodeArray[$i] = "" then _ArrayDelete($CodeArray,$i)
Next



;*************************************************************************************
; Replace Items with 128 Code Patterns, and mount checksum
;*************************************************************************************

_ArrayDelete($CodeArray,0) ;important

If $CodeArray[0] = "[B]" Then
$CodeArray[0] = "11010010000"
$SUM = 104
$CodeType = "[B]"
Else
$CodeArray[0] = "11010011100"
$SUM = 105
$CodeType = "[C]"
EndIf


for $i = 1 to (UBound($CodeArray) - 1)

if $CodeArray[$i] = "[B]" Then
$CodeArray[$i] = "10111101110"
$SUM += $i * 100
$CodeType = "[B]"
ContinueLoop
EndIf


if $CodeArray[$i] = "[C]" Then
$CodeArray[$i] = "10111011110"
$SUM += $i * 99
$CodeType = "[C]"
ContinueLoop
EndIf


for $j = 1 to (UBound($array) - 1)

$data = StringSplit($array[$j],"¬")

Select
case $CodeType = "[B]"

if $CodeArray[$i] == $data[2] Then
$CodeArray[$i] = $data[4]
$SUM += $i * $data[1]

EndIf

case $CodeType = "[C]"

if $CodeArray[$i] == $data[3] Then
$CodeArray[$i] = $data[4]
$SUM += $i * $data[1]

EndIf
EndSelect
Next



Next



;*************************************************************************************
; Calculate & find checksum item
;*************************************************************************************

$ChecksumItem = Mod($SUM,103)

$data = StringSplit($array[$ChecksumItem + 1],"¬")

_ArrayAdd($CodeArray,$data[4])



;*************************************************************************************
; Add stop item
;*************************************************************************************

_ArrayAdd($CodeArray,"1100011101011")



;*************************************************************************************
; Flatten array
;*************************************************************************************

$CodeArrayString = _ArrayToString($CodeArray,"")


Return $CodeArrayString

EndFunc



func close()
;*************************************************************************************
; Bye bye
;*************************************************************************************
Exit
EndFunc

Notice that he draws the codebar inside a GUI code using labels:

;*************************************************************************************
; Draw new Barcode
;*************************************************************************************

Dim $L[StringLen($Barcode) + 1]

$i = 1

While $i <= StringLen($barcode)

$col = StringMid($barcode,$i,1)

if $col = 1 Then
$L[$i] = GUICtrlCreateLabel("",50 + ($i * 2),100,2,100)
GUICtrlSetBkColor(-1,0x000000)

Else
$L[$i] = GUICtrlCreateLabel("",50 + ($i * 2),100,2,100)
GUICtrlSetBkColor(-1,0xFFFFFF)

EndIf
$i += 1
WEnd

EndFunc

If we want to insert the barcode inside our pdf we can create lines instead of colored labels.

Here is a working example:

#include <MPDF_UDF.au3>
#include <array.au3>
#include <file.au3>

;*************************************************************************************
; Declare Vars
;*************************************************************************************

Global $array[104]
Global $CodeArray
Global $data
Global $L[1]

;*************************************************************************************
; Assign Code 128 Pattern array
;*************************************************************************************
; Items are "[Value]¬[Bcode]¬[Ccode]¬[1/0 Pattern]"

$array[1] = "0¬ ¬00¬11011001100"
$array[2] = "1¬!¬01¬11001101100"
$array[3] = '2¬"¬02¬11001100110'
$array[4] = "3¬#¬03¬10010011000"
$array[5] = "4¬$¬04¬10010001100"
$array[6] = "5¬%¬05¬10001001100"
$array[7] = "6¬&¬06¬10011001000"
$array[8] = "7¬'¬07¬10011000100"
$array[9] = "8¬(¬08¬10001100100"
$array[10] = "9¬)¬09¬11001001000"
$array[11] = "10¬*¬10¬11001000100"
$array[12] = "11¬+¬11¬11000100100"
$array[13] = "12¬,¬12¬10110011100"
$array[14] = "13¬-¬13¬10011011100"
$array[15] = "14¬.¬14¬10011001110"
$array[16] = "15¬/¬15¬10111001100"
$array[17] = "16¬0¬16¬10011101100"
$array[18] = "17¬1¬17¬10011100110"
$array[19] = "18¬2¬18¬11001110010"
$array[20] = "19¬3¬19¬11001011100"
$array[21] = "20¬4¬20¬11001001110"
$array[22] = "21¬5¬21¬11011100100"
$array[23] = "22¬6¬22¬11001110100"
$array[24] = "23¬7¬23¬11101101110"
$array[25] = "24¬8¬24¬11101001100"
$array[26] = "25¬9¬25¬11100101100"
$array[27] = "26¬:¬26¬11100100110"
$array[28] = "27¬;¬27¬11101100100"
$array[29] = "28¬<¬28¬11100110100"
$array[30] = "29¬=¬29¬11100110010"
$array[31] = "30¬>¬30¬11011011000"
$array[32] = "31¬?¬31¬11011000110"
$array[33] = "32¬@¬32¬11000110110"
$array[34] = "33¬A¬33¬10100011000"
$array[35] = "34¬B¬34¬10001011000"
$array[36] = "35¬C¬35¬10001000110"
$array[37] = "36¬D¬36¬10110001000"
$array[38] = "37¬E¬37¬10001101000"
$array[39] = "38¬F¬38¬10001100010"
$array[40] = "39¬G¬39¬11010001000"
$array[41] = "40¬H¬40¬11000101000"
$array[42] = "41¬I¬41¬11000100010"
$array[43] = "42¬J¬42¬10110111000"
$array[44] = "43¬K¬43¬10110001110"
$array[45] = "44¬L¬44¬10001101110"
$array[46] = "45¬M¬45¬10111011000"
$array[47] = "46¬N¬46¬10111000110"
$array[48] = "47¬O¬47¬10001110110"
$array[49] = "48¬P¬48¬11101110110"
$array[50] = "49¬Q¬49¬11010001110"
$array[51] = "50¬R¬50¬11000101110"
$array[52] = "51¬S¬51¬11011101000"
$array[53] = "52¬T¬52¬11011100010"
$array[54] = "53¬U¬53¬11011101110"
$array[55] = "54¬V¬54¬11101011000"
$array[56] = "55¬W¬55¬11101000110"
$array[57] = "56¬X¬56¬11100010110"
$array[58] = "57¬Y¬57¬11101101000"
$array[59] = "58¬Z¬58¬11101100010"
$array[60] = "59¬[¬59¬11100011010"
$array[61] = "60¬\¬60¬11101111010"
$array[62] = "61¬]¬61¬11001000010"
$array[63] = "62¬^¬62¬11110001010"
$array[64] = "63¬_¬63¬10100110000"
$array[65] = "64¬`¬64¬10100001100"
$array[66] = "65¬a¬65¬10010110000"
$array[67] = "66¬b¬66¬10010000110"
$array[68] = "67¬c¬67¬10000101100"
$array[69] = "68¬d¬68¬10000100110"
$array[70] = "69¬e¬69¬10110010000"
$array[71] = "70¬f¬70¬10110000100"
$array[72] = "71¬g¬71¬10011010000"
$array[73] = "72¬h¬72¬10011000010"
$array[74] = "73¬i¬73¬10000110100"
$array[75] = "74¬j¬74¬10000110010"
$array[76] = "75¬k¬75¬11000010010"
$array[77] = "76¬l¬76¬11001010000"
$array[78] = "77¬m¬77¬11110111010"
$array[79] = "78¬n¬78¬11000010100"
$array[80] = "79¬o¬79¬10001111010"
$array[81] = "80¬p¬80¬10100111100"
$array[82] = "81¬q¬81¬10010111100"
$array[83] = "82¬r¬82¬10010011110"
$array[84] = "83¬s¬83¬10111100100"
$array[85] = "84¬t¬84¬10011110100"
$array[86] = "85¬u¬85¬10011110010"
$array[87] = "86¬v¬86¬11110100100"
$array[88] = "87¬w¬87¬11110010100"
$array[89] = "88¬x¬88¬11110010010"
$array[90] = "89¬y¬89¬11011011110"
$array[91] = "90¬z¬90¬11011110110"
$array[92] = "91¬{¬91¬11110110110"
$array[93] = "92¬|¬92¬10101111000"
$array[94] = "93¬}¬93¬10100011110"
$array[95] = "94¬~¬94¬10001011110"
$array[96] = "95¬del¬95¬10111101000"
$array[97] = "96¬Fnc3¬96¬10111100010"
$array[98] = "97¬Fnc2¬97¬11110101000"
$array[99] = "98¬Shift¬98¬11110100010"
$array[100] = "99¬Code C¬99¬10111011110"
$array[101] = "100¬Fnc 4¬Code B¬10111101110"
$array[102] = "101¬Code A¬Code A¬11101011110"
$array[103] = "102¬Fnc 1¬Fnc 1¬11110101110"

Local $Inputdata = InputBox("Codebar Example", "Type the data to be codified into the codebar")
If @error = 1 Then
Exit
Else
Global $Barcodedata = IdentifyCodeSwitches($Inputdata)
_SetTitle("Codebar example")
_SetUnit($PDF_UNIT_CM)
_SetPaperSize("A4")
_SetZoomMode($PDF_ZOOM_FULLPAGE)
_SetOrientation($PDF_ORIENTATION_PORTRAIT)
_SetLayoutMode($PDF_LAYOUT_CONTINOUS)
_OpenAfter(True)
_InitPDF(@ScriptDir & "\Codebar Example.pdf")
_BeginPage()
Dim $L[StringLen($Barcodedata) + 1]

$i = 1
Local $pixelcm = 0.06 ; here we define the width of the lines that form the codebar. Adjust depending on the space that you'll have
While $i <= StringLen($Barcodedata)

$col = StringMid($Barcodedata, $i, 1)

If $col = 1 Then
$L[$i] = _DrawLine(3 + ($i * $pixelcm), 29, 3 + ($i * $pixelcm), 27, $pixelcm, $PDF_STYLE_STROKED, $pixelcm, 0x000000) ; adjust the position of the lines depending on where do you need the codebar in the page.
Else
$L[$i] = _DrawLine(3 + ($i * $pixelcm), 29, 3 + ($i * $pixelcm), 27, $pixelcm, $PDF_STYLE_STROKED, $pixelcm, 0xffFFFF)
EndIf
$i += 1
Sleep(30)
WEnd




_EndPage()
_ClosePDFFile()
Exit
EndIf

Func IdentifyCodeSwitches($code)
;*************************************************************************************
; Identify where code switches should be
;*************************************************************************************

$i = 1
$CodeType = "B" ;always start with code type B
$len = StringLen($code)

While $i <= $len
Sleep(20)
Select
Case $CodeType = "B"
If StringRegExp(StringMid($code, $i, 6), "([0-9][0-9]){3}") = 1 Then
$code = StringMid($code, 1, $i - 1) & "¬C¬" & StringMid($code, $i)
$CodeType = "C"
$i += 6 + 3

Else
$CodeType = "B"
$i += 1
EndIf
Case $CodeType = "C"
If StringRegExp(StringMid($code, $i, 2), "([0-9][0-9])") <> 1 Then
$code = StringMid($code, 1, $i - 1) & "¬B¬" & StringMid($code, $i)
$CodeType = "B"
$i += 2 + 3

Else
$CodeType = "C"
$i += 2
EndIf
EndSelect

$len = StringLen($code)

WEnd



;*************************************************************************************
; Add start code B, if not already started C
;*************************************************************************************

If StringMid($code, 1, 3) <> "¬C¬" Then $code = "¬B¬" & $code



;*************************************************************************************
; Split to array, re-assemble code switches
;*************************************************************************************

$CodeArray = StringSplit($code, "")

For $i = 1 To (UBound($CodeArray) - 3)

Select
Case $CodeArray[$i] & $CodeArray[$i + 1] & $CodeArray[$i + 2] = "¬B¬"
$CodeArray[$i] = "[B]"
$CodeArray[$i + 1] = ""
$CodeArray[$i + 2] = ""

Case $CodeArray[$i] & $CodeArray[$i + 1] & $CodeArray[$i + 2] = "¬C¬"
$CodeArray[$i] = "[C]"
$CodeArray[$i + 1] = ""
$CodeArray[$i + 2] = ""
EndSelect

Next



;*************************************************************************************
; Remove empty items
;*************************************************************************************

For $i = (UBound($CodeArray) - 1) To 1 Step -1
If $CodeArray[$i] = "" Then _ArrayDelete($CodeArray, $i)
Next



;*************************************************************************************
; Concatenate C number pairs
;*************************************************************************************

$i = 1

While $i <= (UBound($CodeArray) - 1)

If $CodeArray[$i] = "[C]" Then
$i += 1
Do
If $CodeArray[$i] = "" Then
$i += 1

Else
$CodeArray[$i] &= $CodeArray[$i + 1]
$CodeArray[$i + 1] = ""
$i += 1

EndIf
Until $i = (UBound($CodeArray) - 1) Or $CodeArray[$i] = "[B]" Or $CodeArray[$i + 1] = "[B]"
EndIf

$i += 1

WEnd



;*************************************************************************************
; Remove empty items
;*************************************************************************************

For $i = (UBound($CodeArray) - 1) To 1 Step -1
If $CodeArray[$i] = "" Then _ArrayDelete($CodeArray, $i)
Next



;*************************************************************************************
; Replace Items with 128 Code Patterns, and mount checksum
;*************************************************************************************

_ArrayDelete($CodeArray, 0) ;important

If $CodeArray[0] = "[B]" Then
$CodeArray[0] = "11010010000"
$SUM = 104
$CodeType = "[B]"
Else
$CodeArray[0] = "11010011100"
$SUM = 105
$CodeType = "[C]"
EndIf


For $i = 1 To (UBound($CodeArray) - 1)

If $CodeArray[$i] = "[B]" Then
$CodeArray[$i] = "10111101110"
$SUM += $i * 100
$CodeType = "[B]"
ContinueLoop
EndIf


If $CodeArray[$i] = "[C]" Then
$CodeArray[$i] = "10111011110"
$SUM += $i * 99
$CodeType = "[C]"
ContinueLoop
EndIf


For $j = 1 To (UBound($array) - 1)

$data = StringSplit($array[$j], "¬")

Select
Case $CodeType = "[B]"

If $CodeArray[$i] == $data[2] Then
$CodeArray[$i] = $data[4]
$SUM += $i * $data[1]

EndIf

Case $CodeType = "[C]"

If $CodeArray[$i] == $data[3] Then
$CodeArray[$i] = $data[4]
$SUM += $i * $data[1]

EndIf
EndSelect
Next



Next



;*************************************************************************************
; Calculate & find checksum item
;*************************************************************************************

$ChecksumItem = Mod($SUM, 103)

$data = StringSplit($array[$ChecksumItem + 1], "¬")

_ArrayAdd($CodeArray, $data[4])



;*************************************************************************************
; Add stop item
;*************************************************************************************

_ArrayAdd($CodeArray, "1100011101011")



;*************************************************************************************
; Flatten array
;*************************************************************************************

$CodeArrayString = _ArrayToString($CodeArray, "")


Return $CodeArrayString

EndFunc ;==>IdentifyCodeSwitches

As said above all credits go for andybiochem. Apologizes for my coding skills, I know that my code looks awful and can be writted better. It works for me and I thought that someone could find interesting to have a code bar created directly in the pdf (you can zoom it as much as you want, it will always look great).

You can check your created codebars with websites like: http://www.onlinebarcodereader.com/

Greets from Barcelona

Edited by adolfito121
Link to comment
Share on other sites

  • 2 months later...
  • 1 month later...

Problem solved.. very strange no one else reported it before...

In MPDF_UDF.au3

Search for Func _InitPDF($sFileName = "")

and add $_Pages = 0 between Func _InitPDF($sFileName = "") and __ToBuffer($PDF_VERSION)

Func _InitPDF($sFileName = "")
    $_Pages = 0
    __ToBuffer($PDF_VERSION)
    $_iMaxObject = 0
    __InitObj(1)
    __ToBuffer("<</Title(" & __ToPdfStr($PDF_TITLE) & ")/Author(" & __ToPdfStr($PDF_AUTHOR) & ")/Creator(" & __ToPdfStr($PDF_CREATOR) & ")/Producer(" & __ToPdfStr($PDF_COPYRIGHT) & ") /Keywords(" & __ToPdfStr($PDF_KEYWORDS) & ")/Subject(" & __ToPdfStr($PDF_SUBJECT) & ")/CreationDate(D:" & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & "+02'00')/ModDate()>>")
    __EndObj()
    __InitObj(2)
    __ToBuffer("<</Type/Catalog/Pages 3 0 R")
    Switch $_LayoutMode
        Case $PDF_LAYOUT_SINGLE
            __ToBuffer("/PageLayout /SinglePage")
        Case $PDF_LAYOUT_CONTINOUS
            __ToBuffer("/PageLayout /OneColumn")
        Case $PDF_LAYOUT_TWO
            __ToBuffer("/PageLayout /TwoColumnLeft")
    EndSwitch
    Switch $_ZoomMode
        Case $PDF_ZOOM_FULLPAGE
            __ToBuffer("/OpenAction [1 0 R /Fit]")
        Case $PDF_ZOOM_FULLWIDTH
            __ToBuffer("/OpenAction [1 0 R null /FitH]")
        Case $PDF_ZOOM_REAL
            __ToBuffer("/OpenAction [1 0 R /XYZ null " & $_PageHeight & " 1]")
        Case Int($_ZoomMode)
            __ToBuffer("/OpenAction [1 0 R /XYZ null " & $_PageHeight & " " & StringReplace(StringFormat($_ZoomMode, "###0." & 2), ",", ".") / 100 & "]")
    EndSwitch
    __ToBuffer("/PageMode/UseNone/Lang (en) >>")
    __EndObj()
    $_iMaxObject = 4;4;VERIFICA AICIIIIIIIIIIIIIIIIIIIII
    $PDF_NAME = $sFileName
EndFunc   ;==>_InitPDF

Best regards,Emiel Wieldraaijer

Link to comment
Share on other sites

  • 3 weeks later...
  • 1 month later...

My guess is that it's to be expected. The Acrobat format keeps changing. With each new version, changes are made to the way text and graphics are handled. Files that have an older format are updated to a new format, and Acrobat prompts the user to save the updates. This UDF produces files that are for an older format.

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...