mLipok Posted November 21, 2018 Share Posted November 21, 2018 @esneyder the right place to ask this question is in MPDF thread: Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
Zedna Posted November 27, 2018 Share Posted November 27, 2018 (edited) On 21. 11. 2018 at 8:44 PM, esneyder said: Hello!, I am creating PDF with MPDF_UDF but I have a problem with special characters such as "ñ" or "á", "é" ... etc, these characters are wrong in the writing, does anyone know how to solve it? If you write them but put the next letter on top. Thank you, Community! Greetings from Latin America. As far as I know this problem in MPDF UDF wasn't fixed so nonenglish accents are broken in PDF files created with this UDF. You can see my posts about that problem in MPDF UDF topic. This is reason why I don't use this UDF because my native Czech language have accents too, so in my projects where I wanted to use export to PDF this functionality is still missing :-( Edited November 27, 2018 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
FrancoBordin Posted January 29 Share Posted January 29 Hi guys! Using Christian and Tamer ideas i came up with this function to render a text file in pdf with automatic and/or forced pageskipping and basic "inline" color/graphic properties. Let me know if it's useful. P.S.: the only thing i wasn't able to do is to make the pdf "fully saved": once it is created and then opened (with a reader), while closing it, the reader always asks if it has to be saved. I can't find any help on the internet on which tag/objet to put in the pdf in order to be already "saved" expandcollapse popup; Function Name: _FileTxtToPDF() ; Description: Creates enriched PDF File from text file ; Parameter(s): $cFileTxt = Path of the txt file to be rendered ; $cFilePdf = Path of the pdf file to be produced (warning: if already existing, it'll be overwritten) ; $cPaperSize = Paper size ("A4" or "A3, default "A4") ; $lLandScape = Use landscape orientation (default False) ; $nVMargin = Top Margin (default (20 mm) ; $nHMargin = Left Margin (default (24 mm) ; $cFont = Font ("Courier", "Times" or "Helvetica") (default "Courier") ; $lBold = (default False) ; $lItalic = (default False) ; $nFontSize = Font size (default = 12) ; $nVSpacing = Vertical spacing (if 0 it'll be calculated from $nFontSize) ; $nHScale = Horizontal scale percentage (stretch/enlarge, default 100) ; $nMaxLines = Max lines per page (if 0 it'll be calculated; if it exceeds the calculated value, the latter will be used) ; $cAuthor = Author (default "unknown") ; $cTitle = Title (default "MyPDF") ; $cPage = "Page number" description for the footer. If null or empty string (which is the default value): no footer; example: "Page n. " ; $cPages = "Total pages" for the footer. If null or empty string (which is the default value): no total pages shown in the footer; example " of " ; $cFollow = Header description for showing the previous page number in the header of each page (excluding the first one). If null or empty string (which is the default value): no header; example: "...follows from page " ; $lEasyRead = (default True) The function places a watermark on pages with horizontal stripes in light cyan in order to improve readability ; $lUtf8 = (default False) That's experimental. The function tries a conversion for utf8 encoded input files in order to properly show special characters ; warning: this process is pretty slow (it processes between 50 and 150 lines per seconds depending on computer performance) ; Syntax for a very basic enrichment of the pdf graphic aspect: ; every line of the input file could include one of more of the following tags: ; {[(bold)]} = force the line to be displayed/printed in "bold" ; {[(italic)]} = force the line to be displayed/printed in "italic" ; {[(normal)]} = force the line to be displayed/printed in "normal" even if the function was called with the bold and/or italic parameter "True" ; {[(red)]} = force the line to be displayed/printed in red stroke ; {[(green)]} = force the line to be displayed/printed in green stroke ; {[(byellow)]} = force the line to be displayed/printed with yellow background ; {[(bgreen)]} = force the line to be displayed/printed with green background ; ; The above tags can be all combined. If one of more of them are identified, they are processed accordingly and then stripped from the output line ; ; {[(newpage)]} = force a new page (be aware that the function forces a newpage by himself everytime the end of page is reached) ; warning: "newpage" tag is the only one that cannot be combined at all and must be the only string in the line (every other line contents are ignored) ; ; Author: www.syse.it ; Based on ideas of Christian Korittke <Christian_Korittke@web.de> and Tamer Hosgör <Tamer@TamTech.info> #include-once #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <Math.au3> #include <File.au3> #include <String.au3> Func _FileTxtToPDF($cFileTxt, $cFilePdf, $cPaperSize = "A4", $lLandScape = False, $nVMargin = 20, $nHMargin = 24, $cFont = "Courier", $lBold = False, $lItalic = False, $nFontSize = 12, $nVSpacing = 0, $nHScale = 100, $nMaxLines = 0, $cAuthor = "unknown", $cTitle = "MyPDF", $cPage = "", $cPages = "", $cFollow = "", $lEasyRead = True, $lUtf8 = False) Global $nConversion = 2.834175 Global $cBlack = "0 0 0" Global $cRed = "1 0 0" Global $cGreen = "0 0.5 0" Global $cbYellow = "1 1 0" Global $cbGreen = "0.4 1 0.4" Global $cbCyan = "0.8 1 1" Global $nFontObjs = 5 ;total number of fonts' objs declared Global $nFixedObjs = 5 ;total number of fixed objs declared Global $nGap = 0 ; difference between filesetpos() returned value and the actual offset needed in xref Local $nRetVal = 2 Local $nCount = 0 Local $aReference[0][2] If $cPaperSize = Default Then $cPaperSize = "A4" Endif If $lLandScape = Default Then $lLandScape = False Endif If $nVMargin = Default Then $nVMargin = 20 Endif If $nHMargin = Default Then $nHMargin = 24 Endif If $cFont = Default Then $cFont = "Courier" Endif If $lBold = Default Then $lBold = False Endif If $lItalic = Default Then $lItalic = False Endif If $nFontSize = Default Then $nFontSize = 12 Endif If $nVSpacing = Default Then $nVSpacing = 0 Endif If $nHScale = Default Then $nHScale = 100 Endif If $nHScale = Default Then $nHScale = 100 Endif If $nMaxLines = Default Then $nMaxLines = 100 Endif If $cAuthor = Default Then $cAuthor = "unknown" Endif If $cTitle = Default Then $cTitle = "MyPdf" Endif If $cPage = Default Then $cPage = "" Endif If $cPages = Default Then $cPages = "" Endif If $cFollow = Default Then $cFollow = "" Endif If $lEasyRead = Default Then $lEasyRead = True Endif If $lUtf8 = Default Then $lUtf8 = False Endif If FileExists($cFileTxt) Then If $cPaperSize = "A4" Then If $lLandScape Then $nHsize = 297 $nVsize = 210 Else $nHsize = 210 $nVsize = 297 EndIf ElseIf $cPaperSize = "A3" Then If $lLandScape Then $nHsize = 420 $nVsize = 297 Else $nHsize = 297 $nVsize = 420 EndIf EndIf Local $cBold = $cFont & "-Bold" Local $cItalic = $cFont & "-Oblique" If $cFont = "Times" Then $cItalic = $cFont & "-Italic" EndIf Local $cBoldItalic = $cFont & "-BoldOblique" If $cFont = "Times" Then $cBoldItalic = $cFont & "-BoldItalic" $cFont = "Times-Roman" ;ElseIf $cFont = "Helvetica" Then ;$cBoldItalic = $cItalic EndIf Local $cNormal = $cFont If $lBold Then If $lItalic Then $cFont = $cBoldItalic Else $cFont = $cBold EndIf ElseIf $lItalic Then $cFont = $cItalic EndIf If $nVSpacing = 0 Then ; default vertical spacing if not declared otherwise If $nFontSize = 8 Then $nVSpacing = 9 ElseIf $nFontSize = 9 Then $nVSpacing = 11 ElseIf $nFontSize = 10 Then $nVSpacing = 12 ElseIf $nFontSize = 11 Then $nVSpacing = 13 ElseIf $nFontSize = 12 Then $nVSpacing = 15 ElseIf $nFontSize = 14 Then $nVSpacing = 17 ElseIf $nFontSize = 16 Then $nVSpacing = 19 ElseIf $nFontSize = 18 Then $nVSpacing = 21 ElseIf $nFontSize = 20 Then $nVSpacing = 24 ElseIf $nFontSize = 22 Then $nVSpacing = 26 ElseIf $nFontSize = 24 Then $nVSpacing = 28 ElseIf $nFontSize = 26 Then $nVSpacing = 30 ElseIf $nFontSize = 28 Then $nVSpacing = 32 ElseIf $nFontSize = 36 Then $nVSpacing = 41 ElseIf $nFontSize = 48 Then $nVSpacing = 55 Else $nVSpacing = Round($nFontSize * 1.18) EndIf EndIf Local $nMaxLinesCalculated = Int(($nVsize - $nVMargin) / $nVSpacing * $nConversion) - 1 If $nMaxLines > 0 Then $nMaxLines = _Min($nMaxLines, $nMaxLinesCalculated) Else $nMaxLines = $nMaxLinesCalculated EndIf Local $nNumOut = FileOpen($cFilePdf, $FO_OVERWRITE + $FO_ANSI) ;MsgBox($MB_SYSTEMMODAL, "show starting offset", FileGetPos($nNumOut)) Local $nNumIn = FileOpen($cFileTxt, $FO_ANSI) ; Umrechnung $nVsize = Round($nVsize * $nConversion) $nHsize = Round($nHsize * $nConversion) $nVMargin = Round($nVMargin * $nConversion) $nHMargin = Round($nHMargin * $nConversion) FileWriteLine($nNumOut, "%PDF-1.2") FileWriteLine($nNumOut, "%âãÏÓ") _ArrayAdd($aReference, "1|" & FileGetPos($nNumOut) + $nGap) FileWriteLine($nNumOut, "1 0 obj") FileWriteLine($nNumOut, "<<") FileWriteLine($nNumOut, "/Author (" & $cAuthor & ")") FileWriteLine($nNumOut, "/CreationDate (D:" & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & ")") FileWriteLine($nNumOut, "/Creator (Ahnungslos)") FileWriteLine($nNumOut, "/Producer (Ahnungslos)") FileWriteLine($nNumOut, "/Title (" & $cTitle & ")") FileWriteLine($nNumOut, ">>") FileWriteLine($nNumOut, "endobj") Local $nObjProg = $nFixedObjs + 1 _ArrayAdd($aReference, String($nObjProg) & "|" & FileGetPos($nNumOut) + $nGap) FileWriteLine($nNumOut, String($nObjProg) & " 0 obj") FileWriteLine($nNumOut, "<<") FileWriteLine($nNumOut, "/Type /Font") FileWriteLine($nNumOut, "/Subtype /Type1") FileWriteLine($nNumOut, "/Name /STANDARD") FileWriteLine($nNumOut, "/Encoding 4 0 R") FileWriteLine($nNumOut, "/BaseFont /" & $cFont) FileWriteLine($nNumOut, ">>") FileWriteLine($nNumOut, "endobj") $nObjProg += 1 _ArrayAdd($aReference, String($nObjProg) & "|" & FileGetPos($nNumOut) + $nGap) FileWriteLine($nNumOut, String($nObjProg) & " 0 obj") FileWriteLine($nNumOut, "<<") FileWriteLine($nNumOut, "/Type /Font") FileWriteLine($nNumOut, "/Subtype /Type1") FileWriteLine($nNumOut, "/Name /BOLD") FileWriteLine($nNumOut, "/Encoding 4 0 R") FileWriteLine($nNumOut, "/BaseFont /" & $cBold) FileWriteLine($nNumOut, ">>") FileWriteLine($nNumOut, "endobj") $nObjProg += 1 _ArrayAdd($aReference, String($nObjProg) & "|" & FileGetPos($nNumOut) + $nGap) FileWriteLine($nNumOut, String($nObjProg) & " 0 obj") FileWriteLine($nNumOut, "<<") FileWriteLine($nNumOut, "/Type /Font") FileWriteLine($nNumOut, "/Subtype /Type1") FileWriteLine($nNumOut, "/Name /ITA") FileWriteLine($nNumOut, "/Encoding 4 0 R") FileWriteLine($nNumOut, "/BaseFont /" & $cItalic) FileWriteLine($nNumOut, ">>") FileWriteLine($nNumOut, "endobj") $nObjProg += 1 _ArrayAdd($aReference, String($nObjProg) & "|" & FileGetPos($nNumOut) + $nGap) FileWriteLine($nNumOut, String($nObjProg) & " 0 obj") FileWriteLine($nNumOut, "<<") FileWriteLine($nNumOut, "/Type /Font") FileWriteLine($nNumOut, "/Subtype /Type1") FileWriteLine($nNumOut, "/Name /BLDITA") FileWriteLine($nNumOut, "/Encoding 4 0 R") FileWriteLine($nNumOut, "/BaseFont /" & $cBoldItalic) FileWriteLine($nNumOut, ">>") FileWriteLine($nNumOut, "endobj") $nObjProg += 1 _ArrayAdd($aReference, String($nObjProg) & "|" & FileGetPos($nNumOut) + $nGap) FileWriteLine($nNumOut, String($nObjProg) & " 0 obj") FileWriteLine($nNumOut, "<<") FileWriteLine($nNumOut, "/Type /Font") FileWriteLine($nNumOut, "/Subtype /Type1") FileWriteLine($nNumOut, "/Name /NORMAL") FileWriteLine($nNumOut, "/Encoding 4 0 R") FileWriteLine($nNumOut, "/BaseFont /" & $cNormal) FileWriteLine($nNumOut, ">>") FileWriteLine($nNumOut, "endobj") _ArrayAdd($aReference, "4|" & FileGetPos($nNumOut) + $nGap) FileWriteLine($nNumOut, "4 0 obj") FileWriteLine($nNumOut, "<<") FileWriteLine($nNumOut, "/Type /Encoding") FileWriteLine($nNumOut, "/BaseEncoding /WinAnsiEncoding") FileWriteLine($nNumOut, ">>") FileWriteLine($nNumOut, "endobj") _ArrayAdd($aReference, "5|" & FileGetPos($nNumOut) + $nGap) FileWriteLine($nNumOut, "5 0 obj") FileWriteLine($nNumOut, "<<") FileWriteLine($nNumOut, "/Font <<") FileWriteLine($nNumOut, "/STANDARD " & String($nFixedObjs + 1) & " 0 R") FileWriteLine($nNumOut, "/BOLD " & String($nFixedObjs + 2) & " 0 R") FileWriteLine($nNumOut, "/ITA " & String($nFixedObjs + 3) & " 0 R") FileWriteLine($nNumOut, "/BLDITA " & String($nFixedObjs + 4) & " 0 R") FileWriteLine($nNumOut, "/NORMAL " & String($nFixedObjs + 5) & " 0 R") FileWriteLine($nNumOut, ">>") FileWriteLine($nNumOut, " /ProcSet [ /PDF /Text ]") FileWriteLine($nNumOut, ">>") FileWriteLine($nNumOut, "endobj") Local $nLine = 0 Local $nPage = 1 Local $cLine = "" Local $cCodFont = "" ;Local $nTotPages = Int((_FileCountLines($nNumIn) - 1) / $nMaxLines) + 1 FileSetPos($nNumIn, 0, $FILE_BEGIN) Local $nStart = 0 While True $cLine = FileReadLine($nNumIn) If @error = 0 Then Local $lBoldLine = False Local $lItalicLine = False Local $lNormalLine = False Local $lNewPage = False Local $lRed = False Local $lGreen = False Local $lbYellow = False Local $lbGreen = False AnalizeLine($cLine, $lBoldLine, $lItalicLine, $lNewPage, $lRed, $lGreen, $lbYellow, $lbGreen, $lNormalLine) If Not $lNewPage Then $nLine += 1 EndIf If Not $nRetVal = 0 Then $nStart = CreatePageObjects($nNumOut, 0, $aReference, $cFollow, $nVsize, $nVSpacing) $nRetVal = 0 ElseIf $lNewPage Or $nLine > $nMaxLines Then ClosePageObj($nNumOut, $aReference, $nStart, $cPage, $cPages, $nPage, $lEasyRead, $nLine, $nMaxLines, $nVsize, $nVMargin, $nVSpacing, $nHsize) $nStart = CreatePageObjects($nNumOut, $nPage, $aReference, $cFollow, $nVsize, $nVSpacing) $nPage += 1 If $lNewPage Then $nLine = 0 Else $nLine = 1 EndIf EndIf If Not $lNewPage Then $cCodFont = "STANDARD" If $lNormalLine Then $cCodFont = "NORMAL" ElseIf $lBoldLine Then If $lItalicLine Then $cCodFont = "BLDITA" Else $cCodFont = "BOLD" EndIf ElseIf $lItalicLine Then $cCodFont = "ITA" EndIf ;$cCodFont = "2" If $lbYellow Or $lbGreen Or ($lEasyRead And Mod($nLine, 2) = 1) Then Local $cColor = $cbCyan If $lbGreen Then $cColor = $cbGreen ElseIf $lbYellow Then $cColor = $cbYellow EndIf FileWriteLine($nNumOut, $cColor & " rg") FileWriteLine($nNumOut, "0 " & ($nVsize - $nVMargin - ($nVSpacing * $nLine)) - ($nVSpacing / 4) & " " & $nHsize & " " & $nVSpacing & " re") FileWriteLine($nNumOut, "F") EndIf If $lRed Then $cColor = $cRed ElseIf $lGreen Then $cColor = $cGreen Else $cColor = $cBlack EndIf FileWriteLine($nNumOut, "BT") FileWriteLine($nNumOut, $cColor & " rg") FileWriteLine($nNumOut, "/" & $cCodFont & " " & $nFontSize & " Tf") FileWriteLine($nNumOut, $nHScale & " Tz") FileWriteLine($nNumOut, "1 0 0 1 " & $nHMargin & " " & $nVsize - $nVMargin - $nVSpacing * $nLine & " Tm") If $lUtf8 Then $cLine=Utf8toAnsi($cLIne) Endif FileWriteLine($nNumOut, "(" & $cLine & ") Tj") FileWriteLine($nNumOut, "ET") EndIf Else ExitLoop EndIf WEnd FileClose($nNumIn) If $nRetVal = 0 Then ClosePageObj($nNumOut, $aReference, $nStart, $cPage, $cPages, $nPage, $lEasyRead, $nLine, $nMaxLines, $nVsize, $nVMargin, $nVSpacing, $nHsize) EndIf _ArrayAdd($aReference, "2|" & FileGetPos($nNumOut) + $nGap) FileWriteLine($nNumOut, "2 0 obj") FileWriteLine($nNumOut, "<<") FileWriteLine($nNumOut, "/Type /Catalog") FileWriteLine($nNumOut, "/Pages 3 0 R") FileWriteLine($nNumOut, ">>") FileWriteLine($nNumOut, "endobj") _ArrayAdd($aReference, "3|" & FileGetPos($nNumOut) + $nGap) FileWriteLine($nNumOut, "3 0 obj") FileWriteLine($nNumOut, "<<") FileWriteLine($nNumOut, "/Type /Pages") FileWriteLine($nNumOut, "/Count " & String($nPage)) FileWriteLine($nNumOut, "/MediaBox [ 0 0 " & $nHsize & " " & $nVsize & " ]") FileWriteLine($nNumOut, "/Kids [") For $nCount = 0 To ($nPage - 1) FileWriteLine($nNumOut, String($nFixedObjs + $nFontObjs + 1 + ($nCount * 3)) & " 0 R") Next FileWriteLine($nNumOut, "]") FileWriteLine($nNumOut, ">>") FileWriteLine($nNumOut, "endobj") For $nCount = 0 To UBound($aReference) - 1 $aReference[$nCount][0] = Number($aReference[$nCount][0]) $aReference[$nCount][1] = Number($aReference[$nCount][1]) Next ;_ArrayDisplay($aReference,"before sort") _ArraySort($aReference) ;_ArrayDisplay($aReference,"after sort") Local $nRefPos = FileGetPos($nNumOut) + $nGap FileWriteLine($nNumOut, "xref") FileWriteLine($nNumOut, "0 " & String(UBound($aReference) + 1)) FileWriteLine($nNumOut, "0000000000 65535 f ") For $nCount = 0 To UBound($aReference) - 1 FileWriteLine($nNumOut, StringRight(_StringRepeat("0", 10) & String(Int($aReference[$nCount][1])), 10) & " 00000 n ") Next FileWriteLine($nNumOut, "trailer") FileWriteLine($nNumOut, "<<") FileWriteLine($nNumOut, "/Size " & String(UBound($aReference) + 1)) FileWriteLine($nNumOut, "/Root 2 0 R") FileWriteLine($nNumOut, "/Info 1 0 R") FileWriteLine($nNumOut, ">>") FileWriteLine($nNumOut, "startxref") FileWriteLine($nNumOut, String($nRefPos)) FileWriteLine($nNumOut, "%%EOF") FileClose($nNumOut) If Not StringIsSpace($cPage) And Not StringIsSpace($cPages) Then $nNumIn = FileOpen($cFilePdf, $FO_ANSI) $cLine = StringReplace(FileRead($nNumIn), "{[(totpages)]}", String($nPage)) FileClose($nNumIn) $nNumOut = FileOpen($cFilePdf, $FO_OVERWRITE + $FO_ANSI) FileWrite($nNumOut, $cLine) FileClose($nNumOut) EndIf Else $nRetVal = 1 EndIf Return ($nRetVal) EndFunc ;==>_FileTxtToPDF Func CreatePageObjects($nNumOut, $nPage, ByRef $aReference, $cFollow, $nVsize, $nVSpacing) Local $nPageObject = $nFixedObjs + $nFontObjs + 1 + ($nPage * 3) _ArrayAdd($aReference, String($nPageObject) & "|" & FileGetPos($nNumOut) + $nGap) FileWriteLine($nNumOut, String($nPageObject) & " 0 obj") FileWriteLine($nNumOut, "<<") FileWriteLine($nNumOut, "/Type /Page") FileWriteLine($nNumOut, "/Parent 3 0 R") FileWriteLine($nNumOut, "/Resources 5 0 R") FileWriteLine($nNumOut, "/Contents " & String($nPageObject + 1) & " 0 R") FileWriteLine($nNumOut, "/Rotate 0") FileWriteLine($nNumOut, ">>") FileWriteLine($nNumOut, "endobj") $nPageObject += 1 Local $nStart = FileGetPos($nNumOut) _ArrayAdd($aReference, String($nPageObject) & "|" & FileGetPos($nNumOut) + $nGap) FileWriteLine($nNumOut, String($nPageObject) & " 0 obj") FileWriteLine($nNumOut, "<<") FileWriteLine($nNumOut, "/Length " & String($nPageObject + 1) & " 0 R") FileWriteLine($nNumOut, ">>") FileWriteLine($nNumOut, "stream") ;FileWriteLine($nNumOut, "BT") If $nPage > 0 and Not StringIsSpace($cFollow) Then Local $cHeader = $cFollow & String($nPage) FileWriteLine($nNumOut, "BT") FileWriteLine($nNumOut, $cBlack & " rg") FileWriteLine($nNumOut, "/STANDARD 5 Tf") FileWriteLine($nNumOut, "1 0 0 1 5 " & String($nVsize - 5) & " Tm") FileWriteLine($nNumOut, "(" & $cHeader & ") Tj") FileWriteLine($nNumOut, "ET") EndIf Return $nStart EndFunc ;==>CreatePageObjects Func ClosePageObj($nNumOut, ByRef $aReference, $nStart, $cPage, $cPages, $nPage, $lEasyRead, $nLine, $nMaxLines, $nVsize, $nVMargin, $nVSpacing, $nHsize) Local $nPageLengthObject = $nFixedObjs + $nFontObjs + 3 + (($nPage - 1) * 3) Local $nCount = 0 If $lEasyRead Then For $nCount = $nLine + 1 To $nMaxLines If Mod($nCount, 2) = 1 Then FileWriteLine($nNumOut, "0.8 1 1 rg") FileWriteLine($nNumOut, "0 " & ($nVsize - $nVMargin - ($nVSpacing * $nCount)) - ($nVSpacing / 4) & " " & $nHsize & " " & $nVSpacing & " re") FileWriteLine($nNumOut, "F") FileWriteLine($nNumOut, $cBlack & " rg") EndIf Next EndIf FileWriteLine($nNumOut, "0 0 0 rg") If Not StringIsSpace($cPage) Then Local $cFooter = $cPage & String($nPage) If Not StringIsSpace($cPages) Then $cFooter &= $cPages & "{[(totpages)]}" EndIf FileWriteLine($nNumOut, "BT") FileWriteLine($nNumOut, $cBlack & " rg") FileWriteLine($nNumOut, "/STANDARD 5 Tf") FileWriteLine($nNumOut, "1 0 0 1 5 5 Tm") FileWriteLine($nNumOut, "(" & $cFooter & ") Tj") FileWriteLine($nNumOut, "ET") EndIf ;FileWriteLine($nNumOut, "ET") FileWriteLine($nNumOut, "endstream") FileWriteLine($nNumOut, "endobj") Local $nLength = FileGetPos($nNumOut) - $nStart _ArrayAdd($aReference, String($nPageLengthObject) & "|" & FileGetPos($nNumOut) + $nGap) FileWriteLine($nNumOut, String($nPageLengthObject) & " 0 obj") FileWriteLine($nNumOut, String($nLength)) FileWriteLine($nNumOut, "endobj") Return EndFunc ;==>ClosePageObj Func AnalizeLine(ByRef $cLine, ByRef $lBold, ByRef $lItalic, ByRef $lNewPage, ByRef $lRed, ByRef $lGreen, ByRef $lbYellow, ByRef $lbGreen, ByRef $lNormal) If SearchReplaceLine($cLine, "bold") Then $lBold = True EndIf If SearchReplaceLine($cLine, "italic") Then $lItalic = True EndIf If SearchReplaceLine($cLine, "normal") Then $lNormal = True EndIf If SearchReplaceLine($cLine, "newpage") Then $lNewPage = True EndIf If SearchReplaceLine($cLine, "red") Then $lRed = True EndIf If SearchReplaceLine($cLine, "green") Then $lGreen = True EndIf If SearchReplaceLine($cLine, "byellow") Then $lbYellow = True EndIf If SearchReplaceLine($cLine, "bgreen") Then $lbGreen = True EndIf Return EndFunc ;==>AnalizeLine Func SearchReplaceLine(ByRef $cLine, $cTag) Local $cStartTag = "{[(" Local $cEndTag = ")]}" Local $lRetVal = False If StringInStr($cLine, $cStartTag & $cTag & $cEndTag) > 0 Then $lRetVal = True $cLine = StringReplace($cLine, $cStartTag & $cTag & $cEndTag, "") EndIf Return $lRetVal EndFunc ;==>SearchReplaceLine Func Utf8toAnsi($cString) Local $nCount = 0 Local $aSubst[0][3] For $nCount = 161 to 191 _ArrayAdd ( $aSubst, "194|" & $nCount & "|" & $nCount ) Next For $nCount = 192 to 255 _ArrayAdd ( $aSubst, "195|" & ($nCount - 64) & "|" & $nCount ) Next ;_ArrayDisplay($aSubst) For $nCount = 0 To UBound($aSubst, 1) - 1 $cString = StringReplace($cString, Chr($aSubst[$nCount][0]) & Chr($aSubst[$nCount][1]), Chr($aSubst[$nCount][2])) Next Return ($cString) EndFunc ;==>XmlToString Link to comment Share on other sites More sharing options...
Lion66 Posted September 24 Share Posted September 24 Hello. Can someone help me change the UDF so, that when re -starting script, the text is added to the end of the existing PDF? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now