happytc Posted August 9, 2011 Posted August 9, 2011 (edited) happytc, have you tried the version from the post #95?No, I'm not using FlatDecode in the UDF.Yes, testing Example_Image2PDF.au3 in MPDF_UDF_102: F5 -> select image files -> get file Demo.pdf -> open by Acrobat readerThe screenshot Error info: Edited August 9, 2011 by happytc
happytc Posted August 9, 2011 Posted August 9, 2011 the pdfAutoit.au3 from the Post#1, it's working fine!
taietel Posted August 9, 2011 Author Posted August 9, 2011 Yes, testing Example_Image2PDF.au3 in MPDF_UDF_102: F5 -> select image files -> get file Demo.pdf -> open by Acrobat readerAs I see, you run the example that converts images to pdf and pick a pdf as image? Is it not obvious why that error appear?Try again, but WITH some REAL image files (jpg, bmp, png, gif, tif ...), not text files, and see if it works. 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
happytc Posted August 9, 2011 Posted August 9, 2011 As I see, you run the example that converts images to pdf and pick a pdf as image? Is it not obvious why that error appear?Try again, but WITH some REAL image files (jpg, bmp, png, gif, tif ...), not text files, and see if it works.No, I selected real image file from my computer.BTW:the example of Example_Txt2PDF.au3 in the MPDF_UDF_102 worked
taietel Posted August 9, 2011 Author Posted August 9, 2011 I'm sure it worked (Example_Txt2PDF.au3) because this one is an example for text file. Post that image that didn't worked with the Example_Image2PDF.au3. My guess is that you changed this line $var = FileOpenDialog("Select images", @ScriptDir & "\", "Images (*.jpg;*.bmp;*gif;*png;*tif)", 1 + 4 ) by adding non-image files, hence the error. 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
happytc Posted August 9, 2011 Posted August 9, 2011 The image files i tested from your old examples. I don't modify the Example_Image2PDF.au3. now, i add a line: MsgBox(0,0,$var),it displays:
taietel Posted August 9, 2011 Author Posted August 9, 2011 (edited) Ok, now please post the corrupted pdf that resulted from running the example with the above pictures. I'll take a look at that.I've tested (again) now and in the attachment is the result.Demo.pdf Edited August 9, 2011 by 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
happytc Posted August 9, 2011 Posted August 9, 2011 Ok, now please post the corrupted pdf that resulted from running the example with the above pictures. I'll take a look at that.I've tested (again) now and in the attachment is the result.No problem to open your pdf file
taietel Posted August 9, 2011 Author Posted August 9, 2011 happytc, as I said,...please post the corrupted pdf that resulted from running the example with the above picturesI didn't said to post a screenshot!I know is not a problem with that pdf and also know that you have tested with those images and it's fine too, except the first time when instead of an image you have chosen a pdf file. 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
happytc Posted August 9, 2011 Posted August 9, 2011 happytc, as I said,I didn't said to post a screenshot!I know is not a problem with that pdf and also know that you have tested with those images and it's fine too, except the first time when instead of an image you have chosen a pdf file.Here the file!I followed MPDF_UDF.au3, and found the function __ToBinary() had a problem: StringLen(BinaryToString($Bin)) = 2667, but msgbox(0,0,BinaryToString($Bin)) was only displayed: ?msgbox(0,0,$Bin) is OK!Func __ToBinary($sImage) Local $hFile, $Bin $hFile = FileOpen($sImage, 16) $Bin = FileRead($hFile) FileClose($hFile) Return BinaryToString($Bin)EndFunc
taietel Posted August 9, 2011 Author Posted August 9, 2011 happytc, the pdf that you have posted IS NOT CONTAINING any of the images you said you have tested with (or at least a fragment of them). If you changed the UDF without knowing what you are doing, it's your problem. 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
happytc Posted August 9, 2011 Posted August 9, 2011 (edited) happytc, the pdf that you have posted IS NOT CONTAINING any of the images you said you have tested with (or at least a fragment of them). If you changed the UDF without knowing what you are doing, it's your problem.No, I haven't modified the functions. For proving this, I downloaded again from your post#95, and tried to test the function of Example_Image2PDF() again. The same error occured."(or at least a fragment of them)" ---- i don't know why it happened. I only did thing was following your example.By the way, I found the tmp image file generated by the function of _LoadResImage() was OK. Edited August 9, 2011 by happytc
taietel Posted August 9, 2011 Author Posted August 9, 2011 (edited) happytc, see this: Here is an example (addapted from Example_Image2Pdf.au3) to load one or more images:expandcollapse popup#include "MPDF_UDF.au3" ;set the properties for the pdf _SetTitle("Image2PDF") _SetSubject("Convert image(s) to 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 & "\Demo.pdf") ;=== load resources used in pdf === $var = FileOpenDialog("Select images", @ScriptDir & "\", "Images (*.jpg;*.bmp;*gif;*png;*tif)", 1 + 4 ) If @error Then MsgBox(4096,"","No File(s) chosen") Else If IsArray($var) Then ; check if use choose one image or more $var = StringSplit($var, "|", 2) For $i=1 To UBound($var)-1 _LoadResImage("taietel"&$i, $var[0]&"\"&$var[$i]) Next ;load each image on it's own page For $i = 1 To UBound($var)-1 _BeginPage() ;scale image to paper size! _InsertImage("taietel"&$i, 0, 0, _GetPageWidth()/_GetUnit(), _GetPageHeight()/_GetUnit()) _EndPage() Next Else _LoadResImage("taietel", $var) _BeginPage() ;scale image to paper size! _InsertImage("taietel", 0, 0, _GetPageWidth()/_GetUnit(), _GetPageHeight()/_GetUnit()) _EndPage() EndIf ;then, finally, write the buffer to disk _ClosePDFFile() EndIfTest it with one image and then another test with multiple images. As I've said in the posted link above, the original example was intended for multiple images, Edited August 9, 2011 by 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
taietel Posted August 10, 2011 Author Posted August 10, 2011 Updated first post (v1.0.3). happytc, I've fixed Example_Image2PDF.au3: the problem was with the $var (returned an array). Thanks. With this occasion I've rewrote also _LoadImageResource and made it smaller (got rid of the intermediary clone image in GDI+ stuff) and also the resulted pdf is smaller. See if it works for you now. 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
runsnake Posted August 10, 2011 Posted August 10, 2011 happytc, see this: Here is an example (addapted from Example_Image2Pdf.au3) to load one or more images: expandcollapse popup#include "MPDF_UDF.au3" ;set the properties for the pdf _SetTitle("Image2PDF") _SetSubject("Convert image(s) to 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 & "\Demo.pdf") ;=== load resources used in pdf === $var = FileOpenDialog("Select images", @ScriptDir & "\", "Images (*.jpg;*.bmp;*gif;*png;*tif)", 1 + 4 ) If @error Then MsgBox(4096,"","No File(s) chosen") Else If IsArray($var) Then ; check if use choose one image or more $var = StringSplit($var, "|", 2) For $i=1 To UBound($var)-1 _LoadResImage("taietel"&$i, $var[0]&"\"&$var[$i]) Next ;load each image on it's own page For $i = 1 To UBound($var)-1 _BeginPage() ;scale image to paper size! _InsertImage("taietel"&$i, 0, 0, _GetPageWidth()/_GetUnit(), _GetPageHeight()/_GetUnit()) _EndPage() Next Else _LoadResImage("taietel", $var) _BeginPage() ;scale image to paper size! _InsertImage("taietel", 0, 0, _GetPageWidth()/_GetUnit(), _GetPageHeight()/_GetUnit()) _EndPage() EndIf ;then, finally, write the buffer to disk _ClosePDFFile() EndIf Test it with one image and then another test with multiple images. As I've said in the posted link above, the original example was intended for multiple images, I tested this example and the examples on Post#1(Version 1.0.3-modified today), 4 examples: Example_Image2PDF.au3 Example_Mixed.au3 Example_Table.au3 Example_Txt2PDF.au3 Example_Table.au3 and Example_Txt2PDF.au3 worked But Example_Image2PDF.au3 and Example_Mixed.au3 didn't work rightly for open Example_mixed.pdf and Image2PDF.pdf by Foxit Reader: My Foxit Reader said: format error:not a PDF or corrupted. System: WinXP-SP3 System Language: Japanese
taietel Posted August 10, 2011 Author Posted August 10, 2011 runsnake, my testing environments are WinXP sp3 and Windows 7, both on 32 bit and language English. Please, do the following: open the pdf with notepad and post the last lines, starting with 4 0 obj and finishing with %%EOF: 4 0 obj <</ProcSet [/PDF/Text/ImageB/ImageC/ImageI]/XObject ......................................................................................... %%EOF 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
happytc Posted August 10, 2011 Posted August 10, 2011 runsnake, my testing environments are WinXP sp3 and Windows 7, both on 32 bit and language English. Please, do the following: open the pdf with notepad and post the last lines, starting with 4 0 obj and finishing with %%EOF: 4 0 obj <</ProcSet [/PDF/Text/ImageB/ImageC/ImageI]/XObject ......................................................................................... %%EOF I downloaded the MPDFv103 from your post#1 just a moment ago, then tested the four examples. The result was the same as runsnake's: Example_Image2PDF.au3 -> select image file: bmp.bmp, gif.gif, ico.ico Example_Mixed.au3 Example_Table.au3 Example_Txt2PDF.au3 The two error pdf files here(there's no '4 0 obj' in the pdf): my testing environments: Windows XP-sp3, 32bit, Chinese language
taietel Posted August 10, 2011 Author Posted August 10, 2011 happytc thank you for posting the results: I've just compared the Image2PDF results:Here is the corresponding part of the icon image (16x16), on the left is the corrupted pdf and on the right is the working one; there are missing bites on the left (see the 6 0 obj compared to 10 0 obj on the right). The objects are different because we have selected images in different order, that's not important. I think the code is altered because of the system language (Chinese or Japanese). Why? I really don't know! I have only tested on English systems because I use those.I'll search for a solution. 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
xavierh Posted August 10, 2011 Posted August 10, 2011 Taietel, First, your udf is awesome. I have an issue with it, though. It generates a pdf that works fine on my 16 bit xp machine. But the same file has a problem on all 64 bit machines I have tried. They are windows 7 and windows 2008 r1 machines. Acrobat refuses to open the file and has this error: "There was an error processing a page. There was a problem reading this document (135)." If I remove all the autoit code from your sample that has to do with setting fonts and displaying text, it works fine, and only inserts images in the pdf. But if I even just restore a _LoadFontTT command, the acrobat error when trying to open the pdf is back. So I looked at your _LoadFontTT function and found that there is a missing space just after "/LastChar". Adding the space makes it work. __ToBuffer("<< /Type/Font/Subtype/TrueType/Name/" & $sAlias & "/BaseFont/" & $BaseFont & $sOptions & "/FirstChar " & $FirstChar & "/LastChar" etc should be __ToBuffer("<< /Type/Font/Subtype/TrueType/Name/" & $sAlias & "/BaseFont/" & $BaseFont & $sOptions & "/FirstChar " & $FirstChar & "/LastChar " etc otherwise the buffer you generate will have "/LastChar255" instead of "/LastChar 255" With this modification, I am able to generate a pdf with text that works on my 64 bit machines. Keep up the good work.
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