Help using doc.saveAS method to convert pdf to txt

Forum for the PDF-XChange Editor - Free and Licensed Versions

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Paul - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

anachroman
User
Posts: 3
Joined: Tue Jan 09, 2024 11:57 pm

Help using doc.saveAS method to convert pdf to txt

Post by anachroman »

Hi,

I am testing some code to do batch conversion of pdf to plain text.
I can use the doc.saveAs method to save a copy of a pdf file, but not a text file.
For example:

// This does not work:
var srcFile = app.openDoc({ cPath: "/c/3-Full-Interviews-Transcripts/01-Dr-Group.pdf", bHidden: false });

srcFile.saveAs("/c/3-Full-Interviews-Transcripts/01-Dr-Group.txt");
srcFile.closeDoc();

// Error is:
Console:Exec:4: NotAllowedError: NotAllowedError: Security settings prevent access to this property or method.
Doc.saveAs:4:Console:Exec

I have also tried with
srcFile.saveAs("/c/3-Full-Interviews-Transcripts/01-Dr-Group.txt","com.adobe.acrobat.plain-text");

That gives the console error:
Console:Exec:11: InvalidArgsError: InvalidArgsError: Invalid arguments.
Doc.saveAs:11:Console:Exec

I am suspecting that either you do not support conversion of pdf to text using this method, or I am using an incorrect cConvID string.
Any thoughts?

Also are you ever considering implementing breakpoints in the JavaScript window?

Thanks much
Sunilkumar
User
Posts: 10
Joined: Sat Mar 14, 2026 10:27 am

Re: Help using doc.saveAS method to convert pdf to txt

Post by Sunilkumar »

Hello,

Based on the errors you've shared, it appears that Doc.saveAs() may be restricted to supported output formats and may not directly export PDF content to plain text. The NotAllowedError could also indicate that the method is being executed from a context where file system access is restricted by JavaScript security settings.

You might want to check whether PDF-XChange provides a dedicated export or text extraction method instead of relying on saveAs() with a .txt extension. If plain-text export is supported, there may be a specific conversion ID or SDK/API function required for that operation.

As a troubleshooting step, have you tried running the script from a trusted folder-level script or batch environment to rule out JavaScript security restrictions? It would also be helpful to know which PDF-XChange product and version you're using, as scripting capabilities can vary between products.

I'm interested to see whether the PDF-XChange team can confirm if plain-text export is supported through saveAs() or if a different approach is recommended.
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 12928
Joined: Wed Jan 03, 2018 6:52 pm

Re: Help using doc.saveAS method to convert pdf to txt

Post by Daniel - PDF-XChange »

Hello,

Thank you for the post, I had to check in with the Dev team on this, here was their reply:
You have to specify cConvID, otherwise saveAs will fail as the file extension does not correspond to the requested format.
The proper converter ID for PDF->Text converter in the Editor is conv.exp.txt. It can be found in app.fromPDFConverters.
Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
[email protected]
User avatar
Mathew
User
Posts: 835
Joined: Thu Jun 19, 2014 7:30 pm

Re: Help using doc.saveAS method to convert pdf to txt

Post by Mathew »

Daniel - PDF-XChange wrote: Wed Jun 03, 2026 3:00 pm Hello,

Thank you for the post, I had to check in with the Dev team on this, here was their reply:
You have to specify cConvID, otherwise saveAs will fail as the file extension does not correspond to the requested format.
The proper converter ID for PDF->Text converter in the Editor is conv.exp.txt. It can be found in app.fromPDFConverters.
Kind regards,
Hi Daniel,

I think there may be a bug in v11.0.0 for exporting to text.

I'm also not able to get this method to work for exporting to text in v11.0.0 -- I always get an empty text file:

Code: Select all

srcFile.saveAs({cPath:"/c/3-Full-Interviews-Transcripts/01-Dr-Group.txt", cConvID:'conv.exp.txt', bPromptToOverwrite: true});
But I get the same result when using File > Save As > Save as type > Plain Text (*.txt). I've attached a sample file that's all text, but results in a blank text export for me. In v10.8.410 it exports to text fine.

- Mathew.
You do not have the required permissions to view the files attached to this post.
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 12928
Joined: Wed Jan 03, 2018 6:52 pm

Re: Help using doc.saveAS method to convert pdf to txt

Post by Daniel - PDF-XChange »

Hello, Mathew

Thank you for the report, I have run some testing and it seems this issue is resolved in our 11.0.1 internal testing, but I have escalated this to them for review just in case.

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
[email protected]
anachroman
User
Posts: 3
Joined: Tue Jan 09, 2024 11:57 pm

Re: Help using doc.saveAS method to convert pdf to txt

Post by anachroman »

Thanks everyone. I will give it a try although I'm sure it will work. I am using Editor Plus v10.8.410. Originally, I tried it from a trusted location where another of my js functions work and from the console. I love this product. :D
User avatar
Sean - PDF-XChange
Site Admin
Posts: 1091
Joined: Wed Sep 14, 2016 5:42 pm

Re: Help using doc.saveAS method to convert pdf to txt

Post by Sean - PDF-XChange »

Hi anachroman,

I hope that works out for you - please let us know if you have any problems, and we'll be happy to assist you.

Kind regards,
Sean Godley
Technical Writer
PDF-XChange Co LTD
Sales: +1 (250) 324-1621
Fax: +1 (250) 324-1623