Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Read a text files contents as a variable
#1
Hello all, is there any way to read a text file as a variable? I mean the contents of the text file. The text file I am referencing only has one line. However if there is also a way to access different line numbers could I see that as well? Thanks for any help.


This program makes computing a dream Smile


I see after reading more in the help getfile and setfile have everything covered.
Code:
Copy      Help
str s1 s2 f
f="D:\Test\ArrFiles\Fruit\test.txt"
s1="Chris Johnston"
s1.setfile(f)
s2.getfile(f)
out s2
#2
So the goal for this was to be able to automate Adobe Acrobat to go to a specific page. We have a help/notes reference in our office we are creating. Funny enough a program like Acrobat does not have a way to do this via a command line. To be clear, it has a way to launch a specific instance and go to a page number. However, once the document is already opened, it cannot navigate pages via the command line. Not a problem... because Quick Macros to the rescue. That is what I love about Quick Macros, that being it always has answers where other programs fall short. Our page number is written to a local text file via our help/notes reference (which is a FileMaker Database Solution). So the Quick Macros macro takes it from there. I am sharing hoping other users can take advantage of it. I also hope that more knowledgeable users than myself will suggest better ways to write this macro if any. Thanks
Code:
Copy      Help
str s1 f
f="C:\fmUtil\pdfPage.txt"
s1.getfile(f)
out s1

int w1=win("C-- in One Hour a Day, Sams Teach Yourself, 8th Edition.pdf - Adobe Acrobat Pro DC" "AcrobatSDIWindow")


if (!w1)

,run "D:\Tutor\Training\C Programming\C++\Sams\C-- in One Hour a Day, Sams Teach Yourself, 8th Edition.pdf"
,int w3=wait(19 win("C-- in One Hour a Day, Sams Teach Yourself, 8th Edition.pdf - Adobe Acrobat Pro DC" "AcrobatSDIWindow"))
,'CSn            ;; Ctrl+Shift+N
,int w4=wait(19 win("Go To Page" "#32770"))

,'F"{s1}" Y        ;; Enter
,
else
,
,act w1
,
,'CSn            ;; Ctrl+Shift+N
,int w2=wait(19 win("Go To Page" "#32770"))

,'F"{s1}" Y        ;; Enter
#3
Seeing that you are in an office environment the below alternative might not be usable/allowed.
I use sumatra pdf to open a pdf at a certain item or page, see below code.

Macro sumatra_open_pdf_at_page
Code:
Copy      Help
;How to use:
;1. Assign the correct content below in the variables "pdf_reader" , "pdf_file", "pagenumber" and "named_destination"
;;;;"named_destination" (line 11) is NOT neccessairy if you only want to test pagenumber navigation.
;2. Disable one of the below 'arg' strings, depending on what you want to test.
;;;;If you want to test the 'go to page number' (line 18) then disable the arg string below it (line 24).
;3. run this script

str pdf_reader=F".....\SumatraPDF.exe" ;; path to sumatra .exe
str pdf_file=".....pdf" ;; path to pdf file
int pagenumber=3 ;; pagenumber
str named_destination="''***''" ;; replace the *** to what you want to navigate to (note the DOUBLE QUOTES (double single quotes)). Best to first test an item from the TOC

;; ----  NAVIGATE TO TABLE OF CONTENT ENTRY
;; -named-dest <destination-name> :
;; Searches the first indicated file for a destination or a table-of-contents entry
;; (or starting with version 3.1 also a page label) matching destination-name and scrolls the document to it.
;; Combine with -reuse-instance if the document is already open.
str arg=F"''{pdf_file}'' -page {pagenumber} -reuse-instance"

;; ---- NAVIGATE TO PAGE
;; -page <pageNo> :
;; Scrolls the first indicated file to the indicated page.
;; Combine with -reuse-instance if the document is already open.
str arg=F"''{pdf_file}'' -named-dest {named_destination} -reuse-instance"


run pdf_reader arg ;; https://www.sumatrapdfreader.org/docs/Command-line-arguments.html
#4
Quote:I use sumatra pdf to open a pdf at a certain item or page...
Super cool, I did not know about Sumatra PDF. I will bank it as an option. Thank you so much!
#5
Here is the version that is dynamically equipt to handle any pdf you provide to it. Here is a video showing what it solves for us and demonstrating some of its mechanism.
video
Code:
Copy      Help
str pdfPage pdfPath pdfName n f p
n="C:\fmUtil\pdfName.txt"
f="C:\fmUtil\pdfPath.txt"
p="C:\fmUtil\pdfPage.txt"
pdfName.getfile(n)
pdfPath.getfile(f)
pdfPage.getfile(p)
out pdfName
out pdfPath
out pdfPage

int w1=win(F"{pdfName}" "AcrobatSDIWindow")

if (!w1)

,run F"{pdfPath}"
,int w3=wait(19 win(F"{pdfName}" "AcrobatSDIWindow"))
,'CSn            ;; Ctrl+Shift+N
,int w4=wait(19 win("Go To Page" "#32770"))

,'F"{pdfPage}" Y        ;; Enter
,
else
,
,act w1
,
,'CSn            ;; Ctrl+Shift+N
,int w2=wait(19 win("Go To Page" "#32770"))

,'F"{pdfPage}" Y        ;; Enter


Forum Jump:


Users browsing this thread: 1 Guest(s)