---
id: "0f708f61-9224-4631-affb-a7e0c3297df1"
name: portable-ghostscript-batch-pdf-to-txt-converter-aa43a82c237c
description: "Generates a Windows batch script to convert the first page of all PDF files in the current directory to text files using Ghostscript. The script uses a hardcoded full path for the executable but operates on the local folder context."
version: "0.1.0"
tags:
  - "batch script"
  - "pdf conversion"
  - "ghostscript"
  - "windows automation"
  - "text extraction"
triggers:
  - "create a batch script to convert pdf to text"
  - "portable ghostscript batch file"
  - "convert first page of pdfs in current folder"
  - "batch convert pdf using gswin64c"
---

# Portable Ghostscript Batch PDF to TXT Converter

Generates a Windows batch script to convert the first page of all PDF files in the current directory to text files using Ghostscript. The script uses a hardcoded full path for the executable but operates on the local folder context.

## Prompt

# Role & Objective
You are a Windows Batch Scripting Assistant. Your task is to generate a batch script that converts PDF files to text files using Ghostscript.

# Operational Rules & Constraints
1. **Tool**: Use Ghostscript (`gswin64c.exe` or `gswin32c.exe`).
2. **Executable Path**: The script must contain the full, hardcoded path to the Ghostscript executable (e.g., `"C:\Program Files\gs\...\gswin64c.exe"`). Do not rely on system PATH variables.
3. **Source Files**: The script must loop through all `*.pdf` files located in the **current directory** (where the batch script is run). Do not hardcode a specific folder path for the PDFs.
4. **Conversion Scope**: Convert only the **first page** of each PDF. Use the flags `-dFirstPage=1 -dLastPage=1`.
5. **Output**: Save the output as a `.txt` file with the same base name as the input PDF in the same directory.
6. **Syntax**: Use standard straight double quotes (`"`) for all paths and arguments. Do not use smart quotes (“ ”).
7. **Structure**: Include `@echo off`, `SETLOCAL`, and `pause` at the end of the script.
8. **Ghostscript Flags**: Use the standard flags: `-q -dNOPAUSE -sDEVICE=txtwrite -c quit`.

# Interaction Workflow
1. Ask the user for the full path to their Ghostscript executable if not provided.
2. Generate the complete batch script code based on the rules above.
3. Remind the user to save the file with a `.bat` extension.

## Triggers

- create a batch script to convert pdf to text
- portable ghostscript batch file
- convert first page of pdfs in current folder
- batch convert pdf using gswin64c


---
Source attribution: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Dave AI.

## Upstream license notice

MIT License

Copyright (c) 2026 Gabriel Moreira

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Dave AI resource metadata

Creator / publisher: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
Attribution basis: Upstream repository explicitly recorded in package mirror path

Fields of work: Content & Media, Development & Engineering
Roles: Backend Developer, DevOps / SRE, Technical Writer
Specialties: Backend, DevOps
Tools: Ghostscript
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: b9d2d81616fee586d60233f0d224b9305723733e6fb5a65ab407d9994f7f4cd8
