taietel Posted August 29, 2011 Author Share Posted August 29, 2011 (edited) Here is a reproducer with some 3 files generated one after each other:has 4 pageshas 3 pageshas 4 pagesexpandcollapse popup#include "MPDF_UDF.au3" MsgBox(1, "test", "Hit ok to run the first report (4 pages)") FirstPDF() MsgBox(1, "test", "Hit ok to run the second report (3 pages)") SecondPDF() MsgBox(1, "test", "Hit ok to run the third report (4 pages)") ThirdPDF() Func FirstPDF() ;set the properties for the pdf _SetTitle("Demo Table PDF in AutoIt") _SetSubject("Demo Table PDF in AutoIt, with formating") _SetKeywords("pdf, demo, table, AutoIt") _OpenAfter(True);open after generation _SetUnit($PDF_UNIT_CM) _SetPaperSize("CUSTOM", 841.890, 595.276); A4 landscape _SetZoomMode($PDF_ZOOM_FULLPAGE) _SetOrientation($PDF_ORIENTATION_PORTRAIT) _SetLayoutMode($PDF_LAYOUT_CONTINOUS) ;initialize the pdf _InitPDF(@ScriptDir & "\table.pdf") ;=== load used font(s) === ;fonts: Garamond _LoadFontTT("_CalibriB", $PDF_FONT_CALIBRI, $PDF_FONT_BOLD) _LoadFontTT("_CalibriI", $PDF_FONT_CALIBRI, $PDF_FONT_ITALIC) _LoadFontTT("_Calibri", $PDF_FONT_CALIBRI) ;begin page _BeginPage() _InsertTable(2, 2, 0, 0, 10, 10) $sTit = "Sample pdf table generated with AutoIt" _SetTextRenderingMode(1) _InsertRenderedText((_GetPageWidth() / _GetUnit()) / 2, _GetPageHeight() / _GetUnit() - 1.5, $sTit, "_CalibriI", 32, 100, $PDF_ALIGN_CENTER, 0xbbbbbb, 0x202020) _SetTextRenderingMode(0) _EndPage() _BeginPage() _InsertTable(2, 8, 0, 0, 8, 5) $sTit = "Sample pdf table generated with AutoIt" _SetTextRenderingMode(2) _InsertRenderedText((_GetPageWidth() / _GetUnit()) / 2, _GetPageHeight() / _GetUnit() - 1.5, $sTit, "_CalibriB", 32, 100, $PDF_ALIGN_CENTER, 0xbbbbbb, 0x202020) _SetTextRenderingMode(0) _EndPage() _BeginPage() _InsertTable(2, 8, 20, 0, 8, 5) $sTit = "Sample pdf table generated with AutoIt" _SetTextRenderingMode(3) _InsertRenderedText((_GetPageWidth() / _GetUnit()) / 2, _GetPageHeight() / _GetUnit() - 1.5, $sTit, "_CalibriI", 32, 100, $PDF_ALIGN_CENTER, 0xbbbbbb, 0x202020) _SetTextRenderingMode(0) _EndPage() _BeginPage() _InsertTable(8, 2, 0, 15, 8, 15) $sTit = "Sample pdf table generated with AutoIt" _SetTextRenderingMode(5) _InsertRenderedText((_GetPageWidth() / _GetUnit()) / 2, _GetPageHeight() / _GetUnit() - 1.5, $sTit, "_CalibriB", 32, 100, $PDF_ALIGN_CENTER, 0xbbbbbb, 0x202020) _SetTextRenderingMode(0) _EndPage() _ClosePDFFile() EndFunc ;==>FirstPDF Func SecondPDF() ;set the properties for the pdf _SetTitle("Demo Table PDF in AutoIt") _SetSubject("Demo Table PDF in AutoIt, with formating") _SetKeywords("pdf, demo, table, AutoIt") _OpenAfter(True);open after generation _SetUnit($PDF_UNIT_CM) _SetPaperSize("CUSTOM", 841.890, 595.276); A4 landscape _SetZoomMode($PDF_ZOOM_FULLPAGE) _SetOrientation($PDF_ORIENTATION_PORTRAIT) _SetLayoutMode($PDF_LAYOUT_CONTINOUS) ;initialize the pdf _InitPDF(@ScriptDir & "\table.pdf") ;=== load used font(s) === ;fonts: Garamond _LoadFontTT("_CalibriB", $PDF_FONT_CALIBRI, $PDF_FONT_BOLD) _LoadFontTT("_CalibriI", $PDF_FONT_CALIBRI, $PDF_FONT_ITALIC) _LoadFontTT("_Calibri", $PDF_FONT_CALIBRI) ;begin page _BeginPage() _InsertTable(2, 2, 0, 0, 10, 10) $sTit = "Sample pdf table generated with AutoIt" _SetTextRenderingMode(1) _InsertRenderedText((_GetPageWidth() / _GetUnit()) / 2, _GetPageHeight() / _GetUnit() - 1.5, $sTit, "_CalibriI", 32, 100, $PDF_ALIGN_CENTER, 0xbbbbbb, 0x202020) _SetTextRenderingMode(0) _EndPage() _BeginPage() _InsertTable(2, 8, 0, 0, 8, 5) $sTit = "Sample pdf table generated with AutoIt" _SetTextRenderingMode(2) _InsertRenderedText((_GetPageWidth() / _GetUnit()) / 2, _GetPageHeight() / _GetUnit() - 1.5, $sTit, "_CalibriB", 32, 100, $PDF_ALIGN_CENTER, 0xbbbbbb, 0x202020) _SetTextRenderingMode(0) _EndPage() _BeginPage() _InsertTable(2, 8, 20, 0, 8, 5) $sTit = "Sample pdf table generated with AutoIt" _SetTextRenderingMode(3) _InsertRenderedText((_GetPageWidth() / _GetUnit()) / 2, _GetPageHeight() / _GetUnit() - 1.5, $sTit, "_CalibriI", 32, 100, $PDF_ALIGN_CENTER, 0xbbbbbb, 0x202020) _SetTextRenderingMode(0) _EndPage() _ClosePDFFile() EndFunc ;==>SecondPDF Func ThirdPDF() ;set the properties for the pdf _SetTitle("Demo Table PDF in AutoIt") _SetSubject("Demo Table PDF in AutoIt, with formating") _SetKeywords("pdf, demo, table, AutoIt") _OpenAfter(True);open after generation _SetUnit($PDF_UNIT_CM) _SetPaperSize("CUSTOM", 841.890, 595.276); A4 landscape _SetZoomMode($PDF_ZOOM_FULLPAGE) _SetOrientation($PDF_ORIENTATION_PORTRAIT) _SetLayoutMode($PDF_LAYOUT_CONTINOUS) ;initialize the pdf _InitPDF(@ScriptDir & "\table.pdf") ;=== load used font(s) === ;fonts: Garamond _LoadFontTT("_CalibriB", $PDF_FONT_CALIBRI, $PDF_FONT_BOLD) _LoadFontTT("_CalibriI", $PDF_FONT_CALIBRI, $PDF_FONT_ITALIC) _LoadFontTT("_Calibri", $PDF_FONT_CALIBRI) ;begin page _BeginPage() _InsertTable(2, 2, 0, 0, 10, 10) $sTit = "Sample pdf table generated with AutoIt" _SetTextRenderingMode(1) _InsertRenderedText((_GetPageWidth() / _GetUnit()) / 2, _GetPageHeight() / _GetUnit() - 1.5, $sTit, "_CalibriI", 32, 100, $PDF_ALIGN_CENTER, 0xbbbbbb, 0x202020) _SetTextRenderingMode(0) _EndPage() _BeginPage() _InsertTable(2, 8, 0, 0, 8, 5) $sTit = "Sample pdf table generated with AutoIt" _SetTextRenderingMode(2) _InsertRenderedText((_GetPageWidth() / _GetUnit()) / 2, _GetPageHeight() / _GetUnit() - 1.5, $sTit, "_CalibriB", 32, 100, $PDF_ALIGN_CENTER, 0xbbbbbb, 0x202020) _SetTextRenderingMode(0) _EndPage() _BeginPage() _InsertTable(2, 8, 20, 0, 8, 5) $sTit = "Sample pdf table generated with AutoIt" _SetTextRenderingMode(3) _InsertRenderedText((_GetPageWidth() / _GetUnit()) / 2, _GetPageHeight() / _GetUnit() - 1.5, $sTit, "_CalibriI", 32, 100, $PDF_ALIGN_CENTER, 0xbbbbbb, 0x202020) _SetTextRenderingMode(0) _EndPage() _BeginPage() _InsertTable(8, 2, 0, 15, 8, 15) $sTit = "Sample pdf table generated with AutoIt" _SetTextRenderingMode(5) _InsertRenderedText((_GetPageWidth() / _GetUnit()) / 2, _GetPageHeight() / _GetUnit() - 1.5, $sTit, "_CalibriB", 32, 100, $PDF_ALIGN_CENTER, 0xbbbbbb, 0x202020) _SetTextRenderingMode(0) _EndPage() _ClosePDFFile() EndFunc ;==>ThirdPDF Func _InsertTable($iX, $iY, $iW = 0, $iH = 0, $iCols = 0, $iRows = 0, $lTxtColor = 0x000000, $lBorderColor = 0xdddddd) Local $iPgW = Round(_GetPageWidth() / _GetUnit(), 1) Local $iPgH = Round(_GetPageHeight() / _GetUnit(), 1) If $iW = 0 Then $iW = $iPgW - $iX - 2 If $iH = 0 Then $iH = $iPgH - $iY - 2 _SetColourStroke($lBorderColor) _Draw_Rectangle($iX, $iY, $iW, $iH, $PDF_STYLE_STROKED, 0, 0xfefefe, 0.01) _SetColourStroke(0) Local $iColW = $iW / $iCols Local $iRowH = $iH / $iRows Local $lRGB For $i = 0 To $iRows - 1 For $j = 0 To $iCols - 1 If $i = 0 Then $lRGB = 0xefefef Else $lRGB = 0xfefefe EndIf _SetColourStroke($lBorderColor) _Draw_Rectangle($iX + $j * $iColW, $iY + $iH - ($i + 1) * $iRowH, $iColW, $iRowH, $PDF_STYLE_STROKED, 0, $lRGB, 0.01) _SetColourStroke(0) Local $sText = "Row " & $i & ": Col " & $j Local $sLength = Round(_GetTextLength($sText, "_Calibri", 10), 1) $lScale = Ceiling(0.75 * $iColW * 100 / $sLength) _SetColourFill($lTxtColor) _SetTextHorizontalScaling($lScale) _DrawText($iX + $j * $iColW + $iColW / 10, $iY + $iH - ($i + 1) * $iRowH + ($iRowH - 10 / _GetUnit()) / 2, $sText, "_Calibri", 10, $PDF_ALIGN_LEFT, 0) _SetTextHorizontalScaling(100) _SetColourFill(0) Next Next EndFunc ;==>_InsertTableCheck your script for $a variable. This part is not related with the UDF.Regards,taietel[EDIT] Just to be safe, modify the end of the _ClosePDFFile function to look like this (to clean ALL the resources):Func _ClosePDFFile() ......................... $_Pages = "" $_sPage = "" $_sFONT = "" $_Image = "" $_sObject = "" $_iResource = "" $_Buffer = "" If $_bOpen Then ShellExecute($PDF_NAME) EndFunc ;==>_ClosePDFFile Edited August 29, 2011 by taietel sudeepjd 1 Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text Link to comment Share on other sites More sharing options...
bartekd Posted August 29, 2011 Share Posted August 29, 2011 Thanks, this seems to have worked. Func _ClosePDFFile() ......................... $_Pages = "" $_sPage = "" $_sFONT = "" $_Image = "" $_sObject = "" $_iResource = "" $_Buffer = "" If $_bOpen Then ShellExecute($PDF_NAME) EndFunc ;==>_ClosePDFFile I am going to try to play with it a bit, and see if it still does this, but it looks like it is resolved. BTW, $a is not part of the UDF, but it is part of the loop I was using. If you see, it goes through an array, and exports from the array to the PDF file. That is why I used a variable and a loop, because sometimes there could be 1 thing in the array, and the next report can have 20. Link to comment Share on other sites More sharing options...
taietel Posted August 30, 2011 Author Share Posted August 30, 2011 I know $a is not part of the UDF. If I were you, I'd put the table as an object, once, at the beginning of the pdf, with the flag set to appear on every page, and just fill the needed cells with the data from the array. This way the code is shorter, the pdf is smaller and it generates faster. The table example was just a simple demonstration of how to make one, but not practical for huge documents. You have to modify it to fit your needs. Usually I generate the pdf in one shot, from several to hundreds of pages, that's why I didn't clear the buffer in the first place. Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text Link to comment Share on other sites More sharing options...
bartekd Posted August 30, 2011 Share Posted August 30, 2011 Thanks again. This UDF is great, and will be using it for sure. I will play around with it, and do as you suggested, and ask questions if I have any. Link to comment Share on other sites More sharing options...
happytc Posted September 20, 2011 Share Posted September 20, 2011 I never succeeded to use this great UDF.It's a big pity. I could convert the 6 images in the example of post#1 by this EXE: http://www.comicer.com/stronghorse/software/exe/FreePic2Pdf_eng.zip Here was the converted PDF file: http://min.us/mMZdCQimY But using Example_Image2PDF.au3, I got the corrupted pdf file: http://min.us/mjSJNbVaD Link to comment Share on other sites More sharing options...
NightOwlJack Posted October 6, 2011 Share Posted October 6, 2011 This UDF is great. However, I found created PDF ( txt2pdf function) actually is a plain text format and the content could be modified by notepad. It would be great, if mpdf_udf could combine the zlib udf. Link to comment Share on other sites More sharing options...
Virgilio1 Posted October 14, 2011 Share Posted October 14, 2011 I friends I modified the function _Txt2PDF to split a very long line into multiple lines. <SPAN class="hps"> Local $arrayParole = StringSplit($iTotalRows[$counter]," ") Local $riga = "" for $J = 0 to UBound($arrayParole)-1 ; calcola lunghezza riga Local $iRowLengthParole = Round(_GetTextLength($riga & $arrayParole[$j] & " ", $sFontAlias, $iTextHeight)) if $iRowLengthParole < $iWidth Then $riga &= $arrayParole[$j] & " " Else _DrawText($iX, $iY - ($i * $iRowHeight)-$ExtraHeight, $riga, $sFontAlias, $iTextHeight, $PDF_ALIGN_LEFT, 0) $riga = $arrayParole[$j] & " " $ExtraHeight += $iRowHeight EndIf Next _DrawText($iX, $iY - ($i * $iRowHeight)-$ExtraHeight, $riga, $sFontAlias, $iTextHeight, $PDF_ALIGN_LEFT, 0) Else . . . . . . . . </SPAN> you can justify text? Link to comment Share on other sites More sharing options...
Virgilio1 Posted November 4, 2011 Share Posted November 4, 2011 Hi, I find the functions to create pdf files really useful. I wish I could justify the text that makes up a paragraph. thanks Link to comment Share on other sites More sharing options...
Virgilio1 Posted November 4, 2011 Share Posted November 4, 2011 You can add other fonts than those already included? Link to comment Share on other sites More sharing options...
Efo74 Posted November 13, 2011 Share Posted November 13, 2011 Thank you for this beautiful UDF. It is very simple to use. But I have a problem when I use the caracters "à " "è" ecc. with font Bold or Italic. The line in the pdf file is printed with not correct space between words. Sorry for english. And Thank you for the help. :rolleyes: Link to comment Share on other sites More sharing options...
Zedna Posted November 16, 2011 Share Posted November 16, 2011 GREAT!!! I appreciate very much rewriting of this UDF to not be dependent on any external DLL Of course five stars from me. I will use it definitely in my current project. Thanks. Anyway I probably discovered small bug: In Example_Mixed.au3 there is _DrawText() with $PDF_ALIGN_CENTER/$PDF_ALIGN_LEFT/$PDF_ALIGN_RIGHT but in generated opened PDF there is align left/right swapped. So propably $PDF_ALIGN_LEFT/$PDF_ALIGN_RIGHT are swapped? Also your example for Listview2PDF posted in this topic could be bundled in UDF's ZIP archive. Resources UDF Â ResourcesEx UDF Â AutoIt Forum Search Link to comment Share on other sites More sharing options...
taietel Posted November 17, 2011 Author Share Posted November 17, 2011 @Virgilio1: For justified paragraph, try to use Garamond (I use this mostly). Regarding adding more fonts: of course you can add. @Efo74: That's because the ANSI encoding of fonts in this UDF. @Zedna: I'm glad you use it! About the aligning, I think it is OK: #include "MPDF_UDF.au3" _SetTitle("Demo PDF in AutoIt") _SetSubject("Demo PDF in AutoIt, without any ActiveX or DLL...") _SetKeywords("pdf, demo, 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) _InitPDF(@ScriptDir & "Example_aligned.pdf") _LoadFontTT("_Garamond", $PDF_FONT_GARAMOND) _BeginPage() _DrawLine(3, 25, 3, 21, $PDF_STYLE_STROKED, 3, 0.05, 0x990000, 0, 0) _SetColourFill(0x111111) _DrawText(3, 24, "AutoIt left", "_Garamond", 22, $PDF_ALIGN_LEFT, 0) _DrawText(3, 23, "AutoIt center", "_Garamond", 22, $PDF_ALIGN_CENTER, 0) _DrawText(3, 22, "AutoIt right", "_Garamond", 22, $PDF_ALIGN_RIGHT, 0) _SetColourFill(0) _EndPage() _ClosePDFFile() Sorry for the delay. Now I have 4 jobs and no time. Regards, taietel Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text Link to comment Share on other sites More sharing options...
Zedna Posted November 17, 2011 Share Posted November 17, 2011 @Zedna: I'm glad you use it! About the aligning, I think it is OK:Sorry, I don't think so.Here is screenshot from your last example for align - opened in Adobe Reader 9.3 Czech Resources UDF Â ResourcesEx UDF Â AutoIt Forum Search Link to comment Share on other sites More sharing options...
taietel Posted November 17, 2011 Author Share Posted November 17, 2011 Yes, the image that you have posted shows that the alignment is ok (relative to the red line - that's why I draw it in the example). Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text Link to comment Share on other sites More sharing options...
BrewManNH Posted November 17, 2011 Share Posted November 17, 2011 Shouldn't align left have the text on the left side of the page and align right have it on the right side of the page? Having it align to the center of the page makes no sense. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator Link to comment Share on other sites More sharing options...
Zedna Posted November 17, 2011 Share Posted November 17, 2011 (edited) Now I looked into sources to see what's going on there and there is really bug in DrawText() original Func _DrawText($iX, $iY, $sText, $sFontAlias, $iFontSize, $iAlign = $PDF_ALIGN_LEFT, $iRotate = 0) ... Switch $iAlign Case $PDF_ALIGN_LEFT Case $PDF_ALIGN_RIGHT $l = _GetTextLength($sText, $sFontAlias, $iFontSize) $iX -= $l Case $PDF_ALIGN_CENTER $l = _GetTextLength($sText, $sFontAlias, $iFontSize) $iX -= $l / 2 EndSwitch ... fixed Func _DrawText($iX, $iY, $sText, $sFontAlias, $iFontSize, $iAlign = $PDF_ALIGN_LEFT, $iRotate = 0) ... Switch $iAlign Case $PDF_ALIGN_LEFT Case $PDF_ALIGN_RIGHT $l = _GetTextLength($sText, $sFontAlias, $iFontSize) $iX += $l Case $PDF_ALIGN_CENTER $l = _GetTextLength($sText, $sFontAlias, $iFontSize) $iX += $l / 2 EndSwitch ... $iX -= was incorrect there must be $iX += Here is screenshot of correct result after that fix Edited November 17, 2011 by Zedna Resources UDF Â ResourcesEx UDF Â AutoIt Forum Search Link to comment Share on other sites More sharing options...
Zedna Posted November 17, 2011 Share Posted November 17, 2011 (edited) Adition to my previous post: Now as I more look at the align code/results I see original idea of author :-) Alignment in original way means that X parameter is related to left/center/right edge of text so with $PDF_ALIGN_RIGHT X means not left but right position of text! But that way is uncommon in any other development tools/APIs as far as I know It is common that X means always left position. In sense of that enlightment I think it would be better to add new optional parameter W (width) and make alignment related to this X and X+W --> right corner of text implicitly W=_GetTextLength($sText, $sFontAlias, $iFontSize) Edited November 17, 2011 by Zedna Resources UDF Â ResourcesEx UDF Â AutoIt Forum Search Link to comment Share on other sites More sharing options...
taietel Posted November 17, 2011 Author Share Posted November 17, 2011 @BrewManNHShouldn't align left have the text on the left side of the page and align right have it on the right side of the page?That's exactly what the alignment in the UDF do, but relative to a imaginary border. If you begin to write a text 2 cm from the left, and choose left alignment, it will flow in the right direction. If you choose right alignment, but start in the same point (2 cm from the left), the text will flow on the left.Having it align to the center of the page makes no sense. @ZednaAlignment in original way means that X parameter is related to left/center/right edge of textThat was the idea. Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text Link to comment Share on other sites More sharing options...
Zedna Posted November 17, 2011 Share Posted November 17, 2011 @ZednaThat was the idea.OK.Now when I know it's not bug and I exactly know how to use it in this way despite it's not standard behaviour I can live it :-)Thanks for feedback and confirmation. Resources UDF Â ResourcesEx UDF Â AutoIt Forum Search Link to comment Share on other sites More sharing options...
faustf Posted December 9, 2011 Share Posted December 9, 2011 hi guy i have a questions is possble save directly in hd the pdf , whit out open? ? 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