KickStarter15

[Solved]Converting PDF file to word document. Possible for AutoIt?

22 posts in this topic

#1 ·  Posted (edited)

Hi Experts,

I've tried searching for existing thread on how to convert pdf file into a word file, but it led me to a reverse situation which is word to PDF cases and could not find any samples for me to start with.:>

I just want to ask if that would be possible using AutoIt and if it is, please share any link or thread that can put me to right track. However, any help from Experts in this forum is much more appreciated.:sweating:

EDIT: I forgot to add this link which can convert PDF to word file but all contents from PDF was converted as one line in word file output.

 

Thanks in advance Experts.

KS15

Edited by KickStarter15

Share this post


Link to post
Share on other sites



#2 ·  Posted

Only with using wirtual Printer, or using separate ActiveX component .

 


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
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 API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer 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 * _IEquerySelectorAll() (by uncommon) * 

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: 2017-06-04

Share this post


Link to post
Share on other sites

#3 ·  Posted

I actually had this exact problem about a week ago, and after an entire day of searching I still had no luck. Adobe Acrobat DC can export a PDF to Word but there is no way to call it externally so it isn't really possible with AutoIt. To be honest, I couldn't find a single free reliable tool that would be able to do this conversion from the command line. Total bummer.


UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Thanks, Experts for the response appreciated for the ideas, links and details. So, basically, my only chance of having it is using online converter as what does this link do.

However, found some codings for VBA scripting and tried having it this way:

Sub convertToWord()
   Dim MyObj As Object, MySource As Object, file As Variant
   file = Dir("D:\Programs\PDF\" & "*.pdf") 'pdf path
   Do While (file <> "")
   ChangeFileOpenDirectory "D:\Programs\PDF\"
          Documents.Open FileName:=file, ConfirmConversions:=False, ReadOnly:= _
        False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:= _
        "", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="", _
        Format:=wdOpenFormatAuto, XMLTransform:=""
    ChangeFileOpenDirectory "D:\Programs\PDF\WORD" 'saving word
    ActiveDocument.SaveAs2 FileName:=Replace(file, ".pdf", ".docx"), FileFormat:=wdFormatXMLDocument _
        , LockComments:=False, Password:="", AddToRecentFiles:=True, _
        WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
         SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
        False, CompatibilityMode:=15
    ActiveDocument.Close
     file = Dir
   Loop
End Sub

But it will set as a Windows Default formatting when converting. Tried having it using Office 2010 won't work, but when trying using Office 2013 definitely worked but still in one line paragraph.:sweating:

Here is a sample screen-grab converted from PDF to DOC.

Sample.png

Is there a way of converting these VBA code to AutoIt? by that, at least we can start and wishing with luck.:lol:

 

Edited by KickStarter15

Share this post


Link to post
Share on other sites

#7 ·  Posted

This is just using Word (2013 or above) to open a PDF and then saving the file as .doc or .docx, so you should be able to use Word UDF to do this.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

@Subz, WORD UDF is kind of complex for my knowledge as for now I need more learning on how to handle Word UDF by water. :> kind of new with it and still catching up. I have this confusion on how to do this in word udf?

Edited by KickStarter15

Share this post


Link to post
Share on other sites

#9 ·  Posted

Something like this:
 

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <Word.au3>

; Create application object
Local $oWord = _Word_Create()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocSaveAs Example", _
        "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
; Open the test document
Local $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\Example.pdf")
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocSaveAs Example", _
        "Error opening 'Example.pdf'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

_Word_DocSaveAs($oDoc, @ScriptDir & "\_Word_Test2.doc")
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocSaveAs Example", _
        "Error saving the Word document." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocSaveAs Example", "Document successfully saved as '" & _
        @ScriptDir & "\_Word_Test2.doc'.")

Remark: not tested.

 

1 person likes this

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
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 API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer 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 * _IEquerySelectorAll() (by uncommon) * 

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: 2017-06-04

Share this post


Link to post
Share on other sites

#10 ·  Posted

Slightly modified version of mLipoks version.

Disables/Enables the conversion message, not to be confused with _Word_DocOpen conversion parameter
Need to specify $wdFormatDocumentDefault otherwise it just saves it as something like word.doc rather than the name you specify.

#include <Word.au3>

; Create application object
Local $oWord = _Word_Create()
If @error Then Exit

;~ Disable Message: Word will now convert your PDF to an editable Word document.  This may take a while.  The resulting Word document will be optimized to allow you to edit the text, so it might not look exactly like the original PDF, especially if the original file contained lots of graphics.
RegWrite("HKCU\SOFTWARE\Microsoft\Office\15.0\Word\Options", "DisableConvertPdfWarning", "REG_DWORD", 1)
; Open the test document
Local $bDoc = True, $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\Filename.pdf")
If @error Then $bDoc = False
;~ Enable Message: Word will now convert your PDF to an editable Word document.  This may take a while.  The resulting Word document will be optimized to allow you to edit the text, so it might not look exactly like the original PDF, especially if the original file contained lots of graphics.
RegWrite("HKCU\SOFTWARE\Microsoft\Office\15.0\Word\Options", "DisableConvertPdfWarning", "REG_DWORD", 0)
If $bDoc = False Then Exit

; *****************************************************************************
; Save the document as Filename.docx
; *****************************************************************************
_Word_DocSaveAs($oDoc, @ScriptDir & "\Filename.docx", $WdFormatDocumentDefault)
If @error Then Exit
_Word_DocClose($oDoc)

 

1 person likes this

Share this post


Link to post
Share on other sites

#11 ·  Posted

@Subz and @mLipok your both given codes are working great in converting PDF to Word but using Office 2013. Thanks guys! appreciated.:)

However, is there a way to have this worked if user used Office 2010? very much thankful if that can be done.:sweating:

Share this post


Link to post
Share on other sites

#12 ·  Posted

No, this feature is only available with Office 2013 and later.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#13 ·  Posted

@water, I understand your point but as of the current environment we have in our company, it has both Office 2010 and 2013. However, most of our computers has word 2010 which they can't use the program. I was so happy and overwhelm when Subz and mLipok direct me to your Word UDF and gladly you have that feature.:lol:

Tried searching for forums and most of issues were involving word 2010 which are still hanging until these days.

Maybe can you make something like that for 2010?:>

Share this post


Link to post
Share on other sites

#14 ·  Posted

@KickStarter15 The issue is Word 2010 doesn't support the feature, Waters great Word udf just utilizes the Office version installed on the local system.  What you would probably need is a third-party app for instance: http://www.flipbuilder.com/free-pdf-to-word/ (haven't tested), with batch support.  In the past we use to have a similar product to the one mentioned, except from Word to PDF where a user would dump Word documents into a directory and these were automatically converted to Word files, that way we had no requirements for handling Office versions etc...

Share this post


Link to post
Share on other sites

#15 ·  Posted

@Subz, Thanks. How does this work?

Share this post


Link to post
Share on other sites

#16 ·  Posted

As Subz noted: He didn't test the product. Seems you need to try it yourself ;) 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

Got it @water and @Subz, with thanks and everything for the support.:lol: But some of the characters from PDF file was changed to unknown characters and some were presented in one line paragraph. So, I preferred to used the below codes from Subz and mLipok and check what's the best. I already requested for installation of Office 2013 of some computers here in our work station but limited only to those in need only.

#include <Word.au3>

; Create application object
Local $oWord = _Word_Create()
If @error Then Exit

;~ Disable Message: Word will now convert your PDF to an editable Word document.  This may take a while.  The resulting Word document will be optimized to allow you to edit the text, so it might not look exactly like the original PDF, especially if the original file contained lots of graphics.
RegWrite("HKCU\SOFTWARE\Microsoft\Office\15.0\Word\Options", "DisableConvertPdfWarning", "REG_DWORD", 1)
; Open the test document
Local $bDoc = True, $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\Filename.pdf")
If @error Then $bDoc = False
;~ Enable Message: Word will now convert your PDF to an editable Word document.  This may take a while.  The resulting Word document will be optimized to allow you to edit the text, so it might not look exactly like the original PDF, especially if the original file contained lots of graphics.
RegWrite("HKCU\SOFTWARE\Microsoft\Office\15.0\Word\Options", "DisableConvertPdfWarning", "REG_DWORD", 0)
If $bDoc = False Then Exit

; *****************************************************************************
; Save the document as Filename.docx
; *****************************************************************************
_Word_DocSaveAs($oDoc, @ScriptDir & "\Filename.docx", $WdFormatDocumentDefault)
If @error Then Exit
_Word_DocClose($oDoc)
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <Word.au3>

; Create application object
Local $oWord = _Word_Create()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocSaveAs Example", _
        "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
; Open the test document
Local $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\Example.pdf")
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocSaveAs Example", _
        "Error opening 'Example.pdf'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

_Word_DocSaveAs($oDoc, @ScriptDir & "\_Word_Test2.doc")
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocSaveAs Example", _
        "Error saving the Word document." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocSaveAs Example", "Document successfully saved as '" & _
        @ScriptDir & "\_Word_Test2.doc'.")

For other computers that has no Office 2013, I already provided them the online converter (off course permitted with IT department). This link and This link as well.

Hopefully in the future seeker for help on converting PDF file to Word file, this thread might help them.^_^

 

Thanks,

KS15

 

Edited by KickStarter15
Added link...

Share this post


Link to post
Share on other sites

#18 ·  Posted

Hi @Subz and @water

I need you inputs on the below code on how to change this from _IE... to Firefox. I need to use GUI to run the link in converting PDF to Word file. I need to made something like this so that those who don't have Office2013 yet can use this link.

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

Local $oIE = _IECreateEmbedded()
GUICreate("Embedded Web control Test", 640, 580, _
        (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _
        $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
GUICtrlCreateObj($oIE, 10, 40, 600, 360)
Local $idButton_Back = GUICtrlCreateButton("Back", 10, 420, 100, 30)
Local $idButton_Forward = GUICtrlCreateButton("Forward", 120, 420, 100, 30)
Local $idButton_Home = GUICtrlCreateButton("Home", 230, 420, 100, 30)
Local $idButton_Stop = GUICtrlCreateButton("Stop", 340, 420, 100, 30)

Global $g_idError_Message = GUICtrlCreateLabel("", 100, 500, 500, 30)
GUICtrlSetColor(-1, 0xff0000)

GUISetState(@SW_SHOW) ;Show GUI

_IENavigate($oIE, "http://www.google.com")
_IEAction($oIE, "stop")

; Waiting for user to close the window
While 1
    Local $iMsg = GUIGetMsg()
    Select
        Case $iMsg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $iMsg = $idButton_Home
            _IENavigate($oIE, "http://www.google.com")
            _IEAction($oIE, "stop")
            _IEAction($oIE, "back")
            CheckError("Home", @error, @extended)
        Case $iMsg = $idButton_Back
            _IEAction($oIE, "back")
            CheckError("Back", @error, @extended)
        Case $iMsg = $idButton_Forward
            _IEAction($oIE, "forward")
            CheckError("Forward", @error, @extended)
        Case $iMsg = $idButton_Stop
            _IEAction($oIE, "stop")
            CheckError("Stop", @error, @extended)
    EndSelect
WEnd

GUIDelete()

Exit

Func CheckError($sMsg, $iError, $iExtended)
    If $iError Then
        $sMsg = "Error using " & $sMsg & " button (" & $iExtended & ")"
    Else
        $sMsg = ""
    EndIf
    GUICtrlSetData($g_idError_Message, $sMsg)
EndFunc   ;==>CheckError

Something like ObjCreate("Mozilla.Browser.1").:sweating:

Share this post


Link to post
Share on other sites

#19 ·  Posted

You need to use the Firefox UDF. Please check the example scripts forum for this UDF. 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#20 ·  Posted

Thanks, @water. I'll check on Firefox UDF.^_^

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