Scan PDF and then OpenFile Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
NDuda

Scan PDF and then OpenFile  Topic is solved

11 Apr 2017, 02:04

Hi,
I have a simple USB Barcode Scanner who works similar to a keyboard.
If you scan a code (Code 39, Barcode=filename) then AHK should open the PDF of the same name, if you scan another code, the pdf window closes and a new one opens and so on..

I found this in the archive:

SetTitleMatchMode 2
Gui, +alwaysontop ;keeps the gui on top level
Gui, Add, Edit , w200 vpdfname,
Gui, Add, Button, gopenpdf default , OPEN
Gui, show ,, scantopdf ;give name to gui for later reference

return

openpdf:
Gui,Submit,Nohide
source := "F:\" . pdfname . ".pdf"
run, %source%,hide
Guicontrol,,pdfname, ;makes the edit box blank
sleep 4000 ;wait 4 seconds for pdf to load
WinActivate,scantopdf ;then reactivate the gui window
return

Exit:
GuiClose:
ExitApp

It works but is this doable without any GUI? How would the script look like for two or more pdfs / codes?
Sorry, for the question but i'm completely new.
THANK YOU!!!

Best,
Nico
Darayavahus
Posts: 36
Joined: 21 May 2016, 03:32

Re: Scan PDF and then OpenFile

15 Apr 2017, 02:02

Try "Hotstrings and Auto-Replace" in AHK manual.

::btw::
MsgBox You typed "btw".
return

If you would like to open predefined name of pdf files you can define few functions and have barcodes with those function names on a paper sheet. For above example if you would print "btw" as a barcode, scan it with your scanner it in theory should pop up a message.
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Scan PDF and then OpenFile

18 Aug 2017, 17:06

nibor00 wrote:Hello there,
How can I convert multiple Microsoft Word documents into one document or PDF?
Thanks in advance
This script will combine multiply Word documents into one Word document.

Code: Select all

; Select Documents
FileSelectFile, Select_Files, M1,, Select Documents to Merge, Documents (*.doc; *.docx)
Select_Files := StrSplit(Select_Files, "`n")
Select_Path := Select_Files.RemoveAt(1)

; Init Word
wdApp := ComObjCreate("Word.Application")
wdApp.Visible := true
wdApp.ScreenUpdating := false

; Create New Blank Document
wdDoc_Main := wdApp.Documents.Add
blank_end := wdDoc_Main.Range.End ; save starting blank document end

; Insert Selected Documents
for index, Select_File in Select_Files
{
	rng := wdDoc_Main.Range
	rng.Collapse(0) ; wdCollapseEnd := 0
	rng.InsertFile(Select_Path "\" Select_File)
	rng.InsertBreak(7) ; wdPageBreak := 7
}

; Cleanup
wdDoc_Main.Range(0, blank_end+1).Delete ; delete starting blank document
wdDoc_Main.Range(wdDoc_Main.Range.End-1).Delete ; delete unneeded break at end
wdApp.ScreenUpdating := true
It is pretty basic and straightforward. It is not going to allow you to merge any two Word documents together and have them look exactly the same.

This does not take in to consideration things that don't match between the two documents like margins, page size, orientation, etc. Nor does it deal with headers and footers.

It should handle fonts, paragraph formatting, pictures, tables, etc but not things that have to do with page layout.

Word is kind of like a webpage in that Word does not really know exactly how a page is going to layout until it actually lays it out. It views the data as more of a stream of information to be displayed and formatted as it goes along. Change a margin and the whole document moves and flows to fit the new parameters.

As for combining a bunch of Word documents into a single PDF, that is very doable also. You would just need to convert all the Word documents to PDFs then combine the PDFs. Word can convert them to PDFs but not sure if Word can or something built in to Office can then combine the PDFs. I could do it through COM with Adobe Acrobat which is installed on my computer but I am not sure everyone would have access to Adobe Acrobat. It is what I use when working with PDFs so not totally sure what all PDF capabilities are natively installed with Windows or Office.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
User avatar
JoeWinograd
Posts: 2198
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Scan PDF and then OpenFile

18 Aug 2017, 17:29

Hi FG,
Since your COM code has already combined the multiple Word documents into a single Word document, you can use Word COM to do a Save As to PDF (so there's no need for Acrobat COM). For example:

Code: Select all

wdApp.ActiveDocument.SaveAs2(OutputFile,17)
Regards, Joe
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Scan PDF and then OpenFile

18 Aug 2017, 17:51

JoeWinograd wrote:Hi FG,
Since your COM code has already combined the multiple Word documents into a single Word document, you can use Word COM to do a Save As to PDF (so there's no need for Acrobat COM). For example:

Code: Select all

wdApp.ActiveDocument.SaveAs2(OutputFile,17)
Regards, Joe
Yea, I knew that of course. But I was saying if you want each Word document to look exactly like they do individually (with different margins, headers, footers, etc.), you would need to use something like you posted to output each individually to a PDF and then combine the PDFs. I don't know if Office has any native ability to combine PDFs.

You could possible merge the Word documents and try to properly merge each documents individual margins, foots, headers etc. but it would probably be hard to iron out all the kinks. The individual documents could already have different sectional page layouts. I imagine there are also some formatting choices that just cannot be different in parts of one document. Things like hidden text might be shown in one document but not in another. That is an all or nothing setting. If one document has it on and another has it off. No one merged document is going to display them both properly. Custom paragraph styles with the same names but different settings. There are probably a lot of things that would keep two documents from displaying or printing exactly the same merged as individually.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
User avatar
JoeWinograd
Posts: 2198
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Scan PDF and then OpenFile

18 Aug 2017, 22:44

OK, I should have known you knew that, FG, and now I see your point. There are easier ways, imo, to combine PDFs than Acrobat COM, and certainly less expensive ones. I've used PDFtk Server (free for both personal and commercial use under its GPL license) to combine PDFs. Here's a thread where I discuss it and provide links to it:
https://autohotkey.com/boards/viewtopic ... 48#p133848

Although that's about a different usage of PDFtk (filling a form), the cat operation and shuffle operation allow easy combination of PDFs. I've used them in many AHK scripts — they work great. Regards, Joe
Guest

Re: Scan PDF and then OpenFile

19 Aug 2017, 02:44

If you're not too worried about exact formatting of the PDF (e.g. 100 replica of layout and high quality images) you can also use NW Docx Converter (formerly Docx2Rtf) https://www.portablefreeware.com/index.php?id=1405 - it allows you to convert Microsoft Office (doc, docx) and OpenOffice/LibreOffice documents to RTF and also PDF or plain text even. You can do this per file or entire folder via the Gui and/or via the command line without the need to have Office installed.

Once you have the PDF(s) I would also recommend PDFtk to manipulate the PDF(s) further. The XPDF toolset (command line programs) is also very useful, it can now be found at http://www.xpdfreader.com/download.html
User avatar
AlphaBravo
Posts: 586
Joined: 29 Sep 2013, 22:59

Re: Scan PDF and then OpenFile

19 Aug 2017, 09:52

to reply to the original question about scanner, you could used the following - modified from this post, file name must be more than one character.

Code: Select all

loop, 96
	Hotkey, % "$~" chr(A_Index + 31), BarCodeHandler, on

BarCodeHandler:
Accu .= SubStr(A_ThisHotkey, 0)

If A_TimeSincePriorHotkey < 60
	SetTimer, TheBigShebang, -60

If (A_TimeSincePriorHotkey > 100)
	Accu := SubStr(A_ThisHotkey, 0)
return

TheBigShebang:
If Accu
	ToolTip ,  You scanned barcode %Accu%
return
rhullopeter
Posts: 1
Joined: 13 Jan 2022, 16:08

Re: Scan PDF and then OpenFile

13 Jan 2022, 16:12

I am using this but I can't get it to close the previous file when I scan another barcode. Is anyone familiar with this and might have a solution?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 215 guests