There has got to be a way to display an already existing pdf file in web

Come on guys . . . . This can’t be impossible.

I can create a pdf and display it, but I can’t seem to display one that already exists

I have GraffitiPDFViewer as part of GraffitiSuite Web Edition.

in my vns fpdf project, you display a pdf in a preview window (in desktop but should be easy to port on other platforms)

I haven’t tested this so I’m only speculating, but can you not open it in a WebHTMLViewer (or target a _blank window), and use HandleURL to send it with mime type “application/pdf”?

@John_Scanlan,

You can display an existing PDF file in the HTMLViewer using HTMLViewer.LoadURL.

It works a bit differently depending on where your file lives.

If your PDF lives on a CDN (for those with 1,000s of PDFs), you would simply call (after authenticating for private CDNs).

HTMLViewer1.LoadURL("https://somedomain.somecdn.net/sample.pdf")

If you have a finite number of files you likely use the file system on your deployment platform, be that Xojo Cloud or other web server. The files are stored in SpecialFolders see SpecialFolder — Xojo documentation.

If you have had some issues to date loading existing PDF files, I expect the files are going out of scope before you can load them.

On the web page containing your HTMLViewer, create a Property (to maintain scope):

Name = PDFFile
Type = WebFile
Scope = Private

Say your Debug Build is on Mac:

  • place a PDF (sample.pdf) into your Documents folder
  • in the Opening event of your HTMLViewer add the following (or similar code):
Var documentsFolder As FolderItem = SpecialFolder.Documents

If documentsFolder = Nil Then
  MessageBox("The Documents folder is unavailable.")
  Return
End If

Var pdf As FolderItem = documentsFolder.Child("sample.pdf")

If Not pdf.Exists Then
  MessageBox("sample.pdf was not found in the Documents folder.")
  Return
End If

Try
  PDFFile = WebFile.Open(pdf)
  PDFFile.MIMEType = "application/pdf"
  PDFFile.FileName = "sample.pdf"
  PDFFile.ForceDownload = False
  
  HTMLViewer1.LoadURL(PDFFile.URL)
  
Catch e As IOException
  MessageBox("Unable to open the PDF: " + e.Message)
End Try
  • run and check if the PDF loads

I tested CDN, local (debug), and Xojo Cloud implementations.

All that said, we use/recommend GraffitiSuite and generally use GraffitiPDFViewer as it has a nicer PDF implementation (and is more feature rich), than the HTMLViewer in respect of PDF functionality.

However in answer to your original question - there is a way.

I hope that helps.

Kind regards, Andrew

sorry for my post above it is for desktop, and I did not see you asked for web.
but in your other post, I answered with my new web project for using mozilla pdf.js
it works fine with web projects, and can display url, local, pdf.

if you have the MBS Xojo DynaPDF Plugin with a Pro license, you can render the PDF pages as pictures and show them.

This way users can see them, but not get the PDF saved in the browser unless you explicitly code that.

This code matches, but it’s not showing (in debug mode):

var f as folderItem = app.helpFiles.child(“Notes - Login.pdf”)

If f <> nil And f.exists Then
try
var pdfFile as webFile = webfile.open(f)
pdfFile.mimeType = “application/pdf”
pdfFile.fileName = “Notes - Login.pdf”
pdfFile.forceDownload = false
w.d.notes.pdf.loadURL(pdfFile.URL)
w.d.notes.pdf.visible = true