Sign in to follow this  
Followers 0
drbyte

PDF Automation

4 posts in this topic

#1 ·  Posted (edited)

Hello all,
 
I have to print a lot pdf labels during a day at work.
One of our customers delivers them as a pdf file on a single A4 page.
 
Every time when i need to print a specific label, i need to do the handling below to print
the selected label to our Dymo printer.
Can this be automated in a simple way?
 
1. Zoom opened pdf to 350%
2. Resize the window to fit the label
3. Select print
4. Choose printer
5. Select properties
6. Select left roll
7. Select the correct label size
8. Select current view
9. Press print......
 
If found the code below in the forum, is this, with some adjustments of course usable?
(Thanks to M23)
 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

; Install a custom error handler
Global $oMyError = ObjEvent("AutoIt.Error","_ComErrFunc")
Global $iGUIWidth = 800, $iGUIHeight = 570, $fResized = False

_Show_PDF()

Func _Show_PDF()

    ; Get file to display
    Local $sFile = FileOpenDialog("Choose PDF", "C:\Temp", "PDF Files(*.pdf)", 3) ; put your own start folder here
    If @error Then
        MsgBox(0, "Error", "No file selected")
        Return
    EndIf

    ; Declare objects
    Local $oPDF = ObjCreate("AcroPDF.PDF.1");
    $oPDF.src = $sFile

    ; Create GUI
    GUICreate("Label Printer", 1580, 590, -1, -1, BitOr($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_MAXIMIZEBOX))
    Local $GUI_ActiveX = GUICtrlCreateObj($oPDF, 10, 10, 1560, 570)
    GUICtrlSetStyle($GUI_ActiveX, $WS_VISIBLE)
    GUICtrlSetResizing($GUI_ActiveX, $GUI_DOCKAUTO) ; Auto Resize Object
    GUISetState()

    ; When window is resized, run this function
    GUIRegisterMsg($WM_SIZE, "MY_WM_SIZE")

    While 1

        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch

        If $fResized = True Then
            ConsoleWrite($iGUIWidth & " - " & $iGUIHeight & @CRLF)
            $fResized = False
            WinMove($GUI_ActiveX, "", Default, Default, $iGUIWidth - 20, $iGUIHeight - 20)
        EndIf

    WEnd

    ; Clear up
    $oPDF = ""
    $GUIActiveX = ""

    Exit

EndFunc

Func MY_WM_SIZE($hWnd, $Msg, $wParam, $lParam)

    $iGUIWidth = BitAND($lParam, 0xFFFF)
    $iGUIHeight = BitShift($lParam, 16)
    $fResized = True

    Return $GUI_RUNDEFMSG

EndFunc   ;==>MY_WM_SIZE

Func _ComErrFunc()

  Local $HexNumber = Hex($oMyError.number,8)
  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"       & @CRLF  & @CRLF & _
             "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
             "err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "         & @TAB & $HexNumber              & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "     & @TAB & $oMyError.scriptline     & @CRLF & _
             "err.source is: "         & @TAB & $oMyError.source         & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile       & @CRLF & _
             "err.helpcontext is: "    & @TAB & $oMyError.helpcontext _
            )
  SetError(1)

EndFunc
Edited by drbyte

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

look here: Debenu Quick PDF Library - UDF

Edited by mLipok

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

Last update: 2016-12-23
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 Components * TeamViewer API -UDF * JavaManagement UDF * VIES over SOAPPOP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF * WinSCP UDF *

My contribution to others projects: * _sql.au3 UDF  *

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 * Best coding practices * 

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 *

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

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

@mLipok,

Excuses for the late reply.....
I added the QuickPDF.au3 to the include directory and i ran the QuickPDF_Examples.au3.

At that moment i get a lot of errors of missing several .au3 files.

Edited by drbyte

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Please post in Debenu Quick PDF Library - UDF

And give the entire console output.

 

Edited by mLipok
link fix

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

Last update: 2016-12-23
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 Components * TeamViewer API -UDF * JavaManagement UDF * VIES over SOAPPOP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF * WinSCP UDF *

My contribution to others projects: * _sql.au3 UDF  *

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 * Best coding practices * 

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 *

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

 

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
Sign in to follow this  
Followers 0

  • Similar Content

    • MagicFlute
      By MagicFlute
      Hi guys
      Looking to automate...I have PDF files...Need to convert them all to 2 pages each but more specifically, retain only the first and last.
      Searched a lot and hitting the wall....Any ideas? Just directions would do...
      Not sure how to "print to file" and I believe |ShellExecuteWait($sFilePath, " /h /p", "", "print", @SW_HIDE)| doesn't give options of what pages...
    • dynamitemedia
      By dynamitemedia
      I am using this code to do a basic thumbnail loading counter...  

      what i want to do is change the count each time without changing everything else, i think  just the number count flashing would be better than the whole thing flashing. i tried it with the whole label inside the loop but it flashed too much
      so i was thinking of just put a label over the top of the blank area...   if its in triple digits it flashes horribly weird when gets to double digits, and then on single digits

      and i want to have it do its more like finding the position of where to place label on top of the other label , i know this needs cleaning up a ton but here is what i have which is semi working
       
      #include "GUIScrollbars_Ex.au3" #include <Skin.au3> #include <GDIPlus.au3> #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <GuiListView.au3> #include <GuiTab.au3> #include <StaticConstants.au3> #include <TabConstants.au3> #include <WindowsConstants.au3> #include <File.au3> #include <Array.au3> #include <Process.au3> #include <Constants.au3> #include <String.au3> #include <Date.au3> #include <GDIplus.au3> #include <GuiButton.au3> #Include "Curl.au3" #include "GUIScrollbars_Ex.au3" #include <Skin.au3> #include <GuiButton.au3> #include <GuiListView.au3> #include <GuiTab.au3> #include <StaticConstants.au3> #include <WinAPI.au3> #include <WinAPIGdi.au3> #include "StringSize.au3" Global $iDialog_Width = 1280 Global $iDialog_Depth = 720 Global $blueness = 0xff0066ff $thumbCount = 110 $folder = "testing" $hDialog = GUICreate("", $iDialog_Width, $iDialog_Depth, -1, -1) GUISetState() _GDIPlus_Startup() ;initialize GDI+ Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hDialog) _GDIPlus_GraphicsSetSmoothingMode($hGraphics, $GDIP_SMOOTHINGMODE_HIGHQUALITY) Local $hPen = _GDIPlus_PenCreate($blueness, 6) ; Get the size of label needed to hold the text $aRet = _StringSize("Both vertically" & @CRLF & "and horizontally centered", 30) $iX = ($iDialog_Width - $aRet[2]) / 2 $iY = ($iDialog_Depth - $aRet[3]) / 2 _GDIPlus_GraphicsDrawRect($hGraphics, $iX - 30, $iY - 30, $aRet[2] + 60, $aRet[3] + 60, $hPen) $thumbLength = StringLen($thumbCount) $string2add = "Loading " & " " & " thumbnail(s) from " & $folder $paddLblDate = GUICtrlCreateLabel($string2add, $iX, $iY, $aRet[2], $aRet[3], $SS_CENTER) ConsoleWrite("label Left position : " & $iX & @CRLF) Local $countPosition = StringInStr($string2add, $thumbCount) ConsoleWrite("count position : " & $countPosition & @CRLF) Local $thumbPosition = StringInStr($string2add, "thumbnail(s)") ConsoleWrite("thumb position : " & $thumbPosition & @CRLF) GUICtrlSetFont(-1, 22, 600, 0, "Arial") GUICtrlSetColor($paddLblDate, $COLOR_WHITE) $labelStart = $iX + 130 ConsoleWrite("labelStart : " & $labelStart & @CRLF) For $i = 1 To $thumbCount - 1 $thumbCount = $thumbCount - 1 $thumbLabel = GUICtrlCreateLabel($thumbCount, $labelStart , $iY + 4, 50, 28, $SS_CENTER) GUICtrlSetFont(-1, 20, 700, 0, "Arial") GUICtrlSetColor($thumbLabel, $COLOR_RED) ConsoleWrite("New count : " & $thumbCount & @CRLF) sleep (600) next GUICtrlDelete($paddLblDate) GUICtrlDelete($paddLblDate) GUICtrlDelete($paddLblDate) _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphics)  
    • mLipok
      By mLipok
      ; #FUNCTION# ==================================================================================================================== ; Name ..........: _html2pdf ; Description ...: Convert HTML file to PDF file with htm2pdf.exe by Synopse ; Syntax ........: _html2pdf($sHTML_FileFullPath[, $sPDF_FileFullPath = Default[, $bDeleteHTML = False]]) ; Parameters ....: $sHTML_FileFullPath - a string value. HTML file full path. ; $sPDF_FileFullPath - [optional] a string value. Default value is Default -> $sHTML_FileFullPath & '.pdf' ; $bDeleteHTML - [optional] a boolean value. Default is False. ; Return values .: $sPDF_FileFullPath or set @error to 1 ; Author ........: mLipok ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: http://blog.synopse.info/post/2010/07/14/htm2pdf-free-tool ; Example .......: No ; =============================================================================================================================== Func _html2pdf($sHTML_FileFullPath, $sPDF_FileFullPath = Default, $bDeleteHTML = False) If $sPDF_FileFullPath = Default Then $sPDF_FileFullPath = $sHTML_FileFullPath & '.pdf' Local $sINI_FileFullPath = @ScriptDir & '\htm2pdf.ini' IniWrite($sINI_FileFullPath, 'Settings', 'HTML', $sHTML_FileFullPath) IniWrite($sINI_FileFullPath, 'Settings', 'PDF', $sPDF_FileFullPath) IniWrite($sINI_FileFullPath, 'Settings', 'OpenAfterSave', '0') IniWrite($sINI_FileFullPath, 'Settings', 'ScaleToFit', '1') IniWrite($sINI_FileFullPath, 'Settings', 'Orientation', 0) IniWrite($sINI_FileFullPath, 'Settings', 'PaperSize', 0) IniWrite($sINI_FileFullPath, 'Margins', 'Left', 2) IniWrite($sINI_FileFullPath, 'Margins', 'Top', 1) IniWrite($sINI_FileFullPath, 'Margins', 'Right', 1) IniWrite($sINI_FileFullPath, 'Margins', 'Bottom', 1) ShellExecuteWait(@ScriptDir & '\htm2pdf.exe', '/silent', @ScriptDir) If Not FileExists($sPDF_FileFullPath) Then Return SetError(1, 0, '') Else If $bDeleteHTML Then FileDelete($sHTML_FileFullPath) Return $sPDF_FileFullPath EndIf EndFunc ;==>_html2pdf  
      http://blog.synopse.info/post/2010/07/14/htm2pdf-free-tool#main
      http://blog.synopse.info/post/2010/07/14/htm2pdf-free-tool
      http://synopse.info/forum/viewtopic.php?pid=187
      http://synopse.info/files/pdf/htm2pdf.zip
      mLipok
       
    • ur
      By ur
      Is there any API or functions to convert all office documents(excel,word,ppt,etc) and pdf to images (jps,bmp or convert any animation in ppt to swf or gif).
      It should convert all the pages in the document to individual image files.
       
      Please help me on this.
    • mLipok
      By mLipok
      I was allways wondering How to get reference to AcrobatReader  object and after all to the PDF file embeded in IE.
      Today I was here:
      http://www.vitoplantamura.com/index.aspx?page=axvncviewer
       
      there is such a interesting html:
       
      When I analyze this then I start to wonder about this line:
       
      EDIT: above fraction was only an introduction, describing where it came my question.
       
      And now then the question arise :
      How I can use document.all to get the refrence to specified AxObject in this Case I mean to AcrobatReader opened in IE ?
      EDIT: of course I mean a case when I have opened document in IE.