Paperless-ngx ใช้ดูแลจัดการเอกสาร
เป็นโปรแกรมที่ไว้ช่วยจัดการเอกสารต่าง ๆ ให้เป็นระเบียบ รองรับ multi user ในการเข้ามาใช้ร่วมกัน แต่ไม่มีของใครของมันนะ โดยโปรแกรมเองมี OCR ข้อความในเอกสารได้หลายภาษา รวมภาษาไทยด้วย ช่วยให้ค้นหาสิ่งที่ต้องการได้ง่ายขึ้น คือมีรายละเอียดอื่น ๆ เยอะมากลองไปงมดูได้ใน https://github.com/paperless-ngx/paperless-ngx หรือลองดู demo จากในนั้นก็ได้
อย่าคาดหวังมากกับ OCR ภาษาไทย จากที่ลองคือแค่พอใช้ได้
ไฟล์ docker-compose ด้านล่างนี้ ผ่านการลองถูกลองผิดมาเยอะพอสมควร และได้ทำการรวม env ที่น่าจะสำคัญทำมาให้หมดแล้ว ไม่ต้องสร้างไฟล์แยกแบบตัวติดตั้งต้นฉบับ และได้แก้ระบบ folder เรียงไฟล์ให้ใหม่ เผื่อโปรแกรมนี้ระเบิดจะได้ค้นไฟล์ง่าย ๆ ในภายหลัง
ขั้นตอนติดตั้ง
จัดเตรียมไฟล์
save code ด้านล่างไปทำไฟล์ docker-compose.yaml
# docker-compose file for running paperless from the docker container registry.
# This file contains everything paperless needs to run.
# Paperless supports amd64, arm and arm64 hardware.
# All compose files of paperless configure paperless in the following way:
#
# - Paperless is (re)started on system boot, if it was running before shutdown.
# - Docker volumes for storing data are managed by Docker.
# - Folders for importing and exporting files are created in the same directory
# as this file and mounted to the correct folders inside the container.
# - Paperless listens on port 8000.
#
# SQLite is used as the database. The SQLite file is stored in the data volume.
#
# In addition to that, this docker-compose file adds the following optional
# configurations:
#
# - Apache Tika and Gotenberg servers are started with paperless and paperless
# is configured to use these services. These provide support for consuming
# Office documents (Word, Excel, Power Point and their LibreOffice counter-
# parts.
#
# For more extensive installation and update instructions, refer to the
# documentation.
version: "3.4"
services:
broker:
image: redis:6.0
restart: always
volumes:
- /volume1/docker/paperless-redis:/data # <-- Update
webserver:
image: ghcr.io/paperless-ngx/paperless-ngx:latest
restart: always
depends_on:
- broker
- gotenberg
- tika
ports:
- 8010:8000 # <-- Update
healthcheck:
test: ["CMD", "curl", "-fs", "-S", "--max-time", "2", "http://localhost:8010"] # <-- Update
interval: 30s
timeout: 10s
retries: 5
volumes:
- /volume1/docker/paperless-ngx/data:/usr/src/paperless/data # <-- Update
- /volume1/docker/paperless-ngx/media:/usr/src/paperless/media # <-- Update
- /volume1/docker/paperless-ngx/export:/usr/src/paperless/export # <-- Update
- /volume1/docker/paperless-ngx/consume:/usr/src/paperless/consume # <-- Update
environment:
PAPERLESS_REDIS: redis://broker:6379
PAPERLESS_TIKA_ENABLED: 1
PAPERLESS_TIKA_GOTENBERG_ENDPOINT: http://gotenberg:3000
PAPERLESS_TIKA_ENDPOINT: http://tika:9998
USERMAP_UID: 1035 # <-- Update
USERMAP_GID: 100 # <-- Update
PAPERLESS_SECRET_KEY: fdsfdsfdszcbvcngikh # <-- Update
PAPERLESS_URL: https://paperless.yourname.synology.com # <-- Update
PAPERLESS_TIME_ZONE: Asia/Bangkok
PAPERLESS_OCR_LANGUAGES: tha
PAPERLESS_OCR_LANGUAGE: tha+eng
PAPERLESS_ADMIN_USER: admin # <-- Update
PAPERLESS_ADMIN_PASSWORD: admin # <-- Update
PAPERLESS_FILENAME_FORMAT: "{correspondent}/{created_year}-{created_month}_{correspondent}-{title}"
gotenberg:
image: gotenberg/gotenberg:7.4
restart: always
command:
- "gotenberg"
- "--chromium-disable-routes=true"
tika:
image: ghcr.io/paperless-ngx/tika:latest
restart: always
volumes:
data:
media:
redisdata:
ใช้ notepad หรืออะไรก็ได้เปิดไฟล์ docker-compose.yaml ขึ้นมา เน้นดูตรงส่วนของ comment ในไฟล์ แก้ให้ตรงกับที่ใช้
ports:
- 8010:8000 # <-- Update
healthcheck:
test: ["CMD", "curl", "-fs", "-S", "--max-time", "2", "http://localhost:8010"] # <-- Update
port ที่ใช้เชื่อมต่อ default และ container port ค่าเริ่มต้นตั้งมาที่ 8000 ในตัวอย่างต้ั้งไว้ที่ 8010 ส่วนของ healthcheck ก็ตั้ง port ให้ตรงกัน ถ้าไปใช้ port อื่น
USERMAP_UID: 1035 # <-- Update
USERMAP_GID: 100 # <-- Update
PUID และ PGID ตั้งให้ตรงกับ ID ของเราเพื่อกันไม่ให้เกิดปัญหาเกี่ยวกับ permission ของ docker หาได้จาก วิธีหา UID และ GID เพื่อใช้ติดตั้งโปรแกรมใน Docker
PAPERLESS_SECRET_KEY: fdsfdsfdszcbvcngikh # <-- Update
PAPERLESS_URL: https://paperless.yourname.synology.me # <-- Update
PAPERLESS_SECRET_KEY สิ่งที่ช่วยให้เราโดน hack ได้ยากขึ้นถ้าเปิด paperless ให้เข้าใช้ได้จาก internet วิธีทำคือ พิมพ์อักษรอะไรก็ได้ไปมั่ว ๆ ยิ่งยาวยิ่งดี ถ้านึกไม่ออกเอามือรูด keyboard ไปเลยก็ได้ 🤣(เฉพาะตัวอักษรและตัวเลขไม่รวมเครื่องหมาย)
PAPERLESS_URL เช่นเดียวกับด้านบนเพื่อความปลอดภัย ตั้งให้ตรงกับ URL ที่เราจะใช้ ถ้าไม่ได้ใช้ reverse proxy ควรตั้งให้เป็น DDNS หรือ IP และ Port ที่ใช้งาน เช่น
ถ้า Reverse Proxy URL ของคุณคือ yourname.synology.me และต้องการเข้าผ่านทางซับโดเมน paperless ก็ใส่เป็น https://paperless.yourname.synology.me
ถ้าไม่ใช้ reverse proxy หรือ DDNS คือไม่ต้องการให้เชื่อมต่อได้จาก internet ก็อาจใส่แค่ก็ใส่แค่ ip และ port ของ NAS พอ คือเช่น http://192.168.10:8010
ระวังเรื่อง HTTP, HTTPS ใส่ให้ถูกต้องเดี๋ยวจะเข้าไม่ได้ รวมถึงเรื่อง forward port ด้วย ถ้าไม่ได้ใช้ reverse proxy
การตั้งค่าในส่วนนี้มีความวุ่นวายพอสมควรและซับซ้อน เพราะมี env หลายตัวให้ตั้งค่า ถ้าต้องการทำนอกเหนือจากนี้ให้ไปดูเอกสารเต็มที่ https://paperless-ngx.readthedocs.io/en/latest/configuration.html#hosting-security
PAPERLESS_ADMIN_USER: admin # <-- Update
PAPERLESS_ADMIN_PASSWORD: admin # <-- Update
ตั้งค่า Username และ Password ในการเข้าสู่ระบบสำหรับ Admin หรือจะลบทั้ง 2 แถวนี้ออกไปเลยก็ได้ แล้วค่อยเข้าไปเปลี่ยนภายในเมนู Admin (default: admin/admin)
หากมีการแก้ใข Username หรือ Password ผ่านระบบ Admin ภายใน Paperless-ngx แล้วยังมี env 2 ค่านี้อยู่ ทุกครั้งที่ run docker ใหม่ ระบบจะถูกรีเซตกลับมาเป็นค่านี้ทุกครั้ง ดังนั้นถ้าไม่ต้องการให้ Username หรือ Password มีการเปลี่ยนแปลง แนะนำให้ลบ 2 ค่านี้ก่อนเริ่มทำงาน docker ใหม่ ในส่วนที่ใช้จัดการ env ของ synology docker
แก้เสร็จหมดแล้วให้เซฟไฟล์
จัดเตรียม folder ติดตั้ง
ย้อนกลับไปดูไฟล์ docker-compose.yaml อีกครั้ง ในส่วนของ volume
volumes:
- /volume1/docker/paperless-redis:/data # <-- Update
และ
volumes:
- /volume1/docker/paperless-ngx/data:/usr/src/paperless/data # <-- Update
- /volume1/docker/paperless-ngx/media:/usr/src/paperless/media # <-- Update
- /volume1/docker/paperless-ngx/export:/usr/src/paperless/export # <-- Update
- /volume1/docker/paperless-ngx/consume:/usr/src/paperless/consume # <-- Update
จะเห็นได้ว่าเราจะต้องมีการสร้าง 2 folder ย่อยใน docker นอกจากนี้จะมีอีก 4 folder ย่อยใน paperless-ngx อีกด้วย หน้าตาก็จะได้ประมาณนี้
docker
│
└─── paperless-ngx
│ │ docker-compose.yaml
│ │
│ └─── data
│ │
│ └─── media
│ │
│ └─── export
│ │
│ └─── consume
│
└─── paperless-redis
ถ้าต้องการใช้ชื่ออื่นก็แล้วแต่สะดวก แต่ย้อนกลับไปแก้ docker-compose.yaml ให้ถูกต้องด้วยด้วย
เข้าไปจัดการสร้าง folder ผ่าน File Station ใน DSM ให้เรียบร้อย
ตัวอักษรเล็กใหญ่มีผล ตั้งให้ถูกต้อง ไม่งั้นจะไป error ในขั้นตอนติดตั้ง
หลังจากนั้น copy ไฟล์ docker-compose.yml ที่ทำไว้แล้วไปใส่ไว้ใน paperless-ngx
SSH แล้วติดตั้งโปรแกรมตามขั้นตอนปกติ (วิธีติดตั้งเหมือน pi-hole)
cd /volume1/docker/paperless-ngx
docker-compose up -d
หาก error ในขั้นตอนไหนให้ดูแจ้ง error แล้ว docker-compose up -d อีกรอบติดตั้งต่อได้เลย
ใช้งานเบื้องต้น
- หลังจากเข้าได้แล้วก็อย่าลืมไปจัดการเรื่อง Username และ Password ให้เรียบร้อยในเมนู Admin
- ทำการอัพโหลดเอกสารเข้าไปไม่ต้องเยอะมาก โดยเอกสารที่อัพโหลดเข้าไปจะถูก rename ทั้งหมด ตามค่าที่ตั้งไว้ใน env ในขั้นตอนติดตั้ง และจะถูก OCR ตามภาษาที่ตั้งไว้ โดยผมตั้งไว้ให้แล้วที่ Thai + English
- สร้าง Tag หรือ Document type แล้วลองตั้ง
Matching algorithmให้เป็น Auto หรือจะใช้ regex ต่าง ๆ แบบทำเองก็ได้
- หากใช้
Matching algorithmเป็น Auto ให้ทำการ tag เอกสารด้วยตัวเองเท่าที่จะทำได้ แยกเอกสารประเภทต่าง ๆ เช่น พวกใบเสร็จธนาคาร ก็ tag ว่าBankให้มีตัวอย่างจำนวนหนึ่ง แต่เยอะ ๆ ก็ยิ่งดี เพื่อเป็นตัวอย่างให้ neural network เอาไปศึกษาและจัดกลุ่มให้อัตโนมัติในอนาคต รายละเอียดไปอ่านที่ Automatic matching - ค่าเดิมของเอกสารที่เข้าไปจะถูก rename เป็นตัวเลขทั้งหมด แต่จาก env
PAPERLESS_FILENAME_FORMATได้ถูกตั้งค่าให้ใหม่แล้วเป็น correspondent/YY-MM_correspondent-ชื่อไฟล์เดิม หรือให้เข้าใจง่าย ๆ ดังนี้
media
│
└─── none
│ │ 2022-06_none-ชื่อไฟล์เดิม
│
└─── Bank
│ │ 2022-06_Bank-ชื่อไฟล์เดิม
│
└─── Tag
│ 2022-06_Tag-ชื่อไฟล์เดิม
โดย none คือไฟล์ที่ยังไม่ได้รับการ tag
- การค้นหาเอกสารก็ทำได้ง่าย ๆ โดยพิมพ์คำที่ต้องการค้นหาลงไปในช่อง search เลย เพราะเอกสารถูก OCR เก็บไว้หมดแล้ว ดังนั้นมันสามารถค้นไปได้ถึงคำในตัวเอกสาร ช่วยประหยัดเวลาชีวิตไปมาก (เหมือนเดิมคือภาษาไทยไม่ค่อยแม่นยำ หาได้บ้างไม่ได้บ้าง รอพัฒนาต่อไป)
- คำค้นหาสามารถบันทึกเก็บไว้ได้โดยดูที่ปุ่ม View ด้านขวาบน
- โปรแกรมนี้สามารถเพิ่ม User เพื่อเข้ามาใช้ร่วมกันได้ และมี Feature เชื่อมเมล รวมถึงอื่น ๆ อีกมากมาย ให้ลองงมดูที่เอกสาร ในส่วน Source ท้ายบทความ
หากเก็บเอกสารที่มีความลับ เพื่อความปลอดภัยใช้แค่ local พอ ไม่ควรผ่าน internet แล้วใช้ VPN เข้ามาแทน หรือจำเป็นต้องผ่าน internet ควรทำ Reverse Proxy นอกจากนี้ควรตั้งค่า Username และ Password ให้แข็งแรงพอ
Source:
https://github.com/paperless-ngx/paperless-ngx
https://paperless-ngx.readthedocs.io/en/latest/advanced_usage.html#automatic-matching


