Jump to content
taietel

Create PDF from your application

Recommended Posts

@StuffByDennis

If you don't use these fonts, just remove the code which is causing the problem, thats what i did.

Or search the internet and download the files and recreate them with the code -> second post on page 6.

I believe this code is based on

Basicly this embedding is useless because it isn't used as it supposed to be.. because the files are saved. I would prefer to use the

Sounds good but how do I remove the code. It's compiled binary.

I opened the test.pdf file from the latest download of Dec 7,2010 and it also had the BBOX error for Arial-Bold.

Thanks for your interest.

StuffByDennis

Share this post


Link to post
Share on other sites

Updated first post:

- no need for external fonts

- no need for the ActiveX (now it's just AutoIt)

- I've made it an UDF (kind of...)

- increased speed in pdf generation

- supports multiple image formats (bmp, png, jpg, tif, gif...)

- new functions (existing are obsolete)

- you can add your own functions

Sorry for answering so late!

Emiel, the code is NOT based on Ward's code. :huh2: It's just based on transformation in/from binary.

taietel

[edit] I still need to write a better description to the functions...

Edited by taietel

Share this post


Link to post
Share on other sites

@taietel

Thanks for the nice work

***** Edit *****

Sorry.. it's not nice work .. it's a master piece :huh2:

Thanks again

Edited by Emiel Wieldraaijer

Best regards,Emiel Wieldraaijer

Share this post


Link to post
Share on other sites

Thanks Emiel.

Here is another examples of converting images to pdf:

#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($PDF_PAGE_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", @MyDocumentsDir & "\", "Images (*.jpg;*.bmp;*gif;*png;*tif)", 1 + 4 )
If @error Then
    MsgBox(4096,"","No File(s) chosen")
Else
     $var = StringSplit($var, "|", 2)
EndIf

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

;then, finally, write the buffer to disk
_ClosePDFFile()

and text files:

#include "MPDF_UDF.au3"
#include <file.au3>

Global $sF = FileOpenDialog("Choose a text file", @ScriptDir & "\", "Text file (*.au3;*.txt;*.ini)", 1)

If @error Then
 MsgBox(4096, "", "No File(s) chosen")
Else
 ;set the properties for the pdf
 _SetTitle("Txt2PDF")
 _SetSubject("Convert text file to pdf")
 _SetKeywords("pdf, AutoIt")
 _OpenAfter(True);open after generation
 _SetUnit($PDF_UNIT_CM)
 _SetPaperSize($PDF_PAGE_A4)
 _SetZoomMode($PDF_ZOOM_CUSTOM, 90)
 _SetOrientation($PDF_ORIENTATION_PORTRAIT)
 _SetLayoutMode($PDF_LAYOUT_CONTINOUS)

 ;initialize the pdf
 _InitPDF(@ScriptDir & "\Demo.pdf")
 _LoadFontTT("T", $PDF_FONT_TIMES)
 ;=== load resources used in pdf ===
 _Txt2PDF($sF, "T")
 ;write the buffer to disk
 _ClosePDFFile()
EndIf

; #FUNCTION# ====================================================================================================================
; Name ..........: _Txt2PDF
; Description ...: Convert a text file to pdf
; Syntax ........: _Txt2PDF( $sText , $sFontAlias  )
; Parameters ....: $sText               -  file path.
;                  $sFontAlias          -  font alias.
; Return values .: None
; Author(s) .....: Mihai Iancu (taietel at yahoo dot com)
; Modified ......:
; Remarks .......: If the string is very long, it will be scaled to paper width
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _Txt2PDF($sFile, $sFontAlias)
 Local $hFile = FileOpen($sFile)
 Local $sText = FileRead($hFile)
 FileClose($hFile)

 Local $iUnit = Ceiling(_GetUnit())
 Local $iX = 2
 Local $iY = Ceiling(_GetPageHeight() / _GetUnit()) - 1.5
 Local $iPagina = Ceiling(_GetPageWidth() / $iUnit) - $iX
 Local $iWidth = Ceiling($iPagina - $iX);, 1)
 Local $lScale
 Local $iRanduri = StringSplit($sText & @CRLF & @CRLF & @CRLF, @CRLF, 3)
 Local $iHR = 0.5 * Ceiling($iY / (14.4 * $iUnit))
 Local $iPages = Ceiling((UBound($iRanduri)) * $iHR / $iY)
 Local $iNrRanduri = Ceiling(UBound($iRanduri) / $iPages)

 For $j = 0 To $iPages - 1
  _BeginPage()
  For $i = 0 To $iNrRanduri - 1
   Local $sLength = Round(_GetTextLength($iRanduri[$i + $j * $iNrRanduri], $sFontAlias, 12))
   Local $iH = $iY - $iHR * ($i + 1)
   Select
    Case $iH < 1
     _EndPage()
    Case $i + $j * $iNrRanduri = UBound($iRanduri) - 1
     _EndPage()
     Return
    Case $sLength > $iWidth - 1
     $lScale = Ceiling($iWidth * 100 / $sLength)
     _SetTextHorizontalScaling($lScale)
     _DrawText($iX, $iH, $iRanduri[$i + $j * $iNrRanduri], $sFontAlias, 12, $PDF_ALIGN_LEFT, 0)
     _SetTextHorizontalScaling(100)
    Case Else
     _DrawText($iX, $iH, $iRanduri[$i + $j * $iNrRanduri], $sFontAlias, 12, $PDF_ALIGN_LEFT, 0)
   EndSelect
  Next
 Next
EndFunc   ;==>_Txt2PDF
Edited by taietel

Share this post


Link to post
Share on other sites

If you want to output pdf's from your application, you can use this ActiveX DLL (embeded in the script). It's small and very easy to use. Here is a screenshot of the first page generated by the example.

Posted Image

First, unpack the Fonts directory in the scriptdir (if you put it in another location, replace the path in the script).

[EDIT] Deleted old version (165 downloads) and uploaded new one*

*all included in the au3

[uPDATED] New version: There's no need for external fonts or ActiveX. Now there are just AutoIt functions.

New example: Image2PDF

taietel,

Thank you for the UDF version of your PDF output routines.

I have the following comments to make:

1: The 0,0 of your ddl was the uper left of the page while the 0,0 is the lower left.

Not a big problem but needs to be made known.

2: There is an error in your MPDF_UDF.au3 file.

The program tries to open the Demo.pdf when another name is specified.

The fix is simple. I added the following line after the line: Func _InitPDF($sFileName = $PDF_NAME)

$PDF_NAME=$sFileName

3: Opening up the generated PDF file produces an error unless the following statements are added:

_StartObject("Antet", $PDF_OBJECT_NOTFIRSTPAGE)

_EndObject()

This appears to be needed even if no object is used.

Again no big problem. Easy workaround.

4. There is a problem with the PDF file when printing.

This happens even with your Demo.pdf.

It still prints but I get a message when printing.

May be my problem - still looking into it.

5. There is a problem with the Dash on - Dash off functions.

When trying to produce a dashed line, a solid .5 pt line is also produced.

it is as though the space between the dashes is filled with a solid .5 pt line.

run the attached au3 file for an example.

6. I don't know what the dash on and dash off values mean but they don't mean

x units on, x units off

Again it's easy to see via the attached au3 file.

Again this was a great effort on your part and it has saved me a lot of work.

Except for comment #5, I can put up with the problems.

StuffByDennis

DASHES.au3

Share this post


Link to post
Share on other sites

1. I had to make a program for filling some data on a picture as background for the pdf and that's why I've changed

2. Fixed (thanks!). Updated first post (examples included).

3. Look at the example from the Text2PDF. There are no objects in there.

4. What message? I've tested at school and at home (two printers) and there's no error message.

5. This is how it should be?:

#include "MPDF_UDF.au3"
#Region GLOBAL VARIABLES

_CreatePDF()

Func _CreatePDF()
 Local $i, $j, $s, $temp, $p
 ;set the properties for the pdf
 _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_PT)
 _SetPaperSize($PDF_PAGE_LETTER)
 _SetZoomMode($PDF_ZOOM_FULLWIDTH)
 _SetOrientation($PDF_ORIENTATION_PORTRAIT)
 _SetLayoutMode($PDF_LAYOUT_CONTINOUS)

 ;initialize the pdf
 _InitPDF(@ScriptDir & "\Denis.pdf")

 ;fonts:
 _LoadFontTT("_Courier", $PDF_FONT_COURIER)
 _LoadFontTT("_Arial", $PDF_FONT_ARIAL)
 _LoadFontTT("_TimesT", $PDF_FONT_TIMES)

 _StartObject("Antet", $PDF_OBJECT_NOTFIRSTPAGE)
 _EndObject()

 _BeginPage()
 Local $i, $j, $k, $l
 For $l = 2 To 5
   _DrawText(100, 770, " Dash off to Dash on ratio = "&$l, $PDF_FONT_ARIAL, 8, $PDF_ALIGN_LEFT, 0)
  #cs
  For $i = 50 To 500 Step 5
   _DrawLine($i, 710, $i, 200, $PDF_STYLE_STROKED, 1, .5, 0x000000, 0, 0)
  Next
  #ce
  $j = 700
  For $k = 1 To 25
   _DrawText(100, $j + 2, StringFormat("Dash on = %.2d , Dash off = %.2d", 5 * $k, 5*$l * $k), $PDF_FONT_ARIAL, 8, $PDF_ALIGN_LEFT, 0)
   _DrawLine(50, $j, 500, $j, $PDF_STYLE_STROKED, 0, 2, 0xff0000, 5 * $k, 5*$l * $k)
   $j -= 20
  Next

  _EndPage()
  _BeginPage()
   _DrawText(100, 770, " Dash off to Dash on ratio = "&$l, $PDF_FONT_ARIAL, 8, $PDF_ALIGN_LEFT, 0)
  #cs
  For $i = 50 To 750 Step 5
   _DrawLine(50, $i, 550, $i, $PDF_STYLE_STROKED, 1, .5, 0x000000, 0, 0)
  Next
  #ce
  $j = 70
  For $k = 1 To 25
   _DrawText($j - 2, 400, StringFormat("Dash on = %.2d , Dash off = %.2d", 5 * $k, 5*$l * $k), $PDF_FONT_ARIAL, 8, $PDF_ALIGN_LEFT, 90)
   _DrawLine($j, 50, $j, 750, $PDF_STYLE_STROKED, 0, 2, 0xff0000, 5 * $k, 5*$l * $k)
   $j += 20
  Next
  _EndPage()
  _BeginPage()
 Next
 _EndPage()
 _ClosePDFFile()

EndFunc   ;==>_CreatePDF

6. On/Off means how many units are in the line. E.g. if On is 5 and Off is 3, the line is divided in small lines, 5 units each, with gaps of 3 units.

Share this post


Link to post
Share on other sites

1. I had to make a program for filling some data on a picture as background for the pdf and that's why I've changed

2. Fixed (thanks!). Updated first post (examples included).

3. Look at the example from the Text2PDF. There are no objects in there.

4. What message? I've tested at school and at home (two printers) and there's no error message.

5. This is how it should be?:

#include "MPDF_UDF.au3"
#Region GLOBAL VARIABLES

_CreatePDF()

Func _CreatePDF()
 Local $i, $j, $s, $temp, $p
 ;set the properties for the pdf
 _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_PT)
 _SetPaperSize($PDF_PAGE_LETTER)
 _SetZoomMode($PDF_ZOOM_FULLWIDTH)
 _SetOrientation($PDF_ORIENTATION_PORTRAIT)
 _SetLayoutMode($PDF_LAYOUT_CONTINOUS)

 ;initialize the pdf
 _InitPDF(@ScriptDir & "\Denis.pdf")

 ;fonts:
 _LoadFontTT("_Courier", $PDF_FONT_COURIER)
 _LoadFontTT("_Arial", $PDF_FONT_ARIAL)
 _LoadFontTT("_TimesT", $PDF_FONT_TIMES)

 _StartObject("Antet", $PDF_OBJECT_NOTFIRSTPAGE)
 _EndObject()

 _BeginPage()
 Local $i, $j, $k, $l
 For $l = 2 To 5
   _DrawText(100, 770, " Dash off to Dash on ratio = "&$l, $PDF_FONT_ARIAL, 8, $PDF_ALIGN_LEFT, 0)
  #cs
  For $i = 50 To 500 Step 5
   _DrawLine($i, 710, $i, 200, $PDF_STYLE_STROKED, 1, .5, 0x000000, 0, 0)
  Next
  #ce
  $j = 700
  For $k = 1 To 25
   _DrawText(100, $j + 2, StringFormat("Dash on = %.2d , Dash off = %.2d", 5 * $k, 5*$l * $k), $PDF_FONT_ARIAL, 8, $PDF_ALIGN_LEFT, 0)
   _DrawLine(50, $j, 500, $j, $PDF_STYLE_STROKED, 0, 2, 0xff0000, 5 * $k, 5*$l * $k)
   $j -= 20
  Next

  _EndPage()
  _BeginPage()
   _DrawText(100, 770, " Dash off to Dash on ratio = "&$l, $PDF_FONT_ARIAL, 8, $PDF_ALIGN_LEFT, 0)
  #cs
  For $i = 50 To 750 Step 5
   _DrawLine(50, $i, 550, $i, $PDF_STYLE_STROKED, 1, .5, 0x000000, 0, 0)
  Next
  #ce
  $j = 70
  For $k = 1 To 25
   _DrawText($j - 2, 400, StringFormat("Dash on = %.2d , Dash off = %.2d", 5 * $k, 5*$l * $k), $PDF_FONT_ARIAL, 8, $PDF_ALIGN_LEFT, 90)
   _DrawLine($j, 50, $j, 750, $PDF_STYLE_STROKED, 0, 2, 0xff0000, 5 * $k, 5*$l * $k)
   $j += 20
  Next
  _EndPage()
  _BeginPage()
 Next
 _EndPage()
 _ClosePDFFile()

EndFunc   ;==>_CreatePDF

6. On/Off means how many units are in the line. E.g. if On is 5 and Off is 3, the line is divided in small lines, 5 units each, with gaps of 3 units.

Thank you for your quick reply.

I'll address comment 6 first.

I had 25 years of experience in the electrostatic plotting of micro electronic circuit design for Xerox.

That is my mindset so I need to see if I understand what you are saying, printing may be different than how I look at things.

If you run the au3 file I sent you will notice that the first line had a dash on of 5 and a dash off of 10.

When you look at the top line is has a red line 10 on and 5 off, just the reverse.

The width of the line was specified as 2pt's and a color of red. The space between the red lines is filled with a .5 wide black line.

If I were to ask for a .5 pt black dashed line I would (and did) get a solid black line.

If the output is what you wanted then I will accept it and write a routine to do the dashes as I understand and want them be.

And now for the interesting and confusing further research about comments 3 and 4.

If I do not add the object statements I get the error output indicated in the attachment PDF Printing Error.jpg.

When I ran the Text2PDF sample I got the same error message. When I added the object statements I did not get the error message.

Each time I got the message when I sent the file to the printer from adobe reader 9.

This is where things get really wierd.

When I run the dashes.au3 file I sent you I got the error message when I tried to print the file.

when I run the file you attached (My origional file with calabration lines removed) I get the message shown in PDF reading error.jpg when the pdf file is viewed after the file is closed.

I have run them several times and had the same results each time. There is nothing random here.

I am running 64 bit Windows 7 but I installed 32bit Autoit.

Next I will try the following.

Reinstall adobe reader.

If that does not work then I will reinstall Autoit.

If that still does not work then I will reinstall Windows 7 and all programs.

If that doesn't work I will have some very nasty things to say about Microsoft (again).

Computers are a young mans game.

I am getting way to old for this to happen in my stage of life.

Thank you for hearing me out.

Be Well

StuffByDennis

post-4571-0-28432000-1308381465_thumb.jp

post-4571-0-55240800-1308381481_thumb.jp

Share this post


Link to post
Share on other sites

Denis, I will install Acrobat (I use only FoxitReader) to see if the error appears and get back to you.

taietel

[EDIT]: Done. I've installed Adobe Reader X and it gives me that error. As far as I remember (why I use Foxit Reader) I gave up AR because it is big, it's loading much slower and throws errors. I've notice that when I open a pdf it modifies and ask me to save it. If you google "There was an error reading this document", you will get a lot of information about Adobe Reader (in almost any version). I will not uninstall AR (till I see what seems to be the problem), but I'll keep using FoxitReader (at school we have it also).

Try opening your pdf's with FoxitReader. If you don't like it, just uninstall it but, in my opinion, you should give it a try.

Best regards,

taietel

Edited by taietel

Share this post


Link to post
Share on other sites

I would also recommend Foxit Reader; it's fast. light and best of all for me, can silently

print a PDF file via command line (can also install silent).

Using this UDF, the PDFCreator COM interface, Foxit Reader and IrfanView, I have been

able to completely automate scanning, converting, splitting, combining new or existing docs

from paper, Word, TIF, JPG or any printable doc to PDF, ready for fax, email, print or archive and

finally generate a PDF work order, report or invoice which I can print or email.

Thank you @taitel, you have made my work so much easier, smarter and professional.

Share this post


Link to post
Share on other sites

Denis, I will install Acrobat (I use only FoxitReader) to see if the error appears and get back to you.

taietel

[EDIT]: Done. I've installed Adobe Reader X and it gives me that error. As far as I remember (why I use Foxit Reader) I gave up AR because it is big, it's loading much slower and throws errors. I've notice that when I open a pdf it modifies and ask me to save it. If you google "There was an error reading this document", you will get a lot of information about Adobe Reader (in almost any version). I will not uninstall AR (till I see what seems to be the problem), but I'll keep using FoxitReader (at school we have it also).

Try opening your pdf's with FoxitReader. If you don't like it, just uninstall it but, in my opinion, you should give it a try.

Best regards,

taietel

Taietel,

Sorry for the late response but my out of town visitors just left.

Anyway I installed and tested FoxitReader. It worked as advertised. Thank you, I will switch over to it.

I am in the process of writing 2 UDF's which I will need for my work.

The descriptions are:

; #FUNCTION# ====================================================================================================================

; Name ..........: _Draw_Path

; Description ...: Draws a N segmented line, each line segment is expressed as N repeating sub segments.

; Each sub segment has its own "PEN DOWN" length,line width, color and cap type followed by a "PEN UP" length

; Syntax ........: _Draw_Path( ByRef Const $iXY, ByRef Const $iDU )

; Parameters ....: $iXY is a 2 dimensional array where:

; $iXY[0][0] contains the number of points in the path

; $iXY[0][1] contains the coordinate type 0 = absolute to 0,0 of page, 1=relative to previous coordinate

; $iXY[N][0] X or distance from left of page or previous point

; $iXY[N][1] Y or distance from bottom of page or previous point

; : $iDU is a 1 or 2 dimensional array where:

; for a solid line

; $iDU[0]= Line width

; $iDU[1]= Line cap type

; $iDU[2]= Line color

; for a "DASHED" line $iDU[0][0]= number of sub segments before repeating

; $iDU[N][0]= Number of "PEN DOWN" units for the Nth sub segment

; $iDU[N][1]= Line width for the Nth sub segment

; $iDU[N][2]= Line cap type for the Nth sub segment

; $iDU[N][3]= Line color for the Nth sub segment

; $iDU[N][4]= Number of "PEN UP" units for the Nth sub segment

; Return values .: None

; Author(s) .....: StuffByDennis

; Modified ......:

; Remarks .......:

; Related .......:

; Link ..........:

; Example .......: No

; ===============================================================================================================================

and

; #FUNCTION# ====================================================================================================================

; Name ..........: _Draw_Polygon

; Description ...: Draws a N sided filled polygon

; The perimiter is drawn by the _Draw_Path function.

; Syntax ........: _Draw_Polygon( ByRef Const $iXY, $iFC, ByRef Const $iDU )

; Parameters ....: $iXY (See _Draw_Path for description)

; : $iFC polygon fill color

; : $iDU (See _Draw_Path for description)

; Return values .: None

; Author(s) .....: StuffByDennis

; Modified ......:

; Remarks .......:

; Related .......:

; Link ..........:

; Example .......: No

; ===============================================================================================================================

If you are interested in adding them to your UDF file let me know.

Again thank you for your work and help.

Be Well

StuffByDennis

Share this post


Link to post
Share on other sites

StuffByDennis, of course I can add those functions. Maybe others (and me, in the near future) sure will make use of them. And also others can contribute to the UDF.

Don't be sorry for the late responses. :huh2: I'm short of time either.

Regards,

taietel

P.S. Updated first post with another example and some changes (since you are here, you can download all directly from Here).

Share this post


Link to post
Share on other sites

Amazing piece of code.

Thank you.

Is there a way to make coloured lines thinner?

I'm using this:

_DrawLine(2.15, 19.2, 19, 19.2, $PDF_STYLE_STROKED, 1, 0, 0x16007B, 10, 0)

But it's still very thick.

If i draw a rectangle, i can make it thinner, but i can't get the borderline coloured, only black.

And, if it's not to much to ask... can i digitally sign the pdf, with a certificate?

PLEASE, keep up the great work! :)

Share this post


Link to post
Share on other sites

Something like this?

_DrawLine(2.15, 19.2, 19, 19.2, $PDF_STYLE_STROKED, 1, 0.01, 0x16007B)

Regarding signing, you can not. This is something I've made to help me generate some reports, graphs etc . It's not perfect, but it helped me a lot at school.

Share this post


Link to post
Share on other sites

:) Almost that, but i already have the certificates, i just want to apply them automatically via Autoit or via command line or something, after i make the PDF with your script.

By the way... is there a way to put a picture in the PDF in the original size, 'as is', without the stretch/resizing?

Sent you a PM.

Share this post


Link to post
Share on other sites

Yes, there is:

in MIPDF.au3, modify _InsertImage function:

Func _InsertImage($sAlias, $iX, $iY, $iW = 0, $iH = 0)
    If $iW = 0 And $iH = 0 Then
        $iW = $_iImageW/_GetUnit()
        $iH = $_iImageH/_GetUnit()
    EndIf
    __ToBuffer("q" & @CRLF & __ToStr(__ToSpace($iW)) & " " & " 0 0 " & __ToStr(__ToSpace($iH)) & " " & __ToStr(__ToSpace($iX)) & " " & __ToStr(__ToSpace($iY)) & " cm" & "/" & $sAlias & " Do" & @CRLF & "Q")
EndFunc   ;==>_InsertImage

and as example:

#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 & "\image.pdf")

;=== load resources used in pdf ===
_LoadResImage("someimage", @ScriptDir&"\png.png")

;load image
_BeginPage()
 ;insert image at 10 cm from the left and 15 cm from the bottom, without modifying the dimensions (just put 0 for width and height)
    _InsertImage("someimage", 10,15,0,0)
    ;insert image  at 5 cm from the left and 10 cm from the bottom,  with different width/height (w=5, h=3)
    _InsertImage("someimage", 5,10,5,3)
_EndPage()

;then, finally, write the buffer to disk
_ClosePDFFile()

I will update the first post with more examples, as soon as possible.

Regards,

taietel

Share this post


Link to post
Share on other sites

hmmm... I had already tried that, here's what happens...:

Original image:

In PDF using your example:

http://static.inky.ws/image/441/image.jpg

I've tried it with png and jpg.

Am i the only one with this problem?

EDIT: Ok, i had a different func in MPDF_UDF.au3.

Func _InsertImage($sAlias, $iX, $iY, $iW = 0, $iH = 0)
    If $iW = 0 And $iH = 0 Then
        $iW = $_iImageW
        $iH = $_iImageH
    EndIf
    __ToBuffer("q" & @CRLF & __ToStr(__ToSpace($iW)) & " " & " 0 0 " & __ToStr(__ToSpace($iH)) & " " & __ToStr(__ToSpace($iX)) & " " & __ToStr(__ToSpace($iY)) & " cm" & "/" & $sAlias & " Do" & @CRLF & "Q")
EndFunc   ;==>_InsertImage

But the image still appear twice as big as the original :S

Edited by pintas

Share this post


Link to post
Share on other sites

pintas (sorry for the delay, but I'm on a slow connection), I've downloaded the image from the first link and tested:

#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 & "\image.pdf")

;=== load resources used in pdf ===
_LoadResImage("someimage", @ScriptDir&"\thumb.jpg")

;load image
_BeginPage()
    ;insert image without modifying the dimensions
    _InsertImage("someimage", 10,15,0,0)
_EndPage()

;then, finally, write the buffer to disk
_ClosePDFFile()

Run this example (first modify the _InsertImage function from the UDF as I have posted before) and see if it's ok.

[EDIT] Here's a screenshot of the result: Posted Image

Edited by taietel

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...