I’m creating my own report for one of my apps (Xojo’s report function is just not sufficient) by drawing everything into a canvas. I would like to give the user the option of saving this report to PDF. It’s simple enough to get a picture from the canvas by using the DrawInto method. But is there a way I can save the picture as a PDF w/o having to fork over money for one of the PDF classes from BKeeney or MBS?
Right now I don’t see it…
It looks like there are some MacOSLib functions but those aren’t cross platform and I need that…
I’d bet your customers could use a PNG file anywhere they could use a PDF.
That said, if you need a PDF then you could try using Toby Rush’s old PDF class.
It allows for graphic insertion, and its free.
You might need to bring some of the code up to date, but here is the link:
[quote=147889:@Jeff Tullin]I’d bet your customers could use a PNG file anywhere they could use a PDF.
That said, if you need a PDF then you could try using Toby Rush’s old PDF class.
It allows for graphic insertion, and its free.
You might need to bring some of the code up to date, but here is the link:
[quote=147889:@Jeff Tullin]I’d bet your customers could use a PNG file anywhere they could use a PDF.
That said, if you need a PDF then you could try using Toby Rush’s old PDF class.
It allows for graphic insertion, and its free.
You might need to bring some of the code up to date, but here is the link:
Unfortunately Toby’s code is pretty Mac only with a number of declares. And they are all to CarbonLib which must not be supported any more in Yosemite as the app crashes every time looking for CarbonLIb.
Looks like OmegaBundle it might be. I was considering it anyhow…
Funny, I got a compile time message spelling out something about Mach-O (or was it PEF). Anyways, it said to change CarbonLib to Carbon, I did and it ran fine, producing a pdf.
There’s only 7 or 8 declares, all to do with fonts. I don’t know what they’re doing yet but hopefully there’d be simple declare equivalents in cocoa (for longevity) and windows and linux for the cross platform. My use is just for vector graphics and will try to remove/disentangle that font class from the framework.
They are all deprecated, definitely Carbon, and probably not quite easy to replace by Windows calls, as far as I can see …
Especially since they are not even mentioned in the Apple Developer Library anymore. So it will require digging in Internet archeological sites to find out what these declares may be doing and what are the parameters they take and return.
There used to me another free open source RB PDF implementation by Asher Dunn. It eventually went commercial and the commercial version was acquired by Bob Kenney.
You may be able to find the last open source version in an internet archive somewhere. I last compiled it about a year ago and it still worked after fixing a few things - like constructors with the class name. (I’m not sure if I’m allowed to redistribute it - all I have are the classes I included in my in-house project. I am not sure I have any of the docs that came with it)
[quote=147971:@Will Shank]Funny, I got a compile time message spelling out something about Mach-O (or was it PEF). Anyways, it said to change CarbonLib to Carbon, I did and it ran fine, producing a pdf.
There’s only 7 or 8 declares, all to do with fonts. I don’t know what they’re doing yet but hopefully there’d be simple declare equivalents in cocoa (for longevity) and windows and linux for the cross platform. My use is just for vector graphics and will try to remove/disentangle that font class from the framework.[/quote]
I got it to run but in trying to convert my picture to PDF, it is SLOW.
My picture in my test example is roughly about 800 pixels wide by 3100 pixels tall. The code is literally going through every single pixel and generating a string of the RGB values using the RGBSurface methods. It is taking a LONG time to convert that picture to PDF. Seems like not an efficient way to do it. Here’s the code in question:
Function imageBitmap() As string
dim x,y,w,h as integer
dim s as string
dim r as rgbSurface
dim g as graphics
dim c as color
w=image.width
h=image.height
if image.depth>8 then
r=image.rgbSurface
for y=0 to h-1
for x=0 to w-1
c=r.pixel(x,y)
s=s+chr(c.red)+chr(c.green)+chr(c.blue)
next
next
else
g=image.graphics
for y=0 to h-1
for x=0 to w-1
c=g.pixel(x,y)
s=s+chr(c.red)+chr(c.green)+chr(c.blue)
next
next
end
return s
End Function
I’m wondering if this can be done another way like by using a memory block or something…
Instead it should append to a string array and join at the end. I haven’t really tried to decipher his code yet though, maybe in a few hours I can dig in.
[quote=148241:@Will Shank]I’m betting this is the culprit
s=s+
Instead it should append to a string array and join at the end. I haven’t really tried to decipher his code yet though, maybe in a few hours I can dig in.[/quote]
Yeah - that was it.
On OS X, it’s fairly easy to actual get a canvas to spit out a PDF copy of itself. However it’s not x-plat and your PDF is limited to the size of the canvas. With access to OS X level events it could vastly be improved.
I figured since you can easily print PDFs in OS X. But I need Xplat so…
And Toby’s PDF class is giving me junk when I try to draw pictures. His code makes sense in what he’s trying to do but I don’t know enough about PDF specs to see what is wrong… sigh.
[quote=148269:@Bob Coleman]Your time is worth way more than the cost of the bundle.
[/quote]
Yes, it is and I’m likely going to buy it regardless as there’s good stuff in there like AppWrapper and the Einghur plugins. I was thinking of buying some of those anyhow…
Yes, this looks good - like it might work. I’m having problems with Toby’s classes - I think there must be something I’m missing. I’m going to try it with this set. Looks like they only work with images saved to disk as PNG or JPEG but that’s OK. I can always save the picture to a temp file then read it back in although it always seems like a waste to do that…