for %i in (*.pdf) do gswin64c -q -dNOPAUSE -sDEVICE=txtwrite -sOutputFile=“%~ni.txt”…
- User
for %i in (*.pdf) do gswin64c -q -dNOPAUSE -sDEVICE=txtwrite -sOutputFile=“%~ni.txt” -dFirstPage=1 -dLastPage=1 “%i” -c quit for this command i want to create a file that double cliked to run with power shell
- Assistant
To create a file that can be double-clicked to run the above command with PowerShell, you can create a batch script file (.bat). Here's how you can do it:
- Open a text editor like Notepad.
- Write the following command in the text editor:
@echo off for %%i in (*.pdf) do gswin64c -q -dNOPAUSE -sDEVICE=txtwrite -sOutputFile="%%~ni.txt" -dFirstPage=1 -dLastPage=1 "%%i" -c quit pause- Save the file with a .bat extension. For example, you can save it as "convert_pdf_to_txt.bat".
Now, you can double-click the "convert_pdf_to_txt.bat" file to run the specified command on all PDF files in the same directory. The script will convert each PDF file into a text file with the same name.
- User
Operand stack: Execution stack: %interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push Dictionary stack: --dict:748/1123(ro)(G)-- --dict:0/20(G)-- --dict:85/200(L)-- Current allocation mode is local Last OS error: No such file or directoryGPL Ghostscript 10.03.0: Unrecoverable error, exit code 1 Error: /undefinedfilename in (\316\223\303\207\302\2434500689364-ALL-MALE-100FOI-ARICI-150MM-BLACKBLUE-TK111150-LASER.pdf\316\223\303\207\302\245)
- Assistant
It seems like there is an issue with the file path or name when running the command. The error message indicates that Ghostscript is encountering an "undefinedfilename" because it cannot find the file specified.
Make sure that the PDF files are located in the same directory as the batch script or provide the full path to the directory where the PDF files are located in the script. Additionally, ensure that the file names do not contain any special characters or non-ASCII characters that may cause issues with the command.
You can modify the batch script to include the full path to the directory where the PDF files are located. Here is an example:
@echo off setlocal set "pdf_dir=C:\path\to\pdf\directory" for %%i in ("%pdf_dir%\*.pdf") do ( gswin64c -q -dNOPAUSE -sDEVICE=txtwrite -sOutputFile="%%~ni.txt" -dFirstPage=1 -dLastPage=1 "%%i" -c quit ) pauseReplace
C:\path\to\pdf\directorywith the actual full path to the directory where the PDF files are located. Save the modified script and run it again to see if the issue is resolved. - User
another metod to run this command like an shortcut ?
- Assistant
One way to run a command like this with a shortcut is to create a shortcut to Command Prompt and specify the command as an argument to execute when the shortcut is opened. Here's how you can do it:
-
Right-click on the desktop and select "New" > "Shortcut".
-
In the "Create Shortcut" window, click on "Browse" and navigate to "cmd.exe" (Command Prompt) on your system. It is usually located in the "C:\Windows\System32" folder.
-
Select "cmd.exe" and click "OK".
-
In the "Type the location of the item" field, add the following command after the path to "cmd.exe":
/k gswin64c -q -dNOPAUSE -sDEVICE=txtwrite -sOutputFile="output.txt" -dFirstPage=1 -dLastPage=1 "input.pdf" -c quitReplace "input.pdf" with the path to the PDF file you want to convert.
-
Click "Next" and type a name for the shortcut (e.g., Convert PDF to Text) and click "Finish".
Now, when you double-click on the shortcut, it will open Command Prompt and automatically execute the Ghostscript command to convert the specified PDF file to text. You can customize the command in the shortcut to suit your specific needs.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.