Sign in to follow this  
Followers 0
Tam0r

_StringToPDF

11 posts in this topic

#1 ·  Posted (edited)

Hi Folks.

I've written this UDF based on a scipt of Christian Korittke with which you can write a string in a PDF file. You can specify some format of the PDF like font size and type, spacing to the edge a.s.o. Further functions like exact coordinates of the string in the PDF will be included soon.

Would you please test it and give feedback to me so I can fix errors and enhance the function?

; Function Name:    _StringToPDF()
; Description:      Create PDF File
; Parameter(s):     $Text               - Text in the PDF (I love Autoit)
;                   $File               - Path and Filename of the PDF (c:\Test.pdf)
;                   $Size               - Papersize A4 or A3
;                   $Rand_x             - Spacing between the text and the vertical edges, Default 20
;                   $Rand_y             - Spacing between the text and the horizontal edges, Default 24
;                   $Schriftart         - Fonts (Times-Roman, Helvetica and Courier), Default Courier
;                   $Fett               - Value if the font is bold, Default 0 (normal)
;                   $Kursiv             - Value if the font is italic, Default 0 (normal)
;                   $Schrift            - Size of the font, Default 12
;                   $Autor              - Name of the autor, Default "unknown"
;                   $Titel              - Title of the PDF, Default "MyPDF"
;
; Author(s):        Christian Korittke <Christian_Korittke@web.de>
;                   Tamer Hosgör <Tamer@TamTech.info>



Func _StringToPDF ( $Text, $File, $Size="A4", $Rand_x=20, $Rand_y=24, $Schriftart="Courier", $Fett=0, $Kursiv=0, $Schrift=12, $Autor="unknown", $Titel="MyPDF")
    
    If $Size        = "A4" Then
        $Size_x     = 210
        $Size_y     = 297
    ElseIf $Size    = "A3" Then
        $Size_x     = 420
        $Size_y     = 297
    EndIf
    
               $Zeilen      =   1
    
    If $Fett = 1 Or $Kursiv = 1 Then
        If $Schriftart = "Times-Roman" Then
            If $Fett = 1 Then
                $Schriftart = "Times-Bold"
            ElseIf $Kursiv = 1 Then
                $Schriftart = "Times-Italic"
            EndIf
            If $Fett = 1 And $Kursiv = 1 Then $Schriftart =  "Times-BoldItalic"
        ElseIf $Schriftart = "Helvetica" Then
            If $Fett = 1 Then
                $Schriftart = "Helvetica-Bold"
            ElseIf $Kursiv = 1 Then
                $Schriftart = "Helvetica-Oblique"
            EndIf
            If $Fett = 1 And $Kursiv = 1 Then $Schriftart =  "Helvetica-BoldOblique"
        Else
            If $Fett = 1 Then
                $Schriftart = "Courier-Bold"
            ElseIf $Kursiv = 1 Then
                $Schriftart = "Courier-Oblique"
            EndIf
            If $Fett = 1 And $Kursiv = 1 Then $Schriftart =  "Courier-BoldOblique"
        EndIf
    EndIf
    
    
    If $Schrift     = 8 Then
        $Abstand    = 9
    ElseIf $Schrift = 9 Then
        $Abstand    = 11
    ElseIf $Schrift = 10 Then
        $Abstand    = 12
    ElseIf $Schrift = 11 Then
        $Abstand    = 13
    ElseIf $Schrift = 12 Then
        $Abstand    = 15
    ElseIf $Schrift = 14 Then
        $Abstand    = 17
    ElseIf $Schrift = 16 Then
        $Abstand    = 19
    ElseIf $Schrift = 18 Then
        $Abstand    = 21
    ElseIf $Schrift = 20 Then
        $Abstand    = 24
    ElseIf $Schrift = 22 Then
        $Abstand    = 26
    ElseIf $Schrift = 24 Then
        $Abstand    = 28
    ElseIf $Schrift = 26 Then
        $Abstand    = 30
    ElseIf $Schrift = 28 Then
        $Abstand    = 32
    ElseIf $Schrift = 36 Then
        $Abstand    = 41
    ElseIf $Schrift = 48 Then
        $Abstand    = 55
    EndIf
    

    







    If Not StringInStr($Text,@CRLF) = 0 Then
        $Text = StringSplit($Text,@CRLF)
        $Zeilen = $Text[0] / 2 + 1
    EndIf   

    ; Umrechnung
    $Wert           = 2.834175
    $Size_y         = Round($Size_y * $Wert)
    $Size_x         = Round($Size_x * $Wert)
    $Rand_x         = Round($Rand_x * $Wert)
    $Rand_y         = Round($Rand_y * $Wert)

    FileWriteLine($File,"%PDF-1.2")
    FileWriteLine($File,"%âãÏÓ")

    FileWriteLine($File,"1 0 obj")
    FileWriteLine($File,"<<")
    FileWriteLine($File,"/Author ("&$Autor&")")
    FileWriteLine($File,"/CreationDate (D:"&@YEAR&@MON&@MDAY&@HOUR&@MIN&@SEC&")")
    FileWriteLine($File,"/Creator (Ahnungslos)")
    FileWriteLine($File,"/Producer (Ahnungslos)")
    FileWriteLine($File,"/Title ("&$Titel&")")
    FileWriteLine($File,">>")
    FileWriteLine($File,"endobj")

    FileWriteLine($File,"4 0 obj")
    FileWriteLine($File,"<<")
    FileWriteLine($File,"/Type /Font")
    FileWriteLine($File,"/Subtype /Type1")
    FileWriteLine($File,"/Name /F1")
    FileWriteLine($File,"/Encoding 5 0 R")
    FileWriteLine($File,"/BaseFont /"&$Schriftart)
    FileWriteLine($File,">>")
    FileWriteLine($File,"endobj")

    FileWriteLine($File,"5 0 obj")
    FileWriteLine($File,"<<")
    FileWriteLine($File,"/Type /Encoding")
    FileWriteLine($File,"/BaseEncoding /WinAnsiEncoding")
    FileWriteLine($File,">>")
    FileWriteLine($File,"endobj")

    FileWriteLine($File,"6 0 obj")
    FileWriteLine($File,"<<")
    FileWriteLine($File,"  /Font << /F1 4 0 R >>")
    FileWriteLine($File,"  /ProcSet [ /PDF /Text ]")
    FileWriteLine($File,">>")
    FileWriteLine($File,"endobj")

    FileWriteLine($File,"7 0 obj")
    FileWriteLine($File,"<<")
    FileWriteLine($File,"/Type /Page")
    FileWriteLine($File,"/Parent 3 0 R")
    FileWriteLine($File,"/Resources 6 0 R")
    FileWriteLine($File,"/Contents 8 0 R")
    FileWriteLine($File,"/Rotate 0")
    FileWriteLine($File,">>")
    FileWriteLine($File,"endobj")

    FileWriteLine($File,"8 0 obj")
    FileWriteLine($File,"<<")
    FileWriteLine($File,"/Length 9 0 R")
    FileWriteLine($File,">>")
    FileWriteLine($File,"stream")
    FileWriteLine($File,"BT")
        
    If $Zeilen = 1 Then
        FileWriteLine($File,"/F1 "&$Schrift&" Tf")
        FileWriteLine($File,"1 0 0 1 "&$Rand_y&" "&$Size_y - $Rand_x - $Abstand&" Tm")
        FileWriteLine($File,"("&$Text&") Tj")
    Else
        For $Counter = 1 To $Zeilen
            FileWriteLine($File,"/F1 "&$Schrift&" Tf")
            FileWriteLine($File,"1 0 0 1 "&$Rand_y&" "&$Size_y - $Rand_x - $Abstand * $Counter&" Tm")
            FileWriteLine($File,"("&$Text[$Counter * 2 - 1]&") Tj")
        Next
    EndIf

    FileWriteLine($File,"ET")
    FileWriteLine($File,"endstream")
    FileWriteLine($File,"endobj")

    FileWriteLine($File,"9 0 obj")
    FileWriteLine($File,"78")
    FileWriteLine($File,"endobj")

    FileWriteLine($File,"2 0 obj")
    FileWriteLine($File,"<<")
    FileWriteLine($File,"/Type /Catalog")
    FileWriteLine($File,"/Pages 3 0 R")
    FileWriteLine($File,">>")
    FileWriteLine($File,"endobj")

    FileWriteLine($File,"3 0 obj")
    FileWriteLine($File,"<<")
    FileWriteLine($File,"/Type /Pages")
    FileWriteLine($File,"/Count 1")
    FileWriteLine($File,"/MediaBox [ 0 0 "&$Size_x&" "&$Size_y&" ]")
    FileWriteLine($File,"/Kids [ 7 0 R ]")
    FileWriteLine($File,">>")
    FileWriteLine($File,"endobj")

    FileWriteLine($File,"0 10")
    FileWriteLine($File,"0000000000 65535 f ")
    FileWriteLine($File,"0000000013 00000 n ")
    FileWriteLine($File,"0000000591 00000 n ")
    FileWriteLine($File,"0000000634 00000 n ")
    FileWriteLine($File,"0000000156 00000 n ")
    FileWriteLine($File,"0000000245 00000 n ")
    FileWriteLine($File,"0000000307 00000 n ")
    FileWriteLine($File,"0000000372 00000 n ")
    FileWriteLine($File,"0000000453 00000 n ")
    FileWriteLine($File,"0000000576 00000 n ")
    FileWriteLine($File,"trailer")
    FileWriteLine($File,"<<")
    FileWriteLine($File,"/Size 10")
    FileWriteLine($File,"/Root 2 0 R")
    FileWriteLine($File,"/Info 1 0 R")
    FileWriteLine($File,">>")
    FileWriteLine($File,"startxref")
    FileWriteLine($File,"712")
    FileWriteLine($File,"%%EOF")

    FileClose($File)

EndFunc
Edited by Tam0r
1 person likes this

Share this post


Link to post
Share on other sites



I would set the defaults in the function definition:

Func _StringToPDF ( $Text, $File, $Size="A4", $Rand_x=20, $Rand_y=24, $Schriftart="Courier", $Fett=0, $Kursiv=0, $Schrift=12, $Autor="unknown", $Titel="MyPDF")

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Share this post


Link to post
Share on other sites

this is cool. Now that you got the function, write a full blown PDF maker. :P

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

Thanks for the feedback.

Here's the script of Christian Korittke from a german AutoIt-Forum, followed by the link to the post.

#include <GUIConstants.au3>

GUICreate("PDF-Creator",500,520)
GUICtrlCreateGroup("Seitenformat",10,30,170,70)
GUICtrlCreateGroup("Rand (mm)",190,30,105,70)
GUICtrlCreateGroup("Schriftformat",315,30,175,70)
GUICtrlCreateRadio("Querformat",20,70)
GUICtrlCreateLabel("Autor:",10,475,100,20)
GUICtrlCreateLabel("Titel:",120,475,100,20)
GUICtrlCreateLabel("links:",200,50,30,20)
GUICtrlCreateLabel("oben:",200,75,30,20)

$Start          =   GUICtrlCreateButton("erzeuge PDF",370,480,120,30)
                    GUICtrlSetFont(-1,11,600)
$Autor          =   GUICtrlCreateInput("",10,490,100,20)
$Titel          =   GUICtrlCreateInput("",120,490,100,20)
$Text           =   GUICtrlCreateEdit("Bitte geben sie hier Ihren Text ein.",10,120,480,345) 
$Schrift        =   GUICtrlCreateCombo("8",325,48,45,20)
                    GUICtrlSetData(-1,"9|10|11|12|14|16|18|20|22|24|26|28|36|48|72","12")
$Schriftart     =   GUICtrlCreateCombo("Times-Roman",380,48,100,20)
                    GUICtrlSetData(-1,"Helvetica|Courier","Times-Roman")
$Size           =   GUICtrlCreateCombo("A4",110,60,50,20)
                    GUICtrlSetData(-1,"A3","A4")
$Format         =   GUICtrlCreateRadio("Hochformat",20,50)
                    GUICtrlSetState(-1,$GUI_CHECKED)
$Rand_y         =   GUICtrlCreateInput("24",240,48,45,20)
                    GUICtrlCreateUpdown(-1)
                    GUICtrlSetLimit(-1,999,0)
$Rand_x         =   GUICtrlCreateInput("25",240,72,45,20)
                    GUICtrlCreateUpdown(-1)
                    GUICtrlSetLimit(-1,999,0)
$Fett           =   GUICtrlCreateCheckbox("Fett",325,73,35,20)
$Kursiv         =   GUICtrlCreateCheckbox("Kursiv",370,73,60,20)

GUISetState ()
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then Exit
    If $msg = $Start Then ExitLoop
WEnd
    
$Pfad           =   FileSaveDialog("Speichern",@DesktopDir,"PDF (*.pdf)",16)
If StringRight($Pfad,4) = ".pdf" Then
Else
    $Pfad = $Pfad & ".pdf"
EndIf

$Fett           =   GUICtrlRead($Fett)
$Kursiv         =   GUICtrlRead($Kursiv)
$Schriftart     =   GUICtrlRead($Schriftart)
$Rand_x         =   GUICtrlRead($Rand_x)
$Rand_y         =   GUICtrlRead($Rand_y)
$Format         =   GUICtrlRead($Format)
$Autor          =   GUICtrlRead($Autor)
$Titel          =   GUICtrlRead($Titel)
$Size           =   GUICtrlRead($Size)
$Text           =   GUICtrlRead($Text)
$Schrift        =   GUICtrlRead($Schrift)
                    FileDelete($Pfad)
$File           =   FileOpen($Pfad, 1)
$Zeilen         =   1

If $Size        = "A4" Then
    $Size_x     = 210
    $Size_y     = 297
ElseIf $Size    = "A3" Then
    $Size_x     = 297
    $Size_y     = 420
EndIf

If $Fett = $GUI_CHECKED Or $Kursiv = $GUI_CHECKED Then
    If $Schriftart = "Times-Roman" Then
        If $Fett = $GUI_CHECKED Then
            $Schriftart = "Times-Bold"
        ElseIf $Kursiv = $GUI_CHECKED Then
            $Schriftart = "Times-Italic"
        EndIf
        If $Fett = $GUI_CHECKED And $Kursiv = $GUI_CHECKED Then $Schriftart =  "Times-BoldItalic"
    ElseIf $Schriftart = "Helvetica" Then
        If $Fett = $GUI_CHECKED Then
            $Schriftart = "Helvetica-Bold"
        ElseIf $Kursiv = $GUI_CHECKED Then
            $Schriftart = "Helvetica-Oblique"
        EndIf
        If $Fett = $GUI_CHECKED And $Kursiv = $GUI_CHECKED Then $Schriftart =  "Helvetica-BoldOblique"
    Else
        If $Fett = $GUI_CHECKED Then
            $Schriftart = "Courier-Bold"
        ElseIf $Kursiv = $GUI_CHECKED Then
            $Schriftart = "Courier-Oblique"
        EndIf
        If $Fett = $GUI_CHECKED And $Kursiv = $GUI_CHECKED Then $Schriftart =  "Courier-BoldOblique"
    EndIf
EndIf

If $Format      = $GUI_UNCHECKED Then
    $Size       = $Size_x
    $Size_x     = $Size_y
    $Size_y     = $Size
EndIf

If $Schrift     = 8 Then
    $Abstand    = 9
ElseIf $Schrift = 9 Then
    $Abstand    = 11
ElseIf $Schrift = 10 Then
    $Abstand    = 12
ElseIf $Schrift = 11 Then
    $Abstand    = 13
ElseIf $Schrift = 12 Then
    $Abstand    = 15
ElseIf $Schrift = 14 Then
    $Abstand    = 17
ElseIf $Schrift = 16 Then
    $Abstand    = 19
ElseIf $Schrift = 18 Then
    $Abstand    = 21
ElseIf $Schrift = 20 Then
    $Abstand    = 24
ElseIf $Schrift = 22 Then
    $Abstand    = 26
ElseIf $Schrift = 24 Then
    $Abstand    = 28
ElseIf $Schrift = 26 Then
    $Abstand    = 30
ElseIf $Schrift = 28 Then
    $Abstand    = 32
ElseIf $Schrift = 36 Then
    $Abstand    = 41
ElseIf $Schrift = 48 Then
    $Abstand    = 55
Else
    $Abstand    = 83
EndIf

If Not StringInStr($Text,@CRLF) = 0 Then
    $Text = StringSplit($Text,@CRLF)
    $Zeilen = $Text[0] / 2 + 1
EndIf

; Umrechnung
$Wert           = 2.834175
$Size_y         = Round($Size_y * $Wert)
$Size_x         = Round($Size_x * $Wert)
$Rand_x         = Round($Rand_x * $Wert)
$Rand_y         = Round($Rand_y * $Wert)

FileWriteLine($File,"%PDF-1.2")
FileWriteLine($File,"%âãÏÓ")

FileWriteLine($File,"1 0 obj")
FileWriteLine($File,"<<")
FileWriteLine($File,"/Author ("&$Autor&")")
FileWriteLine($File,"/CreationDate (D:"&@YEAR&@MON&@MDAY&@HOUR&@MIN&@SEC&")")
FileWriteLine($File,"/Creator (Ahnungslos)")
FileWriteLine($File,"/Producer (Ahnungslos)")
FileWriteLine($File,"/Title ("&$Titel&")")
FileWriteLine($File,">>")
FileWriteLine($File,"endobj")

FileWriteLine($File,"4 0 obj")
FileWriteLine($File,"<<")
FileWriteLine($File,"/Type /Font")
FileWriteLine($File,"/Subtype /Type1")
FileWriteLine($File,"/Name /F1")
FileWriteLine($File,"/Encoding 5 0 R")
FileWriteLine($File,"/BaseFont /"&$Schriftart)
FileWriteLine($File,">>")
FileWriteLine($File,"endobj")

FileWriteLine($File,"5 0 obj")
FileWriteLine($File,"<<")
FileWriteLine($File,"/Type /Encoding")
FileWriteLine($File,"/BaseEncoding /WinAnsiEncoding")
FileWriteLine($File,">>")
FileWriteLine($File,"endobj")

FileWriteLine($File,"6 0 obj")
FileWriteLine($File,"<<")
FileWriteLine($File,"  /Font << /F1 4 0 R >>")
FileWriteLine($File,"  /ProcSet [ /PDF /Text ]")
FileWriteLine($File,">>")
FileWriteLine($File,"endobj")

FileWriteLine($File,"7 0 obj")
FileWriteLine($File,"<<")
FileWriteLine($File,"/Type /Page")
FileWriteLine($File,"/Parent 3 0 R")
FileWriteLine($File,"/Resources 6 0 R")
FileWriteLine($File,"/Contents 8 0 R")
FileWriteLine($File,"/Rotate 0")
FileWriteLine($File,">>")
FileWriteLine($File,"endobj")

FileWriteLine($File,"8 0 obj")
FileWriteLine($File,"<<")
FileWriteLine($File,"/Length 9 0 R")
FileWriteLine($File,">>")
FileWriteLine($File,"stream")
FileWriteLine($File,"BT")
    
If $Zeilen = 1 Then
    FileWriteLine($File,"/F1 "&$Schrift&" Tf")
    FileWriteLine($File,"1 0 0 1 "&$Rand_y&" "&$Size_y - $Rand_x - $Abstand&" Tm")
    FileWriteLine($File,"("&$Text&") Tj")
Else
    For $Counter = 1 To $Zeilen
        FileWriteLine($File,"/F1 "&$Schrift&" Tf")
        FileWriteLine($File,"1 0 0 1 "&$Rand_y&" "&$Size_y - $Rand_x - $Abstand * $Counter&" Tm")
        FileWriteLine($File,"("&$Text[$Counter * 2 - 1]&") Tj")
    Next
EndIf

FileWriteLine($File,"ET")
FileWriteLine($File,"endstream")
FileWriteLine($File,"endobj")

FileWriteLine($File,"9 0 obj")
FileWriteLine($File,"78")
FileWriteLine($File,"endobj")

FileWriteLine($File,"2 0 obj")
FileWriteLine($File,"<<")
FileWriteLine($File,"/Type /Catalog")
FileWriteLine($File,"/Pages 3 0 R")
FileWriteLine($File,">>")
FileWriteLine($File,"endobj")

FileWriteLine($File,"3 0 obj")
FileWriteLine($File,"<<")
FileWriteLine($File,"/Type /Pages")
FileWriteLine($File,"/Count 1")
FileWriteLine($File,"/MediaBox [ 0 0 "&$Size_x&" "&$Size_y&" ]")
FileWriteLine($File,"/Kids [ 7 0 R ]")
FileWriteLine($File,">>")
FileWriteLine($File,"endobj")

FileWriteLine($File,"0 10")
FileWriteLine($File,"0000000000 65535 f ")
FileWriteLine($File,"0000000013 00000 n ")
FileWriteLine($File,"0000000591 00000 n ")
FileWriteLine($File,"0000000634 00000 n ")
FileWriteLine($File,"0000000156 00000 n ")
FileWriteLine($File,"0000000245 00000 n ")
FileWriteLine($File,"0000000307 00000 n ")
FileWriteLine($File,"0000000372 00000 n ")
FileWriteLine($File,"0000000453 00000 n ")
FileWriteLine($File,"0000000576 00000 n ")
FileWriteLine($File,"trailer")
FileWriteLine($File,"<<")
FileWriteLine($File,"/Size 10")
FileWriteLine($File,"/Root 2 0 R")
FileWriteLine($File,"/Info 1 0 R")
FileWriteLine($File,">>")
FileWriteLine($File,"startxref")
FileWriteLine($File,"712")
FileWriteLine($File,"%%EOF")

FileClose($File)

http://autoit.aufwaerts.de/thread.php?thre...amp;hilight=pdf

1 person likes this

Share this post


Link to post
Share on other sites

I like this UDF, works really well


My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

This is incredible...I see possibilities opening up before me :nuke:

By the way, here's some more paper sizes for backwards America, holding tight to stupid inches...add this code up at the top where you're defining "A4" and "A3". This is just a beginning list.

Just for my reference, as one o' dems backwards Americans :P , I needed an english version, so I translated the German words as best I could (babelfish and remembering Highschool...using a regular pdf as reference to make sure I got the field names right), and added letter, legal and tabloid sizes to the paper sizes available.

; Function Name:    _StringToPDF()
; Description:      Create PDF File
; Parameter(s):     $Text            - Text in the PDF (I love Autoit)
;                   $File            - Path and Filename of the PDF (c:Test.pdf)
;                   $Size            - Papersize A4, A3, (Letter or 8.5x11), (Legal or 8.5x14), (Tabloid or 11x17)
;                   $HMargin    - Spacing between the text and the vertical edges, Default 20
;                   $VMargin    - Spacing between the text and the horizontal edges, Default 24
;                   $FontFace   - Fonts (Times-Roman, Helvetica and Courier), Default Courier
;                   $Boldface            - 1 if the font is bold, otherwise 0 (Default)
;                   $Italic    - 1 if the font is italic, otherwise 0 (Default)
;                   $FontSize            - Size of the font, Default 12
;                   $Author        - Name of the author, Default "unknown"
;                   $Title        - Title of the PDF, Default "MyPDF"
;
; Author(s):        Christian Korittke <[email="Christian_Korittke@web.de"]Christian_Korittke@web.de[/email]>
;                Tamer Hosgör <[email="Tamer@TamTech.info"]Tamer@TamTech.info[/email]>

Func _StringToPDF ( $Text, $File, $Size="Letter", $HMargin=20, $VMargin=24, $FontFace="Courier", $Boldface=0, $Italic=0, $FontSize=12, $Author="unknown", $Title="MyPDF")
    
    If $Size       = "A4" Then
        $Size_x     = 210
        $Size_y     = 297
    ElseIf $Size    = "A3" Then
        $Size_x     = 420
        $Size_y     = 297
    ElseIf $Size = "Letter" OR $Size = "8.5x11" Then
        $Size_x  = 216
        $Size_y  = 279
     ElseIf $Size = "Legal" OR $Size = "8.5x14" Then
        $Size_x  = 216
        $Size_y  = 356
     ElseIf $Size = "Tabloid" OR $Size = "11x17" Then
        $Size_x  = 279
        $Size_y  = 431
    EndIf
    
    $Lines   =    1
    
    If $Boldface = 1 Or $Italic = 1 Then
        If $FontFace = "Times-Roman" Then
            If $Boldface = 1 Then
                $FontFace = "Times-Bold"
            ElseIf $Italic = 1 Then
                $FontFace = "Times-Italic"
            EndIf
            If $Boldface = 1 And $Italic = 1 Then $FontFace =  "Times-BoldItalic"
        ElseIf $FontFace = "Helvetica" Then
            If $Boldface = 1 Then
                $FontFace = "Helvetica-Bold"
            ElseIf $Italic = 1 Then
                $FontFace = "Helvetica-Oblique"
            EndIf
            If $Boldface = 1 And $Italic = 1 Then $FontFace =  "Helvetica-BoldOblique"
        Else
            If $Boldface = 1 Then
                $FontFace = "Courier-Bold"
            ElseIf $Italic = 1 Then
                $FontFace = "Courier-Oblique"
            EndIf
            If $Boldface = 1 And $Italic = 1 Then $FontFace =  "Courier-BoldOblique"
        EndIf
    EndIf
    
    
    If $FontSize     = 8 Then
        $TrueFontSize    = 9
    ElseIf $FontSize = 9 Then
        $TrueFontSize    = 11
    ElseIf $FontSize = 10 Then
        $TrueFontSize    = 12
    ElseIf $FontSize = 11 Then
        $TrueFontSize    = 13
    ElseIf $FontSize = 12 Then
        $TrueFontSize    = 15
    ElseIf $FontSize = 14 Then
        $TrueFontSize    = 17
    ElseIf $FontSize = 16 Then
        $TrueFontSize    = 19
    ElseIf $FontSize = 18 Then
        $TrueFontSize    = 21
    ElseIf $FontSize = 20 Then
        $TrueFontSize    = 24
    ElseIf $FontSize = 22 Then
        $TrueFontSize    = 26
    ElseIf $FontSize = 24 Then
        $TrueFontSize    = 28
    ElseIf $FontSize = 26 Then
        $TrueFontSize    = 30
    ElseIf $FontSize = 28 Then
        $TrueFontSize    = 32
    ElseIf $FontSize = 36 Then
        $TrueFontSize    = 41
    ElseIf $FontSize = 48 Then
        $TrueFontSize    = 55
    EndIf

    If Not StringInStr($Text,@CRLF) = 0 Then
        $Text = StringSplit($Text,@CRLF)
        $Lines = $Text[0] / 2 + 1
    EndIf

    ; Conversion
    $ConvFactor       = 2.834175
    $Size_y         = Round($Size_y * $ConvFactor)
    $Size_x         = Round($Size_x * $ConvFactor)
    $HMargin         = Round($HMargin * $ConvFactor)
    $VMargin         = Round($VMargin * $ConvFactor)
    FileWriteLine($File,"%PDF-1.2")
    FileWriteLine($File,"%âãÔÕ")
    FileWriteLine($File,"1 0 obj")
    FileWriteLine($File,"<<")
    FileWriteLine($File,"/Author <"&$Author&">")
    FileWriteLine($File,"/CreationDate <"&@YEAR&@MON&@MDAY&@HOUR&@MIN&@SEC&">")
    FileWriteLine($File,"/Creator <"&$Author&">")
    FileWriteLine($File,"/Producer <AutoIt3>")
    FileWriteLine($File,"/Title <"&$Title&">")
    FileWriteLine($File,">>")
    FileWriteLine($File,"endobj")
    FileWriteLine($File,"4 0 obj")
    FileWriteLine($File,"<<")
    FileWriteLine($File,"/Type /Font")
    FileWriteLine($File,"/Subtype /Type1")
    FileWriteLine($File,"/Name /F1")
    FileWriteLine($File,"/Encoding 5 0 R")
    FileWriteLine($File,"/BaseFont /"&$FontFace)
    FileWriteLine($File,">>")
    FileWriteLine($File,"endobj")
    FileWriteLine($File,"5 0 obj")
    FileWriteLine($File,"<<")
    FileWriteLine($File,"/Type /Encoding")
    FileWriteLine($File,"/BaseEncoding /WinAnsiEncoding")
    FileWriteLine($File,">>")
    FileWriteLine($File,"endobj")
    FileWriteLine($File,"6 0 obj")
    FileWriteLine($File,"<<")
    FileWriteLine($File,"  /Font << /F1 4 0 R >>")
    FileWriteLine($File,"  /ProcSet [ /PDF /Text ]")
    FileWriteLine($File,">>")
    FileWriteLine($File,"endobj")
    FileWriteLine($File,"7 0 obj")
    FileWriteLine($File,"<<")
    FileWriteLine($File,"/Type /Page")
    FileWriteLine($File,"/Parent 3 0 R")
    FileWriteLine($File,"/Resources 6 0 R")
    FileWriteLine($File,"/Contents 8 0 R")
    FileWriteLine($File,"/Rotate 0")
    FileWriteLine($File,">>")
    FileWriteLine($File,"endobj")
    FileWriteLine($File,"8 0 obj")
    FileWriteLine($File,"<<")
    FileWriteLine($File,"/Length 9 0 R")
    FileWriteLine($File,">>")
    FileWriteLine($File,"stream")
    FileWriteLine($File,"BT")
        
    If $Lines = 1 Then
        FileWriteLine($File,"/F1 "&$FontSize&" Tf")
        FileWriteLine($File,"1 0 0 1 "&$VMargin&" "&$Size_y - $HMargin - $TrueFontSize&" Tm")
        FileWriteLine($File,"("&$Text&") Tj")
    Else
        For $Counter = 1 To $Lines
            FileWriteLine($File,"/F1 "&$FontSize&" Tf")
            FileWriteLine($File,"1 0 0 1 "&$VMargin&" "&$Size_y - $HMargin - $TrueFontSize * $Counter&" Tm")
            FileWriteLine($File,"("&$Text[$Counter * 2 - 1]&") Tj")
        Next
    EndIf

    FileWriteLine($File,"ET")
    FileWriteLine($File,"endstream")
    FileWriteLine($File,"endobj")
    FileWriteLine($File,"9 0 obj")
    FileWriteLine($File,"78")
    FileWriteLine($File,"endobj")
    FileWriteLine($File,"2 0 obj")
    FileWriteLine($File,"<<")
    FileWriteLine($File,"/Type /Catalog")
    FileWriteLine($File,"/Pages 3 0 R")
    FileWriteLine($File,">>")
    FileWriteLine($File,"endobj")
    FileWriteLine($File,"3 0 obj")
    FileWriteLine($File,"<<")
    FileWriteLine($File,"/Type /Pages")
    FileWriteLine($File,"/Count 1")
    FileWriteLine($File,"/MediaBox [ 0 0 "&$Size_x&" "&$Size_y&" ]")
    FileWriteLine($File,"/Kids [ 7 0 R ]")
    FileWriteLine($File,">>")
    FileWriteLine($File,"endobj")
    FileWriteLine($File,"0 10")
    FileWriteLine($File,"0000000000 65535 f ")
    FileWriteLine($File,"0000000013 00000 n ")
    FileWriteLine($File,"0000000591 00000 n ")
    FileWriteLine($File,"0000000634 00000 n ")
    FileWriteLine($File,"0000000156 00000 n ")
    FileWriteLine($File,"0000000245 00000 n ")
    FileWriteLine($File,"0000000307 00000 n ")
    FileWriteLine($File,"0000000372 00000 n ")
    FileWriteLine($File,"0000000453 00000 n ")
    FileWriteLine($File,"0000000576 00000 n ")
    FileWriteLine($File,"trailer")
    FileWriteLine($File,"<<")
    FileWriteLine($File,"/Size 10")
    FileWriteLine($File,"/Root 2 0 R")
    FileWriteLine($File,"/Info 1 0 R")
    FileWriteLine($File,">>")
    FileWriteLine($File,"startxref")
    FileWriteLine($File,"712")
    FileWriteLine($File,"%%EOF")
    FileClose($File)
EndFunc
Edited by james3mg

"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110

Share this post


Link to post
Share on other sites

HI,

or:

; Function Name: _StringToPDF()
; Description: Create PDF File

_StringToPDF("Hello", "c:\mega.pdf")

Func _StringToPDF($Text, $File = "MyPDF.pdf", $creator = "Creator", $producer = "Producer", $Size = "A4", $Rand_x = 20, $Rand_y = 24, $Schriftart = "Times-Roman", $Fett = 0, $Kursiv = 0, $Schrift = 12, $Autor = "unknown", $Titel = "Title")
    If $Size = "A4" Then
        $Size_x = 210
        $Size_y = 297
    ElseIf $Size = "A3" Then
        $Size_x = 420
        $Size_y = 297
    EndIf
    
    $Zeilen = 1
    If $Fett = 1 Or $Kursiv = 1 Then
        If $Schriftart = "Times-Roman" Then
            If $Fett = 1 Then
                $Schriftart = "Times-Bold"
            ElseIf $Kursiv = 1 Then
                $Schriftart = "Times-Italic"
            EndIf
            If $Fett = 1 And $Kursiv = 1 Then $Schriftart = "Times-BoldItalic"
        ElseIf $Schriftart = "Helvetica" Then
            If $Fett = 1 Then
                $Schriftart = "Helvetica-Bold"
            ElseIf $Kursiv = 1 Then
                $Schriftart = "Helvetica-Oblique"
            EndIf
            If $Fett = 1 And $Kursiv = 1 Then $Schriftart = "Helvetica-BoldOblique"
        Else
            If $Fett = 1 Then
                $Schriftart = "Courier-Bold"
            ElseIf $Kursiv = 1 Then
                $Schriftart = "Courier-Oblique"
            EndIf
            If $Fett = 1 And $Kursiv = 1 Then $Schriftart = "Courier-BoldOblique"
        EndIf
    EndIf
    Switch $Schrift
        Case 8
            $Abstand = 9
        Case 9
            $Abstand = 11
        Case 10
            $Abstand = 12
        Case 11
            $Abstand = 13
        Case 12
            $Abstand = 15
        Case 14
            $Abstand = 17
        Case 16
            $Abstand = 19
        Case 18
            $Abstand = 21
        Case 20
            $Abstand = 24
        Case 22
            $Abstand = 26
        Case 24
            $Abstand = 28
        Case 26
            $Abstand = 30
        Case 28
            $Abstand = 32
        Case 36
            $Abstand = 41
        Case 48
            $Abstand = 55
    EndSwitch
    If Not StringInStr($Text, @CRLF) = 0 Then
        $Text = StringSplit($Text, @CRLF)
        $Zeilen = $Text[0] / 21
    EndIf
    
    Local $Wert = 2.834175
     $Size_y = Round($Size_y * $Wert)
     $Size_x = Round($Size_x * $Wert)
     $Rand_x = Round($Rand_x * $Wert)
     $Rand_y = Round($Rand_y * $Wert)
    
    Local $pdf[47] = [ "%PDF-1.2", "%âãÏÓ", "1 0 obj",  "<<","/Author (" & $Autor & ")", "/CreationDate (D:" & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & ")", _
     "/Creator (" & $creator & ")","/Producer (" & $producer & ")", "/Title (" & $Titel & ")",">>", _
     "endobj","4 0 obj","<<","/Type /Font", "/Subtype /Type1", "/Name /F1","/Encoding 5 0 R","/BaseFont /" & $Schriftart,">>", _
     "endobj","5 0 obj","<<", "/Type /Encoding", "/BaseEncoding /WinAnsiEncoding",">>","endobj","6 0 obj","<<"," /Font << /F1 4 0 R >>", _
     " /ProcSet [ /PDF /Text ]", ">>","endobj","7 0 obj","<<","/Type /Page","/Parent 3 0 R","/Resources 6 0 R","/Contents 8 0 R", _
     "/Rotate 0", ">>","endobj","8 0 obj","<<","/Length 9 0 R",">>","stream","BT"]
     
     For $i=0 To UBound($pdf)-1
    FileWriteLine($File, $pdf[$i] & @CRLF)
    Next

    If $Zeilen = 1 Then
        FileWriteLine($File, "/F1 " & $Schrift & " Tf")
        FileWriteLine($File, "1 0 0 1 " & $Rand_y & " " & $Size_y - $Rand_x - $Abstand & " Tm")
        FileWriteLine($File, "(" & $Text & ") Tj")
    Else
        For $Counter = 1 To $Zeilen
            FileWriteLine($File, "/F1 " & $Schrift & " Tf")
            FileWriteLine($File, "1 0 0 1 " & $Rand_y & " " & $Size_y - $Rand_x - $Abstand * $Counter & " Tm")
            FileWriteLine($File, "(" & $Text[$Counter * 2 - 1] & ") Tj")
        Next
    EndIf
    
    Local $pdf1[40] = ["ET","endstream", "endobj","9 0 obj","78","endobj", "2 0 obj", "<<", "/Type /Catalog", "/Pages 3 0 R", ">>", _
    "endobj", "3 0 obj", "<<", "/Type /Pages", "/Count 1", "/MediaBox [ 0 0 " & $Size_x & " " & $Size_y & " ]", "/Kids [ 7 0 R ]", _
    ">>", "endobj", "0 10", "0000000000 65535 f ", "0000000013 00000 n ", "0000000591 00000 n ", "0000000634 00000 n ", "0000000156 00000 n ", _
    "0000000245 00000 n ","0000000307 00000 n ","0000000372 00000 n ", "0000000453 00000 n ", "0000000576 00000 n ", "trailer", _
    "<<", "/Size 10", "/Root 2 0 R", "/Info 1 0 R", ">>", "startxref", "712", "%%EOF"]
    For $i=0 To UBound($pdf1)-1
    FileWriteLine($File, $pdf1[$i] & @CRLF)
    Next
EndFunc   ;==>_StringToPDF

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Thank you. Unfortunately, my English is not so good:)

Share this post


Link to post
Share on other sites

Ok. Thanks @all.

; Function Name: _StringToPDF()
; Description: Create PDF File

_StringToPDF("Hello", "c:\mega.pdf")

Func _StringToPDF($Text, $File = "MyPDF.pdf", $creator = "Creator", $producer = "Producer", $Size = "A4", $Rand_x = 20, $Rand_y = 24, $Schriftart = "Times-Roman", $Fett = 0, $Kursiv = 0, $Schrift = 12, $Autor = "unknown", $Titel = "Title")
    If $Size = "A4" Then
        $Size_x = 210
        $Size_y = 297
    ElseIf $Size = "A3" Then
        $Size_x = 420
        $Size_y = 297
    EndIf
   
    $Zeilen = 1
    If $Fett = 1 Or $Kursiv = 1 Then
        If $Schriftart = "Times-Roman" Then
            If $Fett = 1 Then
                $Schriftart = "Times-Bold"
            ElseIf $Kursiv = 1 Then
                $Schriftart = "Times-Italic"
            EndIf
            If $Fett = 1 And $Kursiv = 1 Then $Schriftart = "Times-BoldItalic"
        ElseIf $Schriftart = "Arial" Then
            If $Fett = 1 Then
                $Schriftart = "Helvetica-Bold"
            ElseIf $Kursiv = 1 Then
                $Schriftart = "Helvetica-Italic"
            EndIf
            If $Fett = 1 And $Kursiv = 1 Then $Schriftart = "Arial,BoldItalic"
        Else
            If $Fett = 1 Then
                $Schriftart = "Courier-Bold"
            ElseIf $Kursiv = 1 Then
                $Schriftart = "Courier-Oblique"
            EndIf
            If $Fett = 1 And $Kursiv = 1 Then $Schriftart = "Courier-BoldOblique"
        EndIf
    EndIf
  $Abstand = Round($Schrift * 1.121861,3) 
  If Not StringInStr($Text, @CRLF) = 0 Then
        $Text = StringSplit($Text, @CRLF)
        $Zeilen = $Text[0] / 21
    EndIf
   
    Local $Wert = 2.834175
     $Size_y = Round($Size_y * $Wert)
     $Size_x = Round($Size_x * $Wert)
     $Rand_x = Round($Rand_x * $Wert)
     $Rand_y = Round($Rand_y * $Wert)
   
    Local $pdf[47] = [ "%PDF-1.2", "%âãÏÓ", "1 0 obj",  "<<","/Author (" & $Autor & ")", "/CreationDate (D:" & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & ")", _
     "/Creator (" & $creator & ")","/Producer (" & $producer & ")", "/Title (" & $Titel & ")",">>", _
     "endobj","4 0 obj","<<","/Type /Font", "/Subtype /Type1", "/Name /F1","/Encoding 5 0 R","/BaseFont /" & $Schriftart,">>", _
     "endobj","5 0 obj","<<", "/Type /Encoding", "/BaseEncoding /WinAnsiEncoding",">>","endobj","6 0 obj","<<"," /Font << /F1 4 0 R >>", _
     " /ProcSet [ /PDF /Text ]", ">>","endobj","7 0 obj","<<","/Type /Page","/Parent 3 0 R","/Resources 6 0 R","/Contents 8 0 R", _
     "/Rotate 0", ">>","endobj","8 0 obj","<<","/Length 9 0 R",">>","stream","BT"]
    
     For $i=0 To UBound($pdf)-1
    FileWriteLine($File, $pdf[$i] & @CRLF)
    Next

    If $Zeilen = 1 Then
        FileWriteLine($File, "/F1 " & $Schrift & " Tf")
        FileWriteLine($File, "1 0 0 1 " & $Rand_y & " " & $Size_y - $Rand_x - $Abstand & " Tm")
        FileWriteLine($File, "(" & $Text & ") Tj")
    Else
        For $Counter = 1 To $Zeilen
            FileWriteLine($File, "/F1 " & $Schrift & " Tf")
            FileWriteLine($File, "1 0 0 1 " & $Rand_y & " " & $Size_y - $Rand_x - $Abstand * $Counter & " Tm")
            FileWriteLine($File, "(" & $Text[$Counter * 2 - 1] & ") Tj")
        Next
    EndIf
   
    Local $pdf1[40] = ["ET","endstream", "endobj","9 0 obj","78","endobj", "2 0 obj", "<<", "/Type /Catalog", "/Pages 3 0 R", ">>", _
    "endobj", "3 0 obj", "<<", "/Type /Pages", "/Count 1", "/MediaBox [ 0 0 " & $Size_x & " " & $Size_y & " ]", "/Kids [ 7 0 R ]", _
    ">>", "endobj", "0 10", "0000000000 65535 f ", "0000000013 00000 n ", "0000000591 00000 n ", "0000000634 00000 n ", "0000000156 00000 n ", _
    "0000000245 00000 n ","0000000307 00000 n ","0000000372 00000 n ", "0000000453 00000 n ", "0000000576 00000 n ", "trailer", _
    "<<", "/Size 10", "/Root 2 0 R", "/Info 1 0 R", ">>", "startxref", "712", "%%EOF"]
    For $i=0 To UBound($pdf1)-1
    FileWriteLine($File, $pdf1[$i] & @CRLF)
    Next
EndFunc   ;==>_StringToPDF

More pdf functions are in work.

Ich hoffe Tam0r und th.meger Ihr helft dabei (aber lieber in deutsch).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0