I’ve been using fpdf for writing to a pdf in my desktop version. I’m creating a web version.
Any ideas for writing to PDF?
I’ve been using fpdf for writing to a pdf in my desktop version. I’m creating a web version.
Any ideas for writing to PDF?
You could use our MBS DynaPDF Plugin to create a PDF and provide it as download.
There’s also a fpdf-PHP-Lib (Class). But DynaPDF may be more convinient
Why can’t you stick with fpdf? I use it for my web apps.
P Lim … apparently I’ve got to change something. I’m getting an error in the method Output. In the last line I get a “Item does not exist” error. Ideas?
Dim f As FolderItem
Dim t as BinaryStream
//Output PDF to some destination
//Finish document if necessary
if(me.state < 3) then me.Close()
//Normalize parameters
if(name = “”) then
name=“doc.pdf”
dest=“F”
end if
//Save to local file
f = GetFolderItem(name)
t = f.CreateBinaryFile("pdf")
t.Write me.buffer
t.close
f.Launch
so … I’ve removed fpdf from my program and inserted method that just has Xojo’s example in it:
Dim pdfFile As FolderItem
pdfFile = GetOpenFolderItem("")
If pdfFile <> Nil Then
pdfFile.Launch
End If
I still the same error. actually both pdfFile = GetOpenFolderItem("") and pdfFile.Launch get the This item does not exist error while compiling.
[quote=24746:@John Scanlan]so … I’ve removed fpdf from my program and inserted method that just has Xojo’s example in it:
Dim pdfFile As FolderItem
pdfFile = GetOpenFolderItem("")
If pdfFile <> Nil Then
pdfFile.Launch
End If
I still the same error. actually both pdfFile = GetOpenFolderItem("") and pdfFile.Launch get the This item does not exist error while compiling.[/quote]
Launch does not exist which makes sense
If it did it would be launching the file on the web server - not in a users browser
Thanks … how do I get it opened on the user’s browser/computer?
You need either a URL that the browser can access OR some way to send it to them
But I’m really the wrong guy to ask here
I’ve moved on to testing this (from the language reference):
dim textFile as webFile
TextFile = New WebFile // TextFile is a property of the web page
TextFile.MimeType = “text/plain”
TextFile.ForceDownload = True // If False, the browser may try to display the file instead of download it
TextFile.FileName = “TextFile.txt”
TextFile.Data = “Hello, world!”
ShowURL(TextFile.URL) // This causes the file to be downloaded
but I’m getting this “http://127.0.0.1:8080/1183181146821BFF3B0461DF1F161E18/files/{2217-4077-8582-5366-3342}/TextFile.txt” with the error “The webpage cannot be found”
Right. Textfile goes out of scope before the browser has a chance to retrieve it. Make it a property of the webpage.
I got the above to work by creating a property called textFile as webFile and deleted the dim textFile as webFile.
Now I’ve got a weird phenomenon going on. I’m trying to edit the Output method of fpdf (I’ve done it before in realsoftware 2012r2), but now no matter what I do, the old programming keeps coming back. I edit, save, close the IDE, go to appData-Roaming-Xojo2013r2, delete the folder and when I reopen the file in Xojo all the old programming is back again
what the bloody hell ???@???
Not sure about the problem with editing the Output method, but to create and have the client download the file as PDF, this is what I use:
Sub DownloadPDF(filename as string, pdf_data as String)
Dim s as Session = Session
If s.downloadfile = Nil Then
s.downloadfile = New webfile
s.downloadfile.mimetype = "application/pdf"
#If targetmacos=True Then
s.downloadfile.forcedownload = False
#Else
s.downloadfile.forcedownload = True
#EndIf
s.downloadfile.filename = filename
s.downloadfile.data = pdf_data
s.downloadfile.ondownloaded = WeakAddressOf s.filedownloaded
End
ShowURL(s.downloadfile.url)
End Sub
so you’ve created pdf_data elsewhere. I’m struggling to get the buffer to work and to turn it into a pdf.
Thanks …
ok … so i’m just stuck on creating the pdf_data with fpdf and then getting into a webfile I can display.
IN PDF = new fpdf, in pdf.output I get the two lines I entered plus coding in pages(1):
2 J
0.57 w
BT /F1 12.00 Tf ET
1.00 w
BT 50.00 742.00 Td (Hello World) Tj ET
BT 50.00 742.00 Td (Goodbye World) Tj ET
THE PROBLEM is that according to fpdf I need to convert it to a binary stream and write that binary stream to the buffer (from fpdf.output):
case “F”
f = GetFolderItem(name)
t = f.CreateBinaryFile(“pdf”)
t.Write me.buffer
t.close
I’VE GOT:
(session.f is defined as a webfile)
if(me.state < 3) then me.Close()
session.f = new webFile
session.f.MIMEType = “application/pdf”
session.f.filename = fileName
session.f.forceDownload = true
dim t as binaryStream
session.f.CreateBinaryFile(“pdf”)
t.Write session.pdf.buffer
t.close
session.showURL(session.f.URL)
THE ISSUE is that session.f.CreateBinaryFile(“pdf”) gives me a This item does not exist error. This is all I need to deploy my rather complex web app, so please …
Hi John,
This is an example I have:
Dim pdf As fpdf
Dim pdf_file_data As String
pdf = New FPDF("P","mm","A4")
pdf.SetCompression(True)
pdf.AddPage
pdf.SetAutoPageBreak(True)
pdf.SetLeftMargin(20)
pdf.SetRightMargin(20)
pdf.SetFont("Arial","", 7)
pdf.SetXY(20,20)
pdf.Cell(0,0,"",0,1,"L")
pdf.Cell(0,4,"Hello World",0,1,"L")
pdf_file_data = pdf.Output(Me.Name + ".pdf")
// myWebFile is a property of the webpage (or session) so that it doesn't go outof context
If myWebFile = Nil Then
myWebFile = New webfile
myWebFile.mimetype = "application/pdf"
myWebFile.filename = "test.pdf"
myWebFile.data = pdf_file_data
myWebFile.ondownloaded = WeakAddressOf FileDownloaded // FileDownloaded method sets myWebFile to NIL
End
ShowURL(myWebFile.url)
I used exactly your example. myWebFile is a webFile property of the webpage. It tried to create a pdf, but I got this error from Adobe Acrobat:
File does not begin with ‘%PDF-’,
Local\EWH + (random characters)
what is in your fpdf.output method?
You can download my project file here:
https://dl.dropboxusercontent.com/u/15622870/pdf_with_fpdf.rbp
The fpdf and zlib files are from here: https://github.com/roblthegreat/rsfpdf
Thanks tons Patrick. That did it. Most recently I was off by half a line and your gave me the correct line.
Now my program will work !!!