问题
I'm creating a LotusScript web agent that reads the content of a pdf file somewhere on the network and returns it as a stream to the browser.
the agent will be called like this : getPDF?openAgent&pdfId=123456
and it should directly returns the pdf stream. (I didn't implement yet the url parameter catching)
Here's my current try, I still have an issue to convert the read buffer to the final stream
Sub Initialize
On Error GoTo errrorhandle
Dim session As New NotesSession
Dim stream As NotesStream
Set stream = session.CreateStream
Dim buffer As variant
Dim fileNum As Integer
Dim txt As String
Dim filename As String
Dim filecontent As String
filename = "C:\temp\test.PDF"
If Not stream.Open(filename,"binary") Then
MessageBox filename,, "Open failed"
Exit Sub
End If
If stream.Bytes = 0 Then
MessageBox filename,, "File has no content"
Exit Sub
End If
Print "content-type:application/pdf"
Do
buffer = stream.read(1)
Print buffer(0)
Loop Until stream.IsEOS
Call stream.Close
Exit Sub
errrorhandle :
Print "Error :" & Error & " at line : " & Erl
Exit sub
End Sub
回答1:
It is not possible to output the pdf from a stream in Lotusscript.
I suggest you attach the pdf to a notesdocument and redirect the user to attached file url and later on remove the document.
you can get a hold of the saved pdf using the following syntax http://server/database/unid/$File/myfile.pdf
回答2:
Following on Thomas Adrian response, attaching the pdf into a document in a database and then serve the link as described is the best solution.
Keep in mind that this will require the user to be authenticated, if said database has or needs restricted access.
If the web users are not authenticated users, you'll need to give at least reader access to "Anonymous" in the ACL of the hosting database for this to work... which is not always advisable if the database has other purposes.
You can however create a dedicated database just for this purpose, with unrestricted ACL access.
来源:https://stackoverflow.com/questions/28623796/streaming-a-pdf-file-to-the-browser-from-a-lotusscript-web-agent