Jump to content
taietel

Create PDF from your application

Recommended Posts

Hi ErikE83,

I don't know the solution (yet) but it has something to do with the byte offset not being correct inside the PDF

http://forums.adobe.com/thread/998718

Open the file and save it .. and the problem is solved ..

 

Edit : Foxit PDFReader does not want to save the file  when closing

Edited by Emiel Wieldraaijer

Best regards,Emiel Wieldraaijer

Share this post


Link to post
Share on other sites

Is there any documentation available for this?


0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Share this post


Link to post
Share on other sites

Hello again from Barcelona

I'm doing a little script to pass data from an Excel file to a PDF and also create and embed QR codes inside the PDF file.

I read the data from the Excel succefully and I do also create the QR codes as .bmp images (because we can't create pure pdf qr codes yet with this method)

As the Excel file is generated as report by another program, the amount of data will be different everytime.

I'm trying to add data to the PDF as I'm getting it from the excel file, but I have noticed that I just can not begin a pdf page, load the image that I have just created and insert it in the right place in the pdf:

_BeginPage();I do start the page
Sleep(25)
_LoadResImage("Cod", @ScriptDir & "\QR\1.bmp")
Sleep(25)
_InsertImage("Cod", 16, 26, 3.5, 3.5)

The code above doesn't work.

If you do this:

_LoadResImage("Cod", @ScriptDir & "\QR\1.bmp")
Sleep(25)
_BeginPage()
_InsertImage("Cod", 16, 26, 3.5, 3.5)

It works like a charm.

Any hint or clue about how can I create the page first and load the images as I'm creating the QR codes?

Thanks in advance.

Share this post


Link to post
Share on other sites

I am new to Autoit. - I have alltogether 2 weeks expossure and few codding expereience,

I will like to print /Save a web page in PDF format. only wondering if this could be achieed.

Any help will be appreciated.

Vin

Share this post


Link to post
Share on other sites

Well looks like I stumbled on a need for this a year to late since the original poster seems to not be around anymore but I just want to say Awesome Work!!!

Some improvements that are needed from what I have seen so far, and I may have to write them myself for what I need are...

  • Make _ClosePDFFile() clear the buffers so that resources from one pdf do not get loaded into subsequent pdfs and cause larger and larger files the more you create.
  • Since all the stuff gets written at the end, and since order maters as seen in >#224, why not keep a separate buffer for resources that you can put in order later when writing. That way you can loop through some data and dynamically load and insert images within a page, rather than loop to load, then start the page and loop again to insert.

Other notes that are just me being picky

  • take udf out of the name, no other udf has udf in the name.
  • Start the function names with a common identifier like _MPDFDrawLine, _MPDFPath,... So users can easily know what the function is referencing.

Share this post


Link to post
Share on other sites

 

Well looks like I stumbled on a need for this a year to late since the original poster seems to not be around anymore but I just want to say Awesome Work!!!

Some improvements that are needed from what I have seen so far, and I may have to write them myself for what I need are...

  • Make _ClosePDFFile() clear the buffers so that resources from one pdf do not get loaded into subsequent pdfs and cause larger and larger files the more you create.
  • Since all the stuff gets written at the end, and since order maters as seen in >#224, why not keep a separate buffer for resources that you can put in order later when writing. That way you can loop through some data and dynamically load and insert images within a page, rather than loop to load, then start the page and loop again to insert.

Other notes that are just me being picky

  • take udf out of the name, no other udf has udf in the name.
  • Start the function names with a common identifier like _MPDFDrawLine, _MPDFPath,... So users can easily know what the function is referencing.

 

esdios.gif

Any chance of getting no compression on images embedded?

Thanks a lot for keeping the work.

Share this post


Link to post
Share on other sites

I think I may have found a bug but I was wondering if perhaps I just need to modify the example code. I used the included example file (Example_Image2PDF.au3) to try and convert a multi-page TIF file and it only converted the first page. Can anyone with more knowledge of TIF, PDF and MPDF_UDF chime in on where they think the problem might be?

I have not done much digging into the MPDF code to see if I could figure out how to do it. I did find an example on changing a multipage tiff to pdf using 3 different DLL's ( I would rather keep using this UDF because I am also converting other image files as well. 

Share this post


Link to post
Share on other sites

@ryadical

I use IrfanView via its command line interface to temporarily extract the pages then process them individually in a loop.

Share this post


Link to post
Share on other sites

I am new to Autoit. - I have alltogether 2 weeks expossure and few codding expereience,

I will like to print /Save a web page in PDF format. only wondering if this could be achieed.

Any help will be appreciated.

Vin

 

search forum for PDFCreator


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest beginning - communication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  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 APIErrorLog.au3 UDF - A logging Library *

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 * 

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

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 *

"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"
:naughty:  :ranting:, 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: 2019-10-01

Share this post


Link to post
Share on other sites
I'm sorry but I do not write in English 
I need to google translator  :oops:
I read this document
 
I edited the original file release 1.0.3
I changed
 
all @crlf
whit
chr(10)
 
Global $PDF_VERSION = "%PDF-1.5" & @CRLF & "%" & ChrW(199) & ChrW(200) & ChrW(201) & ChrW(202)
whit
Global $PDF_VERSION = "%PDF-1.5" & chr(10) & "%" & ChrW(226) & ChrW(227) & ChrW(207) & ChrW(211)
 
into Func _BeginPage
__ToBuffer("<< /Length " & $intPage + 2 & " 0 R >>" & @CRLF & "stream")
whit
__ToBuffer("<<"&chr(10)&"/Length >>stream")
 
into Func _ClosePDFFile()
__ToBuffer("xref")
__ToBuffer("0 " & $_iMaxObject+1)
__ToBuffer("0000000000 65535 f")
For $i = 1 To $_iMaxObject
__ToBuffer($aXREF[$i])
Next
__ToBuffer("trailer" & @CRLF & _
"<< /Size " & $_iMaxObject + 1 & "/Info 1 0 R" & "/Root 2 0 R" & ">>")
__ToBuffer("startxref" & @CRLF & StringLen("startxref" & @CRLF & $_Buffer & "%%EOF" & @CRLF) + 6)
$_FileName = FileOpen($PDF_NAME,18)
FileWrite($_FileName, $_Buffer & "%%EOF" & @CRLF)
FileClose($_FileName)
If $_bOpen Then ShellExecute($PDF_NAME)
whit
dim $position_xref=stringlen($_Buffer)
__ToBuffer("xref")
__ToBuffer("0 " & $_iMaxObject+1)
__ToBuffer("0000000000 65535 f"&chr(13))
For $i = 1 To $_iMaxObject
__ToBuffer($aXREF[$i]&chr(13))
Next
__ToBuffer("trailer" & chr(10) & _
"<< /Size " & $_iMaxObject + 1 & "/Info 1 0 R" & "/Root 2 0 R" & ">>")
__ToBuffer("startxref" & chr(10) & $position_xref & chr(10) & "%%EOF")
$_FileName = FileOpen($PDF_NAME,18)
FileWrite($_FileName, $_Buffer)
FileClose($_FileName)
$_Pages = ""
$_sPage = ""
$_sFONT = ""
$_Image = ""
$_sObject = ""
$_iResource = ""
$_Buffer = ""
If $_bOpen Then ShellExecute($PDF_NAME)
 
into Func _LoadResImage
__ToBuffer("<</Type /XObject /Subtype /Image /Name /" & $sImgAlias & " /Width " & $_iImageW & " /Height " & $_iImageH & " /Filter /DCTDecode /ColorSpace /DeviceRGB /BitsPerComponent 8" & " /Length " & $iObj + 1 & " 0 R" & ">>")
__ToBuffer("stream" & @CRLF & $ImgBuf & @CRLF & "endstream")

whit

__ToBuffer("<</Type /XObject /Subtype /Image /Name /" & $sImgAlias & " /Width " & $_iImageW & " /Height " & $_iImageH & " /Filter /DCTDecode /ColorSpace /DeviceRGB /BitsPerComponent 8"&chr(10)&"/Length "&stringlen($ImgBuf)&">>stream")
__ToBuffer($ImgBuf)
__ToBuffer("endstream")
 
into Func _StartObject
__ToBuffer("<< /Type /XObject /Subtype /Form /FormType 1 /Name /" & $sAlias & " /BBox [" & __ToStr($__SetMargin) & " " & __ToStr($__SetMargin) & " " & __ToStr($_PageWidth - $__SetMargin) & " " & __ToStr($_PageHeight - $__SetMargin) & "] /Matrix [1 0 0 1 0 0] /Length " & $i + 1 & " 0 R >>" & @CRLF & _
"stream")
whit
__ToBuffer("<< /Type /XObject /Subtype /Form /FormType 1 /Name /" & $sAlias & " /BBox [" & __ToStr($__SetMargin) & " " & __ToStr($__SetMargin) & " " & __ToStr($_PageWidth - $__SetMargin) & " " & __ToStr($_PageHeight - $__SetMargin) & "] /Matrix [1 0 0 1 0 0]"&chr(10)&"/Length >>stream")
 
into Func __InitObj
$aXREF[$iObj] = StringRight("0000000000" & StringLen($_Buffer)+$_Offset+$iObj+1, 10) & " 00000 n"
whit
$aXREF[$iObj] = StringRight("0000000000" & StringLen($_Buffer), 10) & " 00000 n"
 
into Func _EndObject()
$_iTmpOffset = $_Offset - $_iTmpOffset
__ToBuffer("endstream")
__EndObj()
__InitObj()
__ToBuffer($_iTmpOffset)
__EndObj()
whit
$_iTmpOffset = $_Offset - $_iTmpOffset
__ToBuffer("endstream")
__EndObj()
dim $aArray1=_StringBetween($_Buffer,"/Length >>stream","endstream")
dim $stringlen
for $i=0 to ubound($aArray1)-1
$stringlen=$stringlen+stringlen($aArray1[$i])
next
$_Buffer=StringReplace($_Buffer,"/Length >>stream","/Length "&$stringlen-1&">>stream")
__InitObj()
__ToBuffer($_iTmpOffset)
__EndObj()
 
into Func _EndPage()
$_iTmpOffset = $_Offset - $_iTmpOffset
__ToBuffer("endstream")
__EndObj()
; Scrie dimensiunea
__InitObj()
__ToBuffer($_iTmpOffset)
__EndObj()
whit
$_iTmpOffset = $_Offset - $_iTmpOffset
__ToBuffer("endstream")
__EndObj()
dim $aArray1=_StringBetween($_Buffer,"/Length >>stream","endstream")
dim $stringlen
for $i=0 to ubound($aArray1)-1
$stringlen=$stringlen+stringlen($aArray1[$i])
next
$_Buffer=StringReplace($_Buffer,"/Length >>stream","/Length "&$stringlen-1&">>stream")
; Scrie dimensiunea
__InitObj()
__ToBuffer($_iTmpOffset)
__EndObj()
 
so my pdf files are compatible with "Acrobat Reader X" and "flipping pdf reader" and "sumatra pdf" and "pdf-xchange viewer"
I am attaching the modified file udf
 
 

MPDF_UDF.au3

Share this post


Link to post
Share on other sites
hi, I found some bugs using the function _Paragraph
 
  1. Carriage return does not appear 
  2. Accented characters space
 
here is the code to test it, and the screenshot of pdf generated with bugs
 
#include "MPDF_UDF.au3"

$sTxt = "these accented characters: à ì ò ù it is creating problems"
$sTxt2 = "Another problem with the carriage return,"&@CRLF&"which is not displayed"
$fileName = @ScriptDir&"\___prova.pdf"

; set the properties for the pdf -----------------------------------------------------
_SetTitle("titolo")
_OpenAfter(True);open after generation
_SetUnit($PDF_UNIT_CM)
_SetPaperSize("A4")
_SetZoomMode($PDF_ZOOM_CUSTOM,65)
_SetOrientation($PDF_ORIENTATION_PORTRAIT)
_SetLayoutMode($PDF_LAYOUT_TWO)

;initialize the pdf
_InitPDF($fileName)

;fonts:
_LoadFontTT("_Arial", $PDF_FONT_ARIAL)
_LoadFontTT("_TimesT", $PDF_FONT_TIMES)
_LoadFontTT("_Calibri", $PDF_FONT_CALIBRI)
_LoadFontTT("_Garamond", $PDF_FONT_GARAMOND)

;start a page
_BeginPage()

_Paragraph($sTxt2, 1, 24, 10, "_Arial", 14, 0)
_Paragraph("_Arial: "&$sTxt, 1, 22, 10, "_Arial", 14, 0)
_Paragraph("_TimesT: "&$sTxt, 1, 20, 10, "_TimesT", 14, 0)
_Paragraph("_Calibri: "&$sTxt, 1, 18, 10, "_Calibri", 14, 0)
_Paragraph("_Garamond: "&$sTxt, 1, 16, 10, "_Garamond", 14, 0)

_EndPage()

_ClosePDFFile()

post-83845-0-45452900-1399034224_thumb.p

 
 
Does anyone have suggestions?

Share this post


Link to post
Share on other sites

I have been using the version modified by bdr529 successfully, but I have a slight issue with the image quality that I can't seem to figure out.

I'm not sure if large JPG images gets degraded when added to a PDF, one big image per page, or if there is some other issue. But when I look at the PDF (in FoxIt) the images there have a lower quality than the original JPGs.

The actual code is pretty small and simple: (Xmax and Ymax is the size in pixels of the JPG)

_SetTitle("PDF")
                _SetSubject("PDF")
                _SetKeywords("PDF")
                _OpenAfter(True);open after generation
                _SetUnit($PDF_UNIT_CM)
                _SetPaperSize("CUSTOM",$Xmax, $Ymax)
                _SetZoomMode($PDF_ZOOM_FULLPAGE)
                _SetOrientation($PDF_ORIENTATION_PORTRAIT)
                _SetLayoutMode($PDF_LAYOUT_CONTINOUS)

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

                $time = @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC

                For $i = 1 to $pageCount
                    _LoadResImage("img"&$time&$i, @ScriptDir & "\tmp\" & $i & ".jpg")
                Next
                For $i = 1 to $pageCount
                    _BeginPage()
                        ;scale image to paper size!
                        _InsertImage("img"&$time&$i, 0, 0, _GetPageWidth()/_GetUnit(), _GetPageHeight()/_GetUnit())
                    _EndPage()
                Next
                _ClosePDFFile()

On a sidenote, there is a small issue with MPDF when it comes to making several PDF without restarting, this is easily solved by resetting the page count with:

Global $_Pages = 0 ; 

Which prob should have been done in _InitPDF.

Share this post


Link to post
Share on other sites

I'm using the latest; 

 Title .........: MIPDF
; AutoIt Version : 3.3.6.1
; Description ...: Generate pdf using just AutoIt functions.
; Author(s) .....: Mihai Iancu (taietel at yahoo dot com)
; Version .......: 1.0.3
; Last Rev. .....: August 10, 2011
 
It seems like in the latest Autoit3 v3.3.12   _Iif is undefined? How do we fix this?  
 

_Iif($_sFONT <> "", "/Font<<" & $_sFONT & ">>", "") & _

MPDF_UDF.au3"(252,54) : error: _Iif(): undefined function.

Share this post


Link to post
Share on other sites

I'm using the latest; 

 Title .........: MIPDF
; AutoIt Version : 3.3.6.1
; Description ...: Generate pdf using just AutoIt functions.
; Author(s) .....: Mihai Iancu (taietel at yahoo dot com)
; Version .......: 1.0.3
; Last Rev. .....: August 10, 2011
 
It seems like in the latest Autoit3 v3.3.12   _Iif is undefined? How do we fix this?  
 

_Iif($_sFONT <> "", "/Font<<" & $_sFONT & ">>", "") & _

MPDF_UDF.au3"(252,54) : error: _Iif(): undefined function.

 

Instead of _lif() you can use new build in syntax:

 

($_sFONT <> "") ? ("/Font<<" & $_sFONT & ">>") : ("")

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post


Link to post
Share on other sites

HI I'm pretty new to Autoit, and I have a question about creating pdf's from my application. I got the udf working, but I need to know if this is possible.

  1. take an existing pdf that accepts user input (name, dob, date, etc)
  2. somehow import that pdf template into autoit
  3. call data from autoit to populate the data fields
  4. then print the pdf template with the autoit data in the data fields

Is this possible with this udf?

I appreciate any help. 

Share this post


Link to post
Share on other sites

I think I may have answered my own question. 

Should I first convert my pdf into an image and then use the udf to import an image and overlay data where the data fields are?

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...