본문 바로가기
Today I learned

pdf 회고

by soheemon 2020. 1. 3.

모바일에서 pdf문서를 보여줘야 하는 기능이 있었는데,

PC브라우저에서 pdf를 자연스럽게 보여주고 있어서 그동안 단순히 pdf를 이미지 정도로 생각하고 접근했다가 이번에 굉장히 애를 먹었었다.

 

https://www.quora.com/Why-does-Chrome-on-Android-not-open-PDF-files-like-Chrome-on-Windows-Linux-can

 

Why does Chrome on Android not open PDF files like Chrome on Windows/Linux can?

Answer: Answering my own question. The answer is because Chrome's ability to read PDF files on desktop is because of Chrome PDF Viewer, which is a plug-in (and which shouldn't be confused with an extension). Chrome for Android doesn't support plug-ins, so

www.quora.com

 

The answer is because Chrome's ability to read PDF files on desktop is because of Chrome PDF Viewer, which is a plug-in (and which shouldn't be confused with an extension). Chrome for Android doesn't support plug-ins, so it doesn't have Chrome PDF Viewer, and because of this, it can't natively read PDF files (you'll need a separate app for PDFs). This is why the Android version doesn't have this ability, but the desktop version does.

 

PC 브라우저에서는 pdf파일을 자동으로 보여주도록 플러그인이 설치되어 있었던것..!

하지만 모바일에서는 pdf뷰어가 따로 설치되지 않았다면, 자동으로 pdf파일을 다운로드 하게 된다.  

+ IOS에서는 표시된다. 아마 브라우저에 자체 pdf 플러그인을 가지고 있나보다.

 

따라서 pdf파일을 브라우저에서 열기 위해선 pdf파일을 파싱 및 렌더링하여야 한다. 구글링하면 많이 나오는 Google Viewer! (갓 구글:D)

 

쿼리스트링으로 pdf url만 넣어주면 된다. 당연히 local에 위치하는 pdf file은 안 된다. 파일에 구글이 접근이 가능한 상태여야 한다.

https://docs.google.com/gview?embedded=true&url=${pdf url}

하지만.. 구글뷰어에도 무시무시한 문제가 있다.. 렌더링시 실패하면 실패한 이유에 따른 오류코드를 반환하지 않고 무조건 no preview 에러문구가 보이는것...

+ 해결책이 딱히 없어서 이것저것 시도해봐야 한다..

https://stackoverflow.com/questions/30461392/android-pdf-not-loading-in-browser-and-webview

 

Android PDF not loading in browser and WebView

I am trying to load PDF files in Android Webview. when i Googled it. the best answer what i found is to use Google Docs. Now What i did is append the PDF file URL at the end of this url https://docs.

stackoverflow.com

 

특히 PC에서 pdf url로 직접 접근하면 파일이 보여지지만, 구글뷰어를 태우면 보이지 않는 문제가 간혹 있다.. file by file이라 어떤 파일은 잘되는데 어떤 파일은 안됨!

이 문제는 구글쪽에 이슈가 올라왔는데도 딱히 이렇다 할 해결책이 없음... ㄸㄹㄹ..

 

https://support.google.com/docs/forum/AAAABuH1jm0ENqYuFz3kjs/?hl=en&gpf=%23!msg%2Fdocs%2FENqYuFz3kjs%2FXovGh4HhF0QJ&msgid=XovGh4HhF0QJ

 

Google Viewer displays "Apologies. There is no preview available." - Docs Editors Help

i have tried it with several browser chrome, opera,firefox, safari etc but it didn't work for me....

support.google.com

결론은 모바일 내에서 pdf뷰어를 구현해야 하는데

가장 많이 사용하는 라이브러리가.. pdf.js이다.

android webView에서도 호환이 된다고 한다.!

https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#faq-xhr

 

mozilla/pdf.js

PDF Reader in JavaScript. Contribute to mozilla/pdf.js development by creating an account on GitHub.

github.com

pdf를 파싱하기 위해서는 pdf파일 형식에 대해서도 알아야 겠지..!

https://github.com/mozilla/pdf.js/wiki/Additional-Learning-Resources

 

mozilla/pdf.js

PDF Reader in JavaScript. Contribute to mozilla/pdf.js development by creating an account on GitHub.

github.com

google 뷰어마냥 쿼리스트링에 pdf url을 받아서, pdf 렌더링 후 렌더링된 html파일을 반환해주는 컨트롤러를 만들면 좋겠당.

 

+돈이 많고.. pdf viewer를 구현할 시간이 없다면.. 솔루션을 구입하는것도 좋은 방법..! (같이 먹고 살아요 ^__^)

댓글