鄒小城
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Apache Tika Server 介紹與安裝 ## Apache Tika Server 簡介 Apache Tika Server 是一個基於 Apache Tika 的獨立服務,它提供了一種方便的方式來檢索和提取各種文件的內容和元數據。無論是文本文檔、電子表格、演示文稿、圖像、音頻還是視頻,Tika Server 都可以處理各種類型的文件。它是 Apache Tika 的一個功能強大的子項目,可以幫助開發人員在他們的應用程序中進行文本分析和信息擷取。 Tika Server 採用了客戶端-服務器架構,可以通過 HTTP 協議接收請求並返回處理結果。這使得 Tika Server 可以與不同的客戶端應用程序進行交互,包括 Web 應用程序、命令行工具或其他服務。它的設計目標是提供一個簡單易用的介面,使開發人員能夠輕鬆地將 Tika 的功能集成到他們的應用程序中。 Tika Server 提供了各種功能和服務,包括文本提取、元數據擷取和語言檢測。它可以將輸入文件轉換為純文本,並提取出其中的文字內容、元數據(如作者、標題、創建日期等)以及結構化的信息(如表格、列表等)。此外,Tika Server 還支持自然語言處理功能,例如斷詞、詞性標註和命名實體識別,這些功能可以幫助開發人員進行更高級的文本分析。 ## Windwos 環境安裝 * 安裝 Java Runtime , 這邊我選擇 [Microsoft 提供的 OpenJDK 17](https://learn.microsoft.com/zh-tw/java/openjdk/download),Oracle 提供的那個之前有些授權問題。 * 下載 Apache Tika Server,就一個 [tika-server-standard-2.7.0.jar](https://www.apache.org/dyn/closer.lua/tika/2.7.0/tika-server-standard-2.7.0.jar) 而已。 * 下載 [Apache Commons Daemon binary distributions for Windows](https://downloads.apache.org/commons/daemon/binaries/windows/),**commons-daemon-1.3.3-bin-windows.zip** 。 * 建立資料夾 `D:\TikaServer` jar 跟 zip 解壓丟進去,**prunsrv.exe** 改用 amd64 目錄下面那一個,因為佈署在 x64 的環境下。 * 完成上述動作後資料夾下只要留下,**prunsrv.exe**、**tika-server-standard-2.7.0.jar**、**prunmgr.exe** 三個檔案就可以了。 * 新增 'InstallTikaServer.bat' 檔內容約略如下,建立好後執行 BAT 就可以 Tika Server 註冊進 Windwos 服務。 bat檔中有一段 `++StartParams=-host#*` 設定服務 Listen 所有的主機可用的IP,不然預設只會在 127.0.0.1:9998 上運作。 ```batch REM 放置檔案的目錄 SET BasePath=D:\TikaServer REM 根據安裝 Java 版本不同路徑可能會有所差異 SET JvmDllPath="C:\Program Files\Microsoft\jdk-17.0.7.7-hotspot\bin\server\jvm.dll" prunsrv.exe //IS//TikaServer ^ --DisplayName="Tika Server" ^ --Description="Tika Server" ^ --Install="%BasePath%\prunsrv.exe" ^ --Startup=auto ^ --LogPath="%BasePath%\Logs" ^ --Jvm=%JvmDllPath% ^ --Classpath="%BasePath%\tika-server-standard-2.7.0.jar" ^ --StartMode=jvm ^ --StartClass=org.apache.tika.server.core.TikaServerCli ^ --StartMethod=main ^ --StopMode=jvm ^ --StopClass=org.apache.tika.server.core.TikaServerCli ^ --StopMethod=stop ^ ++StartParams=-host#* ``` * 新增 'RemoveTikaServer.bat' 檔內容約略如下,這檔案是要把 Tika Server 從服務移除時才需要執行。 ```batch prunsrv.exe //DS//TikaServer ``` * 將 **prunmgr.exe** 更名為 **TikaServer.exe**,這個名字是根據上面註冊服務時使用的名字決定。 * 後續透過 **TikaServer.exe** 就可以調整服務參數,或重啟服務。 ## 使用範例 * 透過 C# 呼叫 TikaServer 取得檔案中的文字資訊。 ```csharp var filePath = @"D:\TestData\xxxx.docx"; var fileStream = File.OpenRead(filePath); var content = new StreamContent(fileStream); var client = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Put, "http://127.0.0.1:9998/tika"); request.Content = content; request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("text/plain")); var response = await client.SendAsync(request); var responseContent = await response.Content.ReadAsStringAsync(); Console.WriteLine(responseContent); ``` * 透過 curl 呼叫 TikaServer 取得檔案中的文字資訊。 ```bash # 回傳 html 格式的本文 curl -s -T 資通安全法說明.pdf http://127.0.0.1:9998/tika # 回傳純文字格式的本文 curl -s -T 資通安全法說明.pdf http://127.0.0.1:9998/tika -H "Accept: text/plain" # 回傳 json 格式的資料,這種格式資料會在豐富一點,除了一個欄位是 html 本文外 ,還有一些其他的檔案資訊會一併取得 curl -s -T 資通安全法說明.pdf http://127.0.0.1:9998/tika -H "Accept: application/json" # 單純判讀檔案類型 curl -s -T 資通安全法說明.pdf http://127.0.0.1:9998/detect/stream ``` ## 補充說明 * Tika 可以讀取的文件總類非常多 doc、docx、ppt、pptx、pdf、xls、xlsx、ods、odt 基本常見的應該都有支援。 * Tika Server 預設只 Listen 127.0.0.1:9998,如果要改成 0.0.0.0:9998 要注意安全性問題,這個 API 沒有可以設定授權驗證的功能。 * Tika 除了讀取本文外,也可以拿來做檔案類型的判讀。(不是單純看副檔名那種) * Linux 環境安裝的話直接用 docker compose 佈署簡單乾淨不黏牙。 ## 網路參考資料 * [Apache Tika 官方網站](https://tika.apache.org/) * [Apache Commons Daemon](https://commons.apache.org/proper/commons-daemon/binaries.html) * [Apache Commons Daemon binary distributions for Windows](https://downloads.apache.org/commons/daemon/binaries/windows/) * [Apache Tika實戰](https://iter01.com/524316.html)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully