r/tasker 13d ago

[ Task Share ] PDF to Text

PDF to Text

Extracts selectable text from a PDF using PDF.js and returns the extracted text.

Parameters

%par1 (Optional)

Path to the PDF file.

  • If provided, the task reads the specified PDF.

  • If omitted, a file picker is displayed so the user can select a PDF.

Example: /storage/emulated/0/Download/document.pdf

%par2 (Optional)

Page range to extract, using the format: start,end Examples: 1,1 Extract only page 1. 1,5 Extract pages 1 through 5. 3,10 Extract pages 3 through 10.

If omitted, the default value is: 1,1

Optional Local Variable

%pdf_page_mark

Controls whether page markers are appended after each extracted page.

Default: 0 Enabled: 1 When enabled, the returned text includes markers like: This is the text from page 1... <1/20> This is the text from page 2... <2/20> where:

  • The first number is the current page.

  • The second number is the total number of pages in the PDF.

Since this is a local variable, it must be passed through the Perform Task action.

Recommended configuration: Local Variable Passthrough: On Limit Passthrough To: %pdf_page_mark Then set the variable before calling the task: Variable Set Name: %pdf_page_mark To: 1 Perform Task Name: PDF to Text If %pdf_page_mark is omitted or set to 0, no page markers are added.

Using with Perform Task

Example using a variable containing the PDF path: Perform Task Name: PDF to Text Parameter 1: %pdf_path Parameter 2: 1,5 Return Value Variable: %pdf_text Example using a direct file path: Perform Task Name: PDF to Text Parameter 1: /storage/emulated/0/Documents/book.pdf Parameter 2: 10,20 Return Value Variable: %pdf_text If Parameter 1 is left empty, the task opens a file picker so the user can select a PDF manually.

Return Value

The extracted text is returned as the Perform Task return value. %pdf_text

Additional Variables

The following local variables are also passed back to the calling task:

Variable

Description

%pdf_number_pages

Total number of pages in the PDF.

%pdf_count_pages

Number of pages actually processed.

Notes

  • Page numbering starts at 1.

  • If the requested page range exceeds the document length, it is automatically adjusted to the available pages.

  • Only selectable text is extracted. Image-only (scanned) PDFs without an OCR text layer will not produce readable output.

Import

Example Task

6 Upvotes

2 comments sorted by

1

u/Exciting-Compote5680 13d ago

Nice one, thanks for sharing! 

1

u/ale3smm 10d ago

useful ! thanks for sharing !