=== RelahConvert PDF & Office Tools ===
Contributors: brightagbomado
Tags: pdf, pdf editor, merge pdf, split pdf, compress pdf
Requires at least: 5.6
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 1.0.2
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

PDF and Office tools in your Media Library — your file never leaves your device. Merge, split, compress, watermark, protect, Excel to Word, more.

== Description ==

**RelahConvert PDF & Office Tools** is a Media Library extension that brings 16 free PDF and Office document tools to WordPress. Click a tool button on any PDF, Word, Excel, or PowerPoint attachment, process the file on RelahConvert.com, and the result is sent back to your Media Library automatically.

**Your file never leaves your device.** All 16 tools process your PDF or Office document entirely in your browser — there is no server-side conversion step, no third-party processing API, no upload to RelahConvert's servers for the file itself. The processing JavaScript runs locally on whatever device you have the Media Library open on.

This plugin is a sibling to **RelahConvert Image Tools** (38 image tools). They cover non-overlapping file types — install one, both, or neither.

= The 16 tools =

**PDF — Organize**
* Merge PDF — combine multiple PDF files into a single document
* Split PDF — split a PDF into multiple files by page range
* Reorder Pages — drag and drop to reorder pages
* Extract Pages — pull specific pages into a new document
* Remove Pages — remove unwanted pages

**PDF — Edit**
* Rotate PDF — rotate pages by 90, 180, or 270 degrees
* Crop PDF — crop margins or specific areas
* Add Page Numbers — add page numbers with custom positioning
* Watermark PDF — add text or image watermarks
* Extract Images — pull every embedded image out of a PDF

**PDF — Optimize & Security**
* Compress PDF — reduce file size while preserving quality
* Protect PDF — add a password
* Unlock PDF — remove the password from a PDF you own

**Office ↔ Office**
* Excel to Word — convert .xlsx spreadsheets to editable .docx documents
* Word to Excel — convert .docx documents to editable .xlsx spreadsheets
* PowerPoint to Word — convert .pptx slide text and tables to .docx documents

= Where Processing Happens =

**All 16 tools process your file entirely in your browser using open-source JavaScript libraries** (pdf-lib, pdfjs, JSZip, mammoth.js, SheetJS, docx). Your PDF, Word, Excel, or PowerPoint file never leaves your device for the actual conversion or editing step.

The only network activity tied to file content is **"Send to WordPress"** — when you choose to send your processed file back to your Media Library, the plugin POSTs it to a REST endpoint on your own WordPress site using a short-lived authentication token.

**Optional, only if the user signs in on RelahConvert.com:** Save to Account uploads the processed file to Supabase Storage so it can be re-downloaded later. Sign-in is not required to use any tool.

= Seamless WordPress Integration =

Click a tool button in the Media Library → file opens on RelahConvert.com with your file auto-loaded → process it in your browser → click "Send to WordPress" → processed file lands back in your Media Library. No manual download and re-upload.

= How It Works =

1. Activate the plugin and click **Connect** on the **Settings → RelahConvert PDF** page. This is a one-click authorization that uses WordPress's built-in Application Passwords — no setup, no API keys.
2. Go to your WordPress Media Library.
3. Click any RelahConvert action button on a PDF, .docx, .xlsx, or .pptx attachment (Merge, Split, Compress, or To Word / To Excel).
4. The tool opens on RelahConvert.com with your file auto-loaded.
5. Process your file with one click — everything happens in your browser.
6. Click "Send to WordPress" to add the processed file directly back to your Media Library.

You can use the 16 tools for conversion without connecting — the one-time Connect step only enables the round-trip "Send to WordPress" upload.

= Third-Party Services =

This plugin loads the processing UI from [RelahConvert.com](https://relahconvert.com). When you click a tool button in the Media Library, your browser opens RelahConvert.com with your file auto-loaded.

What happens there:

* **All 16 tools (Merge, Split, Compress, Rotate, Watermark, Excel ↔ Word, etc.)** — Processing runs in your browser via JavaScript. No network roundtrip for your file itself.
* **Library scripts via jsDelivr CDN** — On first use of a tool, RelahConvert.com loads JavaScript libraries (pdfjs for PDF parsing, JSZip for ZIP bundling) from the [jsDelivr](https://www.jsdelivr.com) public CDN. Only the library code is fetched from jsDelivr; no user data is sent there. Subject to [jsDelivr Privacy](https://www.jsdelivr.com/privacy-policy-jsdelivr-net).
* **Save to Account (optional)** — Only if the user signs in with Google or email on RelahConvert.com. Files are stored on Supabase Storage. [Supabase Terms](https://supabase.com/terms) and [Privacy](https://supabase.com/privacy).
* **Send to WordPress** — Sends the processed file from your browser back to your WordPress site using WordPress's standard `/wp/v2/media` REST endpoint, authenticated via the Application Password you generated during Connect. No custom auth code on the upload path — WordPress core handles the authentication.

By using this plugin, you agree to [RelahConvert's Terms of Service](https://relahconvert.com/terms) and [Privacy Policy](https://relahconvert.com/privacy), and to the terms of any third-party service you choose to use through it.

= CORS Configuration =

On activation, this plugin adds a CORS header to your `wp-content/uploads/.htaccess` file to allow RelahConvert.com to load your attachments for processing:

`Header set Access-Control-Allow-Origin "https://relahconvert.com"`

The block is bracketed by `# BEGIN RelahConvert-PDF CORS` and `# END RelahConvert-PDF CORS` markers so the plugin can clean up after itself. The rule is automatically removed when the plugin is deactivated.

If you also use the **RelahConvert Image Tools** plugin, both plugins manage their own marker blocks independently — they coexist without interfering with each other.

= Features =

* Action buttons in Media Library list view and grid view for PDF, .docx, .xlsx, and .pptx attachments
* "More Tools" dropdown with all 13 PDF tools on every PDF attachment
* Auto-loads your file into the selected tool
* "Send to WordPress" button sends processed files directly back to your Media Library
* MIME-aware — the right tools show up for the right file types
* Settings page with quick links to all 16 tools
* Lightweight — no bloat, minimal database usage (temporary tokens only)
* Works with the Classic Editor and Block Editor
* Coexists cleanly with the RelahConvert Image Tools plugin (separate REST namespace, separate .htaccess marker, separate transient keys)

== Installation ==

1. Upload the `relahconvert-pdf-office-tools` folder to `/wp-content/plugins/`.
2. Activate the plugin through the **Plugins** menu in WordPress.
3. Go to **Settings > RelahConvert PDF** to see all available tools.
4. Open your **Media Library** to start using the action buttons on PDF / Office attachments.

== Frequently Asked Questions ==

= Does this plugin upload my PDFs or documents to a server? =

No. All 16 tools process your file entirely in your browser using JavaScript libraries (pdf-lib, pdfjs, JSZip, mammoth.js, SheetJS, docx). Your PDF, Word, Excel, or PowerPoint file never leaves your device.

The only time your file moves over a network is when you explicitly click **"Send to WordPress"** to upload the processed result back to your own Media Library. That goes only to your WordPress site, not to any third party.

= Is it free? =

Yes. All 16 tools are free to use. No account is required for processing. No watermark is added to output. Optional sign-in unlocks cloud-saved files and preference sync across devices.

= Do I need an API key? =

No. The plugin uses WordPress's built-in Application Passwords, which are generated automatically when you click "Connect" on the plugin settings page. You never enter or manage an API key.

= How is the "Send to WordPress" upload authenticated? =

The plugin uses [WordPress Application Passwords](https://developer.wordpress.org/rest-api/frequently-asked-questions/#how-can-i-authenticate-application-passwords-requests) — the official WordPress mechanism for authenticating third-party app requests. When you click **Connect** in plugin settings, WordPress's built-in authorization screen asks you to approve the app once. WordPress generates an application-specific password (separate from your login password) and stores it. The plugin then uses that password to authenticate the upload via WordPress's native `/wp/v2/media` REST endpoint using HTTP Basic Auth. You can revoke access at any time via plugin settings (Disconnect) or directly from your WordPress profile under "Application Passwords".

= Why are Word→PDF, Excel→PDF, and PowerPoint→PDF not in this plugin? =

Those conversions (and the reverse direction — PDF→Word, PDF→Excel, PDF→PowerPoint) require a server-side conversion engine because they can't be done reliably in the browser. RelahConvert.com offers them as free tools through a third-party conversion API. We've intentionally excluded them from this plugin so that everything in the plugin can guarantee "your file never leaves your device." If you need those conversions, visit [RelahConvert.com](https://relahconvert.com).

= Does it work with the Block Editor (Gutenberg)? =

Yes. The plugin adds action buttons in the media library modal used by both the Classic Editor and Block Editor.

= What does "Send to WordPress" do? =

After processing a file on RelahConvert.com, you can click "Send to WordPress" to upload the processed file directly to your WordPress Media Library without manually downloading and re-uploading.

= Does this plugin modify my .htaccess file? =

Yes. On activation, the plugin adds a CORS header to `wp-content/uploads/.htaccess` to allow RelahConvert.com to load your attachments. The block is wrapped in `# BEGIN RelahConvert-PDF CORS` / `# END RelahConvert-PDF CORS` markers and is removed on deactivation.

= Can I use this alongside the RelahConvert Image Tools plugin? =

Yes. The two plugins use distinct REST namespaces (`relahconvert-pdf/v1` vs `relahconvert/v1`), distinct .htaccess marker blocks, and distinct transient key prefixes. They are designed to coexist.

== Screenshots ==

1. Media Library grid view with RelahConvert PDF buttons (Merge, Split, Compress, More) on a PDF attachment.
2. RelahConvert tool with PDF auto-loaded and Send to WordPress button.
3. Settings page listing all 16 tools.

== Changelog ==

= 1.0.2 =
* Fix: "Send to WordPress" button now appears for connected users. The Media Library tool buttons were emitting URLs without the handoff token, so RelahConvert tools opened without the upload-back capability even when the site was connected.

= 1.0.1 =
* Authentication: replaced custom token-based REST endpoint with WordPress's built-in Application Passwords. "Send to WordPress" now uses the standard `/wp/v2/media` REST endpoint with HTTP Basic Auth — no custom auth code on the upload path.
* New: Connect / Disconnect flow on the plugin settings page. One-click authorization via WordPress's `authorize-application.php`.
* New: Admin notice on the Media Library prompting users to connect for "Send to WordPress" functionality.
* Bumped minimum WordPress version to 5.6 (required for Application Passwords).
* Tools continue to work for conversion without connecting — only the round-trip upload requires the one-time Connect.

= 1.0.0 =
* Initial release.
* 13 PDF tools (Merge, Split, Compress, Rotate, Reorder, Extract, Remove, Add Page Numbers, Watermark, Crop, Protect, Unlock, Extract Images).
* 3 Office↔Office conversion tools (Excel ↔ Word, PowerPoint → Word).
* MIME-aware action buttons in the Media Library for PDF, .docx, .xlsx, and .pptx.
* Auto-loads attachments into RelahConvert tools.
* "Send to WordPress" posts processed files back to the Media Library via a token-authenticated REST endpoint.
* Settings page with tool overview.

== Upgrade Notice ==

= 1.0.1 =
Authentication now uses WordPress's built-in Application Passwords. After updating, click Connect on the plugin settings page to re-authorize. Minimum WordPress version is now 5.6.

= 1.0.0 =
Initial release.
