1

I have a page that is dedicated to the Standard Operating Procedures (SOP). I want this page to show the the SOP in the page with a download button above it (and for Admin an upload button). Basically I want the user to be able to read the SOP without having to download it. I have the buttons sorted and I almost have the display set, but the format is off.

The admin can upload a PDF of the current SOP. That file then gets stored and overwrites that last upload. I tried using cffile but it was unreadable no matter what charset I tried to use. Currently I am taking the file and extracting it as a .txt, then using cffile to read it to a variable that I then output to the screen. It sort of works, but the formatting is all wrong.

I know I can use cfcontent and just have the page be the PDF, but I'd rather not have to mess with adding a new page just for admins to upload new SOP files. (The way the site is built it would have to be a new page)

<cfpdf
action="extracttext"
source="D:\file_path\SOP.pdf"
overwrite="true"
honourspaces="true"
type="string"
useStructure="true"
destination="D:\file_path\SOP.txt">

<cffile
action="read"
file="D:\file_path\SOP.txt"
variable="dcnSOP">

...


<cfoutput>#dcnSOP#</cfoutput>

Basically I'm getting a block of unformatted (as in spaces and new paragraphs) text. It's the text I want, and It's on the page where I want it. But it looks terrible. It seems to just be getting rid of any new line characters and just presenting the text in a blob. Is there a better way of doing this without just having the whole page be the PDF using cfcontent?

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
Clark
  • 63
  • 8
  • 2
    In order to display a PDF document within an HTML page you need to either embed the content or iframe the content, you can't mix both (browsers can't do that). This has already been answered here - https://stackoverflow.com/q/17784037/1636917 or https://stackoverflow.com/q/291813/1636917 – Miguel-F Feb 12 '19 at 19:02
  • 1
    "ExtractText" does exactly that - text only. No formatting or html is supported. Though there are external tools for converting pdf's to html, the task is not trivial. The simplest approach is what @Miguel-F suggested - embed the pdf file in the cfm/html page or use an iframe. – SOS Feb 12 '19 at 21:45
  • @Miguel-F and Ageax thanks for the help. That link gave me what I needed to know. Sorry for the reposted question, I guess I missed it when I was searching for the answer. – Clark Feb 13 '19 at 16:25

1 Answers1

3

Thanks to @Miguel-F and @Ageax for the suggestions and leading me to a question I missed on here when I was searching for the answer.

<embed src="\file_path\SOP.pdf" width="800px" height="2100px"/>

This works with every browser but Chrome (our clients will not be using mobile browsers). I know you can use Google's PDF reader to get around this, if anyone is interested in that here is an example of that given by @Script47 here:

 <embed src="https://drive.google.com/viewerng/
viewer?embedded=true&url=http://example.com/the.pdf" width="500" height="375">
Clark
  • 63
  • 8
  • 1. I am surprised the that backward slashes work. 2. It this worked, you can mark this as the accepted answer – James A Mohler Feb 14 '19 at 03:00
  • Glad the info helped you and thanks for coming back and providing your answer. – Miguel-F Feb 14 '19 at 16:40
  • 1
    @James A Mohler I had to wait a day to accept it as the answer. But this did work. And I had the file path using "/" but that threw errors. So I switched them. I guess its on a Windows server? I'm new to this project. – Clark Feb 14 '19 at 17:24