首页 > 解决方案 > 在本地使用 pdftron webviewer 服务器时无法加载 pdf 文件

问题描述

我正在尝试将 webviewer 与 webviewer 服务器一起使用。cookie 中有需要传递的安全信息。在 docker-compose 中设置了要转发的属性。

 webviewer:
    container_name: webviewer-server
    image: pdftron/webviewer-server:latest
    ports:
      - "8090:8090"
    environment:
#      - INCLUDE_DEMO='true'
      - TRN_FORWARD_CLIENT_COOKIES='true'
      - TRN_DEBUG_MODE='true'

查看来自 webviewer 服务器的日志,信息会到达它。它接收必要的 cookie 信息以调用服务器。但是当进行 cal 时,连接被拒绝。这是错误消息。

| Creating WS connection at endpoint ...
webviewer-server | 09-Apr-2020 14:38:22.554 INFO [http-apr-8090-exec-2] com.pdftron.server.ConnectionService$WebsocketConnection.<init> Creating WS connection 31204549507251, 1 connections total
webviewer-server | 09-Apr-2020 14:38:22.804 INFO [http-apr-8090-exec-10] com.pdftron.server.BlackBoxMessenger.accessLog 31204549507251 accessing http://localhost:8080/secured/fileContent/2?downloadFile=false for page info
webviewer-server | 09-Apr-2020 14:38:22.805 INFO [http-apr-8090-exec-10] com.pdftron.server.ServerJob.<init> Starting pages: /usr/local/apache-tomcat/static_data/Image/Fetched/4XAIzCDauayBoDmSiovlh4f6tcgVwzeZ4NVrpZjKxUA=2.pdf_dir/pageinfo.json
webviewer-server | 09-Apr-2020 14:38:22.806 INFO [http-apr-8090-exec-10] com.pdftron.server.ServerJob.<init> Starting image: /usr/local/apache-tomcat/static_data/Image/Fetched/4XAIzCDauayBoDmSiovlh4f6tcgVwzeZ4NVrpZjKxUA=2.pdf_dir/pageimg0.jpg
webviewer-server | 09-Apr-2020 14:38:22.806 INFO [pool-2-thread-12] com.pdftron.server.DocReference.fetchLocalBlocking needs_fetch: http://localhost:8080/secured/fileContent/2?downloadFile=false
webviewer-server | 09-Apr-2020 14:38:22.807 INFO [pool-2-thread-7] com.pdftron.server.DocReference.fetchLocalBlocking needs_fetch: http://localhost:8080/secured/fileContent/2?downloadFile=false
webviewer-server | 09-Apr-2020 14:38:22.807 INFO [pool-2-thread-12] com.pdftron.server.DocManagement.createFetchThread Adding task http://localhost:8080/secured/fileContent/2?downloadFile=falseto fetch queue
webviewer-server | 09-Apr-2020 14:38:22.810 INFO [pool-5-thread-1] com.pdftron.server.DocManagement$DocFetchTask.doFetch Kicking off potential fetch of http://localhost:8080/secured/fileContent/2?downloadFile=false
webviewer-server | 09-Apr-2020 14:38:22.810 INFO [pool-5-thread-1] com.pdftron.server.DocManagement.constructConnection setting http://localhost:8080/secured/fileContent/2?downloadFile=false custom header Cookie: Idea-b611af61=fc8272b5-372b-48b6-a200-03b7204be819; fingerprint=e68d8c46-0988-4ac0-9154-1aac1be432b0; access_token=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJsY2VyZ2ljK2JAZXJ5Y2UuY29tIiwiY2xpZW50SWQiOiJXRUJfQVBQTElDQVRJT04iLCJ1c2VySWQiOjIsImlzcyI6ImVyeWNlLmNvbSIsImp0aSI6IjkwZDE1ZDBkLTU4ZTctNGM4YS1hMTBlLTdiYjlmZTA1Y2ZhYSIsImlhdCI6MTU4NjQ0Mjg2NSwiZXhwIjoxNTg2NDQzMTY1fQ.zFqrjvEZTwe9QC5azI1HrNG4wbxGrydGdUVli0XmRmf7wv9-KKBFeNsljluz9o7lSXPsAzdrlq5Bhzd3hKk1aw; refresh_token=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJsY2VyZ2ljK2JAZXJ5Y2UuY29tIiwiY2xpZW50SWQiOiJXRUJfQVBQTElDQVRJT04iLCJ1c2VySWQiOjIsImlzcyI6ImVyeWNlLmNvbSIsImp0aSI6IjAyYjc4MjRkLTJjMDAtNDRkNi04ZTY2LWM1OGU0NmM4ODE5YiIsImlhdCI6MTU4NjQ0Mjg2NSwiZXhwIjoxNTg2ODc0ODY1fQ.60jj88_lSH_ZngtfAt6EyzfMzZltCTNxLRYHxfGCUrEKd46O6b9bxCSS23_w4vHvecJebYOtpPgUlD0kYLeiHw; JSESSIONID=CB48A60A9DE9EAFBC94F9C4A98089EB3
webviewer-server | 09-Apr-2020 14:38:22.812 WARNING [pool-2-thread-1] com.pdftron.server.ServerJob.run During job id (/usr/local/apache-tomcat/static_data/Image/Fetched/4XAIzCDauayBoDmSiovlh4f6tcgVwzeZ4NVrpZjKxUA=2.pdf_dir/pageimg0.jpg):
webviewer-server | Exception during job run of type image
webviewer-server |  java.lang.Exception: WebViewer Server complete job (/usr/local/apache-tomcat/static_data/Image/Fetched/4XAIzCDauayBoDmSiovlh4f6tcgVwzeZ4NVrpZjKxUA=2.pdf_dir/pageimg0.jpg) failed: unable to complete fetch of http://localhost:8080/secured/fileContent/2?downloadFile=false
webviewer-server | Connection refused (Connection refused)
webviewer-server |      at com.pdftron.server.ServerJob.run(Unknown Source)
webviewer-server |      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
webviewer-server |      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
webviewer-server |      at java.lang.Thread.run(Thread.java:748)
webviewer-server | 09-Apr-2020 14:38:22.812 WARNING [pool-2-thread-4] com.pdftron.server.ServerJob.run During job id (/usr/local/apache-tomcat/static_data/Image/Fetched/4XAIzCDauayBoDmSiovlh4f6tcgVwzeZ4NVrpZjKxUA=2.pdf_dir/pageinfo.json):
webviewer-server | Exception during job run of type pages
webviewer-server |  java.lang.Exception: WebViewer Server complete job (/usr/local/apache-tomcat/static_data/Image/Fetched/4XAIzCDauayBoDmSiovlh4f6tcgVwzeZ4NVrpZjKxUA=2.pdf_dir/pageinfo.json) failed: unable to complete fetch of http://localhost:8080/secured/fileContent/2?downloadFile=false
webviewer-server | Connection refused (Connection refused)
webviewer-server |      at com.pdftron.server.ServerJob.run(Unknown Source)
webviewer-server |      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
webviewer-server |      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
webviewer-server |      at java.lang.Thread.run(Thread.java:748)
webviewer-server | Closing ws connection from endpoint: CloseReason: code [1001], reason [null]
webviewer-server | 09-Apr-2020 14:39:06.386 INFO [http-apr-8090-exec-4] com.pdftron.server.ConnectionService$Connection.onCloseImpl Closing Connection, 0 outstanding

现在“?downloadFile = false”部分有点误导,但它实际上并没有停止文件获取。所有服务都在我的本地主机上运行。它只是 webviewer 容器当然是在 docker 容器中运行的。它是用 docker-compose up 命令启动的。而且它似乎无法从容器调用 localhost 服务。日志没有显示在服务中,Webviewer 只是说连接被拒绝。

在第一次尝试时,我尝试从同一个 url 获取带有 arraybuffer 的文件,这很有效。当然,在这种情况下,现在也在 localhost 上运行的前端可以获取文件,我可以在前端显示文件。

但是,一旦我添加了服务器,服务器就无法访问该服务。这也是我在前端角度应用程序上配置文件读取的方式

const configWebViewer = {
  pdftronServer: serverUrlWithoutPort + ':8090/',
  path: '../../../../../../../../../../assets/webviewer',
  withCredentials: true,
  initialDoc: fileUrl,
}
WebViewer(configWebViewer, this.viewer.nativeElement)

现在另一件事是,出于某种原因,我在控制台中收到警告说“withCredentials”不是已知属性。

我整天都在看这个,即使我仍在尝试,我也不知道该怎么办。因此,如果我能得到任何信息,也许是我的疏忽或将不胜感激的事情。

亲切的问候

标签: angularpdftron

解决方案


对于任何可能遇到与我相同或相似情况的人。问题当然是“本地主机”。我所有的服务都在同一个 docker compose 中运行。所以他们在我认为 docker-compose 为他们创建的同一个网络上。

我将容器名称的 url 中的“localhost”更改为“myService”,它是如何在 docker-compose 文件中定义的。因此,webviewer 服务器能够通过我给它的 url 从服务中检索文件。

在部署/生产等中不应出现此问题。因为在这种情况下,您不会在 localhost 等中运行所有内容。

这在本地只是有问题,因为我正在尝试测试 PdfTron。

我还没有真正解决的另一个问题是,因为我在 docker 容器中启动了该服务,所以我无法调试该服务。当然,在某些情况下,我需要在 PdfTron 中查看文件并调试该服务。

但也许 docker-compose 创建网络的方式也许是我可以尝试的。无论哪种方式,我希望这对遇到此问题的任何人都有帮助。


推荐阅读