# Decrypt pdfs while import into DT

**URL:** https://discourse.devontechnologies.com/t/decrypt-pdfs-while-import-into-dt/65921
**Category:** Automation
**Created:** [July 31, 2021, 8:30am UTC](https://discourse.devontechnologies.com/t/decrypt-pdfs-while-import-into-dt/65921 "2021-07-31T08:30:06Z")
**Posts on this page:** 1
**Showing post:** 15

<div class="post-metadata">

### Author: ![pete31](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/p/d26b3c/32.png) [@pete31](https://discourse.devontechnologies.com/u/pete31)
#### Post date: [August 5, 2021, 1:07pm UTC](https://discourse.devontechnologies.com/t/decrypt-pdfs-while-import-into-dt/65921/15 "2021-08-05T13:07:36Z")

</div>

> [@vinschger](#):
>
> decrypt it with a given password

You could try this script in Script Editor.app. To test:

- put an encrypted PDF on your desktop, name `Input PDF.pdf`
- set your password in property `thePassword`
- run script

If the result is an unencrypted new PDF then the rest should be quite easy.

I’ve never used encrypted PDFs so I may be missing something, but it seems to work over here.

```auto
-- Test - Decrypt PDF

use AppleScript version "2.4"
use framework "Foundation"
use framework "Quartz"
use scripting additions

property thePassword : "test"
property theInputPath : POSIX path of (path to desktop) & "Input PDF.pdf" -- path of form "/Users/User/Desktop/Input PDF.pdf" (just in case you want to use something else than the desktop)
property theOutputPath : POSIX path of (path to desktop) & "Output PDF.pdf"

set thePDF to current application's PDFDocument's alloc()'s initWithURL:(current application's |NSURL|'s fileURLWithPath:theInputPath)
thePDF's unlockWithPassword:thePassword
thePDF's writeToFile:theOutputPath

```

---

_[View the full topic](https://discourse.devontechnologies.com/t/decrypt-pdfs-while-import-into-dt/65921)._
