Jump to content

Create PDF from your application


taietel
 Share

Recommended Posts

What unit are you using?

[edit] Doesn't matter. The difference maybe lies in the fact that when printing, the pdf reader tends to shrink the page to less than 100%.

Edited by taietel
Link to comment
Share on other sites

rosmild, the problem lies within the GUI portion of your script. Can you post a simplified example?

[EDIT] Nope, in _ClosePDF(), at the end: just delete the word Exit just before EndFunc. I forgot to delete it (a sign of getting old? yep!).

Edited by taietel
Link to comment
Share on other sites

Hey taiatel, can you post an example how to use _GetTextLength?

I'm trying to center some text (with variable size) between two vertical lines, like this:

| text |

But when i do the following i get a value zero:

_DrawLine(13, 10, 13, 22, $PDF_STYLE_STROKED, 1, 0.01, 0x16007B)
_DrawLine(4, 10, 4, 22, $PDF_STYLE_STROKED, 1, 0.01, 0x16007B)
$sText="text string"
$size=_GetTextLength($sText, "_Arial_Bold", 14)
;~ msgbox("",$size,"")
_DrawText(9-$size/2, 15, StringUpper($sText), "_Arial_Bold", 14,$PDF_ALIGN_CENTER); pretending the space from line 1 to line 2 is size 9

I'm pretty sure i'm doing something wrong.... but what?

Link to comment
Share on other sites

Something like this (again, don't use Adobe Reader, use Foxit Reader):

#include "MPDF_UDF.au3"

;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_CM)
_SetPaperSize("A4")
_SetZoomMode($PDF_ZOOM_CUSTOM,90)
_SetOrientation($PDF_ORIENTATION_PORTRAIT)
_SetLayoutMode($PDF_LAYOUT_CONTINOUS)

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

;fonts:
_LoadFontTT("_Calibri", $PDF_FONT_CALIBRI)

;start a page
_BeginPage()
 $sText = "Anna Montes ridiculus, in penatibus, in aliquam enim sagittis pellentesque? Mattis duis et ut nunc sagittis enim "
 $sText &= "tortor urna, eros? Scelerisque? Dapibus scelerisque vel rhoncus porttitor! Porttitor ridiculus. In adipiscing augue "
 $sText &= "vel pellentesque tortor porta hac tristique turpis placerat scelerisque elementum hac pulvinar mid dolor pellentesque "
 $sText &= "lundium mattis nec. Nec sed. Et adipiscing nec nisi elementum natoque! Turpis penatibus est dictumst magnis integer "
 $sText &= "scelerisque, sociis, risus scelerisque ultrices auctor porta, enim? Ac montes pellentesque cum enim augue penatibus "
 $sText &= "pulvinar? Vel mid, cum habitasse etiam urna? In? Et, natoque! Integer odio egestas! Rhoncus a vut natoque pellentesque "
 $sText &= "diam lundium augue in mus. Auctor, dictumst lacus turpis phasellus etiam, proin mauris. Natoque ultricies turpis nisi "
 $sText &= "platea parturient? Nunc nascetur est, adipiscing enim turpis Mihai."

 _DrawLine(2, 22.5, 2, 17, $PDF_STYLE_STROKED, 10, 0.1, 0xff0000, 0, 0)
 _Paragraph($sText, 2.5, 22, 10, "_Calibri", 10, 0)
 _DrawLine(13, 22.5, 13, 17, $PDF_STYLE_STROKED, 10, 0.1, 0xff0000, 0, 0)

_EndPage()

;write the buffer to disk
_ClosePDFFile()
Link to comment
Share on other sites

Yeah, there's a difference with acrobat reader.

But i just want to center the text between the two lines.

That way i can only align it.

I'm looking for something like this:

|    text    |
|  sdflkjgs  |
|  asdfasdfasdfasdf  |
|    asdfasdfasdf    |
Edited by pintas
Link to comment
Share on other sites

There are many differences between Acrobat and Foxit. I'll try to make the resulted pdf's to look the same in both, but in time.

Regards,

taietel

[EDIT] I just saw you've edited your post.

To do that,

1. draw the lines

2. at half the distance between lines insert the text as usual, not paragraph, but aligned to center

#include "MPDF_UDF.au3"

;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_CM)
_SetPaperSize("A4")
_SetZoomMode($PDF_ZOOM_CUSTOM,90)
_SetOrientation($PDF_ORIENTATION_PORTRAIT)
_SetLayoutMode($PDF_LAYOUT_CONTINOUS)

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

;fonts:
_LoadFontTT("_TimesT", $PDF_FONT_TIMES)
_LoadFontTT("_Calibri", $PDF_FONT_CALIBRI)

;start a page
_BeginPage()
 $sText1 = "ridiculus"
 $sText2 = "tortor urna"
 $sText3 = "vel pellentesque"
 $sText4 = "lundium mattis"

 _DrawLine(2, 22.5, 2, 20, $PDF_STYLE_STROKED, 10, 0.1, 0xff0000, 0, 0)
 _DrawText(7.5, 22, $sText1, "_Calibri", 10, $PDF_ALIGN_CENTER)
 _DrawText(7.5, 21.5, $sText2, "_Calibri", 10, $PDF_ALIGN_CENTER)
 _DrawText(7.5, 21, $sText3, "_Calibri", 10, $PDF_ALIGN_CENTER)
 _DrawText(7.5, 20.5, $sText4, "_Calibri", 10, $PDF_ALIGN_CENTER)
 _DrawLine(13, 22.5, 13, 20, $PDF_STYLE_STROKED, 10, 0.1, 0xff0000, 0, 0)
_EndPage()

;write the buffer to disk
_ClosePDFFile()
Edited by taietel
Link to comment
Share on other sites

  • 3 weeks later...

With VISTA Professional French version Autoit 3.6.1 and Acrobat 9.4 i have trouble when the file was printing in Acrobat , i have the following message

"This page have an error. Acrobat may have a problem to display this page"

Have you the same problem ?

post-230-0-39366200-1311273559_thumb.jpg

Edited by LOULOU
Link to comment
Share on other sites

Well done taietel :)

Can be very useful when saving to pdf files!

5* from me!

Example_Image2PDF.au3 is causing an error for me when AR opens the created pdf: "There was an error opening this document. This file cannot be opened because it has no pages."

Example_Txt2PDF.au3 is also causing an error after selecting MPDF_UDF.au3: "An error exists on this page. Acrobat may not display the page correctly. Please contact the person who created the PDF document to correct the problem."

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Sorry for the delay (went on short(est) vacation).

Thanks you all for the feedback.

I found the bug (:) ) responsible for Adobe Reader errors.

Dennis Sandstrom (aka StuffByDennis) added two more functions: _Draw_Path and _Draw_Polygon (thanks for those, Dennis!)

I have attached the updated version, without images.

UEZ, welcome back!

Regards,

taietel

[EDIT] Attachment moved to first post (lack of space)

Edited by taietel
Link to comment
Share on other sites

  • 2 weeks later...

Well done taietel :mellow:

Can be very useful when saving to pdf files!

5* from me!

Example_Image2PDF.au3 is causing an error for me when AR opens the created pdf: "There was an error opening this document. This file cannot be opened because it has no pages."

Example_Txt2PDF.au3 is also causing an error after selecting MPDF_UDF.au3: "An error exists on this page. Acrobat may not display the page correctly. Please contact the person who created the PDF document to correct the problem."

Br,

UEZ

The same Errors occured when run the two examples

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...