1. Convert to PDF
Convert Word, Excel, PowerPoint, images to PDF:
```bash
# Convert a text file to PDF
echo "Hello, PDF4ME!" > /tmp/test.txt
BASE64_CONTENT=$(base64 < /tmp/test.txt)
```
Write to /tmp/pdf4me_request.json:
```json
{
"docContent": "${BASE64_CONTENT}",
"docName": "test.txt"
}
```
Then run:
```bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/ConvertToPdf" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json' | jq -r '.docContent' | base64 -d > /tmp/output.pdf
```
2. HTML to PDF
Convert HTML content to PDF:
```bash
HTML_CONTENT=$(echo 'Hello World
This is a test.
' | base64)
```
Write to /tmp/pdf4me_request.json:
```json
{
"docContent": "${HTML_CONTENT}",
"docName": "test.html",
"layout": "Portrait",
"format": "A4"
}
```
Then run:
```bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/ConvertHtmlToPdf" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json' --output /tmp/from-html.pdf
```
3. URL to PDF
Convert a webpage to PDF:
Write to /tmp/pdf4me_request.json:
```json
{
"webUrl": "https://example.com"
}
```
Then run:
```bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/ConvertUrlToPdf" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json' > /tmp/webpage.pdf
```
4. Merge PDFs
Combine multiple PDFs into one:
```bash
PDF1_BASE64=$(base64 < file1.pdf)
PDF2_BASE64=$(base64 < file2.pdf)
```
Write to /tmp/pdf4me_request.json:
```json
{
"docContent": ["${PDF1_BASE64}", "${PDF2_BASE64}"],
"docName": "merged.pdf"
}
```
Then run:
```bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/Merge" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json' | jq -r '.docContent' | base64 -d > merged.pdf
```
5. Split PDF
Split PDF by page ranges:
```bash
PDF_BASE64=$(base64 < input.pdf)
```
Write to /tmp/pdf4me_request.json:
```json
{
"docContent": "${PDF_BASE64}",
"docName": "input.pdf",
"splitAction": "splitAfterPage",
"splitAfterPage": 2
}
```
Then run:
```bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/Split" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json'
```
6. Compress PDF
Reduce PDF file size:
```bash
PDF_BASE64=$(base64 < large.pdf)
```
Write to /tmp/pdf4me_request.json:
```json
{
"docContent": "${PDF_BASE64}",
"docName": "large.pdf"
}
```
Then run:
```bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/Compress" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json' | jq -r '.docContent' | base64 -d > compressed.pdf
```
7. PDF to Word
Convert PDF to editable Word document:
```bash
PDF_BASE64=$(base64 < input.pdf)
```
Write to /tmp/pdf4me_request.json:
```json
{
"docContent": "${PDF_BASE64}",
"docName": "input.pdf"
}
```
Then run:
```bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/PdfToWord" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json' | jq -r '.docContent' | base64 -d > output.docx
```
8. PDF to Images
Create thumbnails/images from PDF pages:
```bash
PDF_BASE64=$(base64 < input.pdf)
```
Write to /tmp/pdf4me_request.json:
```json
{
"docContent": "${PDF_BASE64}",
"docName": "input.pdf",
"imageFormat": "png",
"width": 800
}
```
Then run:
```bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/CreateThumbnail" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json'
```
9. Add Text Stamp/Watermark
Add text watermark to PDF:
```bash
PDF_BASE64=$(base64 < input.pdf)
```
Write to /tmp/pdf4me_request.json:
```json
{
"docContent": "${PDF_BASE64}",
"docName": "input.pdf",
"stampText": "CONFIDENTIAL",
"pages": "all",
"alignX": "center",
"alignY": "middle",
"alpha": 0.3
}
```
Then run:
```bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/TextStamp" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json' | jq -r '.docContent' | base64 -d > stamped.pdf
```
10. OCR - Extract Text from Scanned PDF
Make scanned PDFs searchable:
```bash
PDF_BASE64=$(base64 < scanned.pdf)
```
Write to /tmp/pdf4me_request.json:
```json
{
"docContent": "${PDF_BASE64}",
"docName": "scanned.pdf",
"ocrLanguage": "eng"
}
```
Then run:
```bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/PdfOcr" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json' | jq -r '.docContent' | base64 -d > searchable.pdf
```
11. Protect PDF with Password
```bash
PDF_BASE64=$(base64 < input.pdf)
```
Write to /tmp/pdf4me_request.json:
```json
{
"docContent": "${PDF_BASE64}",
"docName": "input.pdf",
"password": "secret123"
}
```
Then run:
```bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/ProtectDocument" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json' | jq -r '.docContent' | base64 -d > protected.pdf
```
12. Extract Pages
Extract specific pages from PDF:
```bash
PDF_BASE64=$(base64 < input.pdf)
```
Write to /tmp/pdf4me_request.json:
```json
{
"docContent": "${PDF_BASE64}",
"docName": "input.pdf",
"pageNrs": [1, 3, 5]
}
```
Then run:
```bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/ExtractPages" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json' | jq -r '.docContent' | base64 -d > extracted.pdf
```
---