Jump to content

Recommended Posts

Posted
1 hour ago, faustf said:

when i open a file tell meĀ  the number of the page is not valid or not exist in a page

but when i close not ask me if i want save it

Hi again, with the script above you get a non existing page error?

What pdf reader are you using?

Posted

nitro pdf reader

i modify a pdf i show you

Func _TxtPrint()

    ;set the properties for the pdf
    _SetTitle("Fattura")
    _SetSubject("Fattura di cortesia")
    _SetKeywords("pdf, Fattura")
    _OpenAfter(True) ;open after generation
    _SetUnit($PDF_UNIT_CM)
    _SetPaperSize("A4")
    _SetZoomMode($PDF_ZOOM_CUSTOM, 90)
    _SetOrientation($PDF_ORIENTATION_PORTRAIT)
    _SetLayoutMode($PDF_LAYOUT_CONTINOUS)

    ;initialize the pdf
    _InitPDF(@ScriptDir & "\Fattura.pdf")
    ;_LoadFontTT("F1", $PDF_FONT_CALIBRI,$PDF_FONT_ITALIC)
    _LoadFontTT("_Calibri", $PDF_FONT_CALIBRI)
    _SetColourFill(0x000000)
    _SetColourStrokE(0x000000)

    ;=== create objects that are used in multiple pages ===
    _StartObject("Antet", $PDF_OBJECT_ALLPAGES) ;NOTFIRSTPAGE)
    _Draw_Rectangle(0.5, 25, 9.8, 4, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo di sinistra sede legale
    _DrawText(0.6, 28.6, "Cedente/prestatore (fornitore)", "_Calibri", 9, $PDF_ALIGN_LEFT)
    _DrawText(0.7, 28, "Identificativo fiscale ai fini IVA: ", "_Calibri", 9, $PDF_ALIGN_LEFT)
    _DrawText(0.7, 27.4, "Denominazione: ", "_Calibri", 9, $PDF_ALIGN_LEFT)
    _DrawText(0.7, 27, "Indirizzo: ", "_Calibri", 9, $PDF_ALIGN_LEFT)
    _DrawText(0.7, 26.6, "Comune: ", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere provincia
    _DrawText(0.7, 26.2, "Cap:", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione

    _Draw_Rectangle(10.7, 25, 9.8, 4, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo di destra sede  operativa


    _DrawText(10.8, 28.6, "Cessionario/committente (cliente)", "_Calibri", 9, $PDF_ALIGN_LEFT)
    _DrawText(10.9, 28, "Identificativo fiscale ai fini IVA: ", "_Calibri", 9, $PDF_ALIGN_LEFT)
    _DrawText(10.9, 27.4, "Denominazione: ", "_Calibri", 9, $PDF_ALIGN_LEFT)
    _DrawText(10.9, 27, "Indirizzo: ", "_Calibri", 9, $PDF_ALIGN_LEFT)
    _DrawText(10.9, 26.6, "Comune: ", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere provincia
    _DrawText(10.9, 26.2, "Cap:", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione
    ;   _DrawText(1.3, 28.6, "Cedente/prestatore (fornitore)", "_Calibri", 9, $PDF_ALIGN_LEFT)

    ;_Draw_Rectangle(0.5, 23.3, 20, 1.5, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    ;------------------------------------------------------------------------------------------------------------------------------------
    _Draw_Rectangle(0.5, 24.1, 6, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    _DrawText(2, 24.3, "Tipologia Documento", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione
    _Draw_Rectangle(0.5, 23.4, 6, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    _DrawText(2, 23.6, "variabile Documento", "_Calibri", 9, $PDF_ALIGN_LEFT) ; variabile documento

    _Draw_Rectangle(6.5, 24.1, 2, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    _DrawText(7, 24.3, "ART. 73", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione
    _Draw_Rectangle(6.5, 23.4, 2, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    _DrawText(7, 23.6, "var 73", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione

    _Draw_Rectangle(8.5, 24.1, 5, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    _DrawText(9.7, 24.3, "Numero documento", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione
    _Draw_Rectangle(8.5, 23.4, 5, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    _DrawText(9.7, 23.6, "variabile num documento ", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione

    _Draw_Rectangle(13.5, 24.1, 4, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    _DrawText(14.4, 24.3, "Data documento ", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione
    _Draw_Rectangle(13.5, 23.4, 4, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    _DrawText(14.4, 23.6, " var Data documento ", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione

    _Draw_Rectangle(17.5, 24.1, 3, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    _DrawText(18, 24.3, "Cod. Destinatario", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione
    _Draw_Rectangle(17.5, 23.4, 3, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    _DrawText(18, 23.6, "var Codice Destinatario", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione
    ;------------------------------------ BODY INVOICE -----------------------------------------------------------------------------------------
    _Draw_Rectangle(0.5, 22.5, 2, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    _DrawText(1, 22.8, "Cod.Art.", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione
    _Draw_Rectangle(0.5, 21.8, 2, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    _DrawText(1, 22, "var 73", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione

    _Draw_Rectangle(2.5, 22.5, 6, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    _DrawText(4.5, 22.8, "Descrizione", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione
    _Draw_Rectangle(2.5, 21.8, 6, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    _DrawText(4.5, 22, "variabile Documento", "_Calibri", 9, $PDF_ALIGN_LEFT) ; variabile documento

    _Draw_Rectangle(8.5, 22.5, 2, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    _DrawText(8.9, 22.8, "Quantita", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione
    _Draw_Rectangle(8.5, 21.8, 2, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    _DrawText(8.9, 22, "variabile qtt", "_Calibri", 9, $PDF_ALIGN_LEFT) ; variabile documento

    _Draw_Rectangle(10.5, 22.5, 2, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    _DrawText(10.8, 22.8, "prezzo unit.", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione
    _Draw_Rectangle(10.5, 21.8, 2, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    _DrawText(10.8, 22, "variabile prez", "_Calibri", 9, $PDF_ALIGN_LEFT) ; variabile documento

    _Draw_Rectangle(12.5, 22.5, 1.5, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    _DrawText(13, 22.8, "UM", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione
    _Draw_Rectangle(12.5, 21.8, 1.5, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    _DrawText(13, 22, "var UM", "_Calibri", 9, $PDF_ALIGN_LEFT) ; variabile documento

    _Draw_Rectangle(14, 22.5, 2, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    _DrawText(14.5, 22.8, "Sconto", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione
    _Draw_Rectangle(14, 21.8, 2, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    _DrawText(14.1, 22, "variabile prez", "_Calibri", 9, $PDF_ALIGN_LEFT) ; variabile documento

    _Draw_Rectangle(16, 22.5, 1.5, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    _DrawText(16.5, 22.8, "IVA", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione
    _Draw_Rectangle(16, 21.8, 1.5, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    _DrawText(16.1, 22, "var UM", "_Calibri", 9, $PDF_ALIGN_LEFT) ; variabile documento

    _Draw_Rectangle(17.5, 22.5, 3, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    _DrawText(17.9, 22.8, "Cod. Destinatario", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione
    _Draw_Rectangle(17.5, 21.1, 3, 1.4, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo y sposta di 0.7 alla volta e y allarga il doppio per incrementare le righe
    _DrawText(17.6, 22, "var Codice Destinatario", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione
    _DrawText(17.6, 21.5, "var Codice Destinatario", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione
    ;_Draw_Rectangle(0.5, 23.3, 20, 0.9, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    ;------------------------------------------------------------------------------------------------------------------------------------
    ;----------------------------------- RIEPILOGHI IVA E TOTALI ------------------------------------------------------------------------
    _Draw_Rectangle(17.5, 1.2, 3, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    _DrawText(17.8, 1.4, "Totale Documento", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione
    _Draw_Rectangle(17.5, 0.5, 3, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    _DrawText(17.9, 0.8, "Var tot docu", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione

    _Draw_Rectangle(17.5, 2.5, 3, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    _DrawText(17.9, 2.8, "Totale Imposta", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione
    _Draw_Rectangle(17.5, 1.8, 3, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    _DrawText(17.8, 2.0, "Var tot Impo", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione


    _Draw_Rectangle(14.5, 1.2, 3, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    _DrawText(14.8, 1.4, "Totale Imponibile", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione
    _Draw_Rectangle(14.5, 0.5, 3, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    _DrawText(14.9, 0.8, "Var tot docu", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione

    _Draw_Rectangle(14.5, 2.5, 3, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    _DrawText(14.9, 2.8, "Totale Imposta", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione
    _Draw_Rectangle(14.5, 1.8, 3, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    _DrawText(14.8, 2.0, "Var tot Impo", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione

    _Draw_Rectangle(11.5, 1.2, 3, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    ;_DrawText(11.8, 2.8, "Arr.", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione
    _Draw_Rectangle(11.5, 0.5, 3, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    _DrawText(11.9, 0.8, "Var Arr", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione

    _Draw_Rectangle(11.5, 2.5, 3, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    _DrawText(11.9, 2.8, "", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione
    _Draw_Rectangle(11.5, 1.8, 3, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo
    ;_DrawText(11.8, 2.0, "Var Arr", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione
    _DrawText(11.9, 2.8, "Arr.", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione

    _Draw_Rectangle(8.5, 2.5, 3, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo 1
    _DrawText(9, 2.8, "spese acc", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione
    _Draw_Rectangle(8.5, 1.8, 3, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo 2
    _DrawText(8.8, 2.0, "Var tot Impo", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione

    _Draw_Rectangle(8.5, 1.1, 3, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo 3
    _DrawText(9, 1.4, "Sconto/Maggioraz.", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione
    _Draw_Rectangle(8.5, 0.5, 3, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo 4
    _DrawText(8.9, 0.8, "Var tot docu", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione

    _Draw_Rectangle(5.5, 2.5, 3, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo 1
    _DrawText(6.8, 2.8, "IVA", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione
    _Draw_Rectangle(5.5, 1.8, 3, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo 2
    _DrawText(5.8, 2.0, "Var tot Impo", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione

    _Draw_Rectangle(5.5, 1.1, 3, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo 3
;   _DrawText(5.8, 1.4, "Sconto/Maggioraz.", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione
    _Draw_Rectangle(5.5, 0.5, 3, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo 4
    _DrawText(5.8, 0.8, "Var tot docu", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione

    _Draw_Rectangle(0.5, 2.5, 5, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo 1
    _DrawText(1.5, 2.8, "egesibilit./rif. normativo", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione
    _Draw_Rectangle(0.5, 1.8, 5, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo 2
    _DrawText(2, 2.0, "Var tot Impo", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione

    _Draw_Rectangle(0.5, 1.1, 5, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo 3
    _DrawText(2, 1.4, "Importo Bollo", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione
    _Draw_Rectangle(0.5, 0.5, 5, 0.7, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.05) ; rettangolo 4
    _DrawText(2, 0.8, "Var tot docu", "_Calibri", 9, $PDF_ALIGN_LEFT) ; da mettere nazione

;----------------------------------------------------------------------------------------------------------------------------------------




    #cs
        _SetTextHorizontalScaling(90)
        ;and begin writting some data
        _DrawText(5.2, 27.6, StringUpper("Et adipiscing nec nisi elementum natoque!"), "_Garamond", 14, $PDF_ALIGN_LEFT)
        _DrawText(5.2, 26.9, StringUpper("Dapibus scelerisque vel rhoncus porttitor!"), "_Garamond", 16, $PDF_ALIGN_LEFT)
        _SetTextHorizontalScaling(80)
        _DrawText(5.2, 26.2, "Dapibus scelerisque vel rhoncus porttitor!", "_TimesT", 12, $PDF_ALIGN_LEFT)
        _DrawText(5.2, 25.6, "Rhoncus a vut natoque pellentesque", "_TimesT", 12, $PDF_ALIGN_LEFT)
        _DrawText(5.2, 25, "taietel@yahoo.com" & "; " & "http://autoitscript.com/forum/topic/118827-create-pdf-from-your-application/", "_TimesT", 11, $PDF_ALIGN_LEFT)
        ;get the scalling back to default value
        _SetTextHorizontalScaling(100)
        ;and colour also
        _SetColourFill(0)
        ;that's the end of our header!
    #ce
    _EndObject()


    _BeginPage()
    ;that's the end of our header!



    ;_Draw_Rectangle(7, 25.5, 0, 4, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.01)
    _EndPage()
    ;write the buffer to disk
    _ClosePDFFile()
EndFunc   ;==>_TxtPrint

Ā 

Posted

:)Ā Ā  we canĀ  build aĀ  prog for create pdf layoutĀ  likeĀ  a paintĀ Ā Ā  ... but notĀ  nowĀ  soon i sureĀ  ask some help :D thankz again

  • 7 months later...
  • 2 years later...
Posted
4 hours ago, wimhek said:

Hi there,

Is it possible to create an index /table of content within the PDF document ?

Ā 

Thank You

Hi wimhek.

Ā 

This udf creates the pdf concatenating a string following the pdf standard (more info here:Ā https://www.oreilly.com/library/view/pdf-explained/9781449321581/ch04.html)

I tried to include hyperlinks to the current udf (didn't accomplished, sorry).

Ā 

The problem with the index/table is that you should create it after the rest of the elements in the pdf, so it would mean to change the way the whole udf works.

  • 5 months later...
Posted
On 10/8/2022 at 9:18 PM, Qwerty212 said:

I tried to include hyperlinks to the current udf (didn't accomplished, sorry).

Try this, see if it works:

#include "..\MPDF_UDF.au3"
#include <File.au3>

;set the properties for the pdf
_SetTitle("Link to web example")
_SetSubject("click link in pdf")
_SetKeywords("pdf, AutoIt")
_OpenAfter(True)    ;open after generation
_SetUnit($PDF_UNIT_CM)
_SetPaperSize("A4")
_SetZoomMode($PDF_ZOOM_CUSTOM, 90)
_SetOrientation($PDF_ORIENTATION_PORTRAIT)
_SetLayoutMode($PDF_LAYOUT_CONTINOUS)

;initialize the pdf
_InitPDF(@ScriptDir & "\link_in_pdf")
_LoadFontTT("fontArial", $PDF_FONT_ARIAL, $PDF_FONT_ITALIC)
_BeginPage()
_InsertLink(2, 28, "https://autoitscript.com/", "fontArial", 10)
_EndPage()
;write the buffer to disk
_ClosePDFFile()

Func _InsertLink($iX, $iY, $sURL, $sFontAlias, $iFontSize)
    __InitObj()
    _DrawText($iX, $iY, $sURL, $sFontAlias, $iFontSize)
    __EndObj()
    __InitObj()
    __ToBuffer("<</URI(" & __ToPdfStr($sURL) & ") /Type /Action /S /URI>>")
    __EndObj()
EndFunc   ;==>_InsertLink

Ā 

Posted
23 minutes ago, taietel said:

Try this, see if it works:

#include "..\MPDF_UDF.au3"
#include <File.au3>

;set the properties for the pdf
_SetTitle("Link to web example")
_SetSubject("click link in pdf")
_SetKeywords("pdf, AutoIt")
_OpenAfter(True)    ;open after generation
_SetUnit($PDF_UNIT_CM)
_SetPaperSize("A4")
_SetZoomMode($PDF_ZOOM_CUSTOM, 90)
_SetOrientation($PDF_ORIENTATION_PORTRAIT)
_SetLayoutMode($PDF_LAYOUT_CONTINOUS)

;initialize the pdf
_InitPDF(@ScriptDir & "\link_in_pdf")
_LoadFontTT("fontArial", $PDF_FONT_ARIAL, $PDF_FONT_ITALIC)
_BeginPage()
_InsertLink(2, 28, "https://autoitscript.com/", "fontArial", 10)
_EndPage()
;write the buffer to disk
_ClosePDFFile()

Func _InsertLink($iX, $iY, $sURL, $sFontAlias, $iFontSize)
    __InitObj()
    _DrawText($iX, $iY, $sURL, $sFontAlias, $iFontSize)
    __EndObj()
    __InitObj()
    __ToBuffer("<</URI(" & __ToPdfStr($sURL) & ") /Type /Action /S /URI>>")
    __EndObj()
EndFunc   ;==>_InsertLink

Ā 

Impressive.

Ā 

It works like a charm. This udf is almost 13 years old and it's probably one of the ones that I've used the most.

Ā 

Thanks a lot.

Ā 

Greets from Barcelona

  • 1 year later...
Posted (edited)


How can I print bar codes (code 128) into a pdf?

I use barcode128.au3 for generating the Code 128 string from my input string (patient name etc.)
#include <barcode128.au3> ; Much thancs to Zedna for duing this work and sharing it.

First of all I install the true type font code128.ttf with font name "Code 128" as a Win10 font.
Next I include in the MPDFF_UDF.au3 V103 the missing function _Iif and get the Example_Mixed.au3 running.Ā 
After this I tried to include the "Code 128" font:

; constant string as new font name:
Global $PDF_FONT_CODE128 = "Code 128"

; setting the font name
_LoadFontTT("_Code128", $PDF_FONT_CODE128)
; genrat test string:
    $stOut = ""
    For $i=32 To 64
        $stOut = $stOut & Chr($i)
    Next
; start a pdf page as in the example: Example_Mixed.au3    and change pdf content to:
_BeginPage()    
    ;put some text etc.
    _SetColourFill(0x000000)
    _DrawText(3, 20,  $stOut, "_Courier", 12, $PDF_ALIGN_LEFT, 0)
    _DrawText(3, 16,  $stOut, "_Code128", 12, $PDF_ALIGN_LEFT, 0)
_EndPage()


But the result is always a ASCII Char Array: !"#$%&'()*+,-./0123456789:;<=>?@, not a series of bar code letters.
How to install and use the font "Code 128" corectly to generate a pdf?

My changes in MPDFF_UDF:

; include style etc., same parameter used as at function __FontCourier
Func __FontCode128($Style = $PDF_FONT_NORMAL)
    $BaseFont = "Code 128"
    $FirstChar = 32
    $LastChar = 255
    $MissingWidth = 600
    Local $aTemp[$LastChar - $FirstChar]; + 1]
    Switch $Style
        Case $PDF_FONT_NORMAL
            $aTemp = StringSplit("600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, " & _
            "600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, " & _
            "600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, " & _
            "600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, " & _
            "600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, " & _
            "600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, " & _
            "600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, " & _
            "600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600", ", ", 3)
            $Param = "/Flags 34 /FontBBox [-250 -300 720 1000] " & _
                    "/MissingWidth 600 /StemV 109 " & _
                    "/StemH 109 /ItalicAngle 0 /CapHeight 833 /XHeight 417 " & _
                    "/Ascent 833 /Descent -300 /Leading 133 " & _
    ;...the othet 2 cases are simelar
    EndSwitch
    For $i = $FirstChar To $LastChar
        $Widths[$i] = $aTemp[$i - $FirstChar]
    Next
    Local $aRetTmp[6] = [$BaseFont, $FirstChar, $LastChar, $Param, $Widths, $MissingWidth]
    Return $aRetTmp
EndFunc   ;==>__FontCode128

; add the new case in _loadFont 
Func _LoadFontTT($sAlias, $BaseFont, $sOptions = $PDF_FONT_NORMAL)
    Local $sTemp = ""
    $_Font = $_Font + 1
    $BaseFont = StringReplace($BaseFont, " ", "")
    Switch $BaseFont
        Case "TimesNewRoman"
            __FontTimes($sOptions)
        Case "CourierNew"
            __FontCourier($sOptions)
        Case "Code128"
            __FontCode128($sOptions) ; it this seem that this is not working corectly
        Case "Symbol"
            __FontSymbol($sOptions)
        Case "Calibri"
            __FontCalibri($sOptions)
        Case "Garamond"
            __FontGaramond($sOptions)
        Case Else
            __FontArial($sOptions)
    EndSwitch
    Local $i = __InitObj()
    __ToBuffer("<< /Type/Font/Subtype/TrueType/Name/" & $sAlias & "/BaseFont/" & $BaseFont & $sOptions & "/FirstChar " & $FirstChar & "/LastChar " & $LastChar & "/FontDescriptor " & $i + 1 & " 0 R/Encoding/WinAnsiEncoding/Widths [")
    For $j = $FirstChar To $LastChar
        If $Widths[$j - $FirstChar] <> 0 Then
            $sTemp &= __ToStr($Widths[$j - $FirstChar]) & " "
            If Mod($j - $FirstChar + 1, 16) = 0 Or $j = $LastChar Then
                __ToBuffer($sTemp)
                $sTemp = ""
            EndIf
        EndIf
    Next
    __ToBuffer("] >>")
    __EndObj()
    $_sFONT = $_sFONT & "/" & $sAlias & " " & $i & " 0 R " & @CRLF
    $_sFONTNAME = $_sFONTNAME & "<" & $sAlias & ">" & StringRight("0000" & $_Font, 4) & ";"
    ;$i =
    __InitObj()
    __ToBuffer("<< /Type/FontDescriptor/FontName/" & $BaseFont & $Param & ">>")
    __EndObj()
EndFunc   ;==>_LoadFontTT

Ā 

Edited by Jos
added codeboxes
  • 3 weeks later...
  • 6 months later...

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
  • Recently Browsing   0 members

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