Thread: [Java-gnome-developer] Cairo - embedding images in pdfs
Brought to you by:
afcowie
From: William T. <wil...@gm...> - 2010-02-05 22:57:47
|
Dear all Thanks for the great libraries. They're absolutely the best way of producing PDFs I've found. I've got what I expect is quite a simple problem, but I've spent hours trawling apis and I can't figure it out. I'd just like to embed a large image in a pdf. The following crashes the JVM: Pixbuf pb = new Pixbuf("/tmp/logo.png"); Could anyone give me some pointers please? I'm hoping to produce PDFs like these: http://www.map.ox.ac.uk/data/ Which I created with some hacky Python scripts + ArcGIS, The Gnome / Cairo Java bindings would be a much cleaner solution. Thanks and regards, Will Temperley Malaria Atlas Project University of Oxford http://www.map.ox.ac.uk/ |
From: Andrew C. <an...@op...> - 2010-02-05 23:34:25
|
On Fri, 2010-02-05 at 22:57 +0000, William Temperley wrote: > Thanks for the great libraries. They're absolutely the best way of > producing PDFs I've found. Well, there are glitches :) notably the fact that Cairo itself doesn't quite do everything we need it to. Adrian Johnson wants to create a PDF specific library that uses Cairo for its drawing but that knows about the rest of the PDF spec (as there are a number of PDF want-to-haves that just don't belong in Cairo, and won't get there, unfortunately). Needless to say that's a year+ away, but I'm hoping to support him as he goes. That said, Cairo 1.9 is a *significant* improvement over 1.8 in a lotof areas we touch using PdfSurface. > I've got what I expect is quite a simple problem, but I've spent hours > trawling apis and I can't figure it out. I'd just like to embed a > large image in a pdf. > So that's actually one of the problems; right now Cairo converts it to a bitmap or so, rather than just embedding the damn (ie) jpg. That's fixed in 1.10 by the addition of a setMimeType() API. But we don't have that yet. > The following crashes the JVM: But regardless, THAT shouldn't happen. Especially not her > pb = new Pixbuf("/tmp/logo.png"); > Could anyone give me some pointers please? So, if you could post on a server or pastebin somewhere the VM crash dump you get from the JVM, that might help. It might help people on the list if they could see some code, too. Hard to imagine what context you have that led to a crash there. AfC Sydney |
From: William T. <wil...@gm...> - 2010-02-06 10:52:51
|
On 5 February 2010 23:34, Andrew Cowie <an...@op...> wrote: > On Fri, 2010-02-05 at 22:57 +0000, William Temperley wrote: ><snip> > > >> The following crashes the JVM: > > But regardless, THAT shouldn't happen. Especially not her >> pb = new Pixbuf("/tmp/logo.png"); > >> Could anyone give me some pointers please? > > So, if you could post on a server or pastebin somewhere the VM crash > dump you get from the JVM, that might help. > > It might help people on the list if they could see some code, too. Hard > to imagine what context you have that led to a crash there. I've posted the VM crash dump here: http://pastebin.com/m7587cc22 I'm on a fairly standard Ubuntu Karmic AMD64 install - using Java-gnome-4.0.14. It just crashed when creating a pixbuf from a file. I was just doing a very simple trial of a few features: public class CairoTest { static PdfSurface pdf; public static void main(String[] args) throws IOException { pdf = new PdfSurface("/tmp/javacairo.pdf", 500, 707); final Pattern linear, radial; Context cr = new Context(pdf); cr.setSource(1.0, 0.1, 0.0, 1.0); cr.moveTo(10, 40); cr.lineTo(120, 145); cr.stroke(); //Crashes here Pixbuf pb = new Pixbuf("/tmp/logo.gif"); cr.setSource(pb, 10, 10); cr.paint(); Cheers Will |
From: Andrew C. <an...@op...> - 2010-02-09 05:01:24
|
On Sat, 2010-02-06 at 10:52 +0000, William Temperley wrote: > I've posted the VM crash dump here: > http://pastebin.com/m7587cc22 The relevant part is: Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) C [libpixbufloader-gif.so+0x1b76] Java frames: (J=compiled Java code, j=interpreted, Vv=VM code) j org.gnome.gdk.GdkPixbuf.gdk_pixbuf_new_from_file(Ljava/lang/String;)J+0 j org.gnome.gdk.GdkPixbuf.createPixbufFromFile(Ljava/lang/String;)J+21 j org.gnome.gdk.Pixbuf.checkPixbufFromFile(Ljava/lang/String;)J+44 j org.gnome.gdk.Pixbuf.<init>(Ljava/lang/String;)V+2 j uk.ac.ox.map.carto.canvas.CairoTest.main([Ljava/lang/String;)V+69 v ~StubRoutines::call_stub which is nothing unusual at all. > I'm on a fairly standard Ubuntu Karmic AMD64 install - using Java-gnome-4.0.14. Sure, that's fine. (java-gnome from the PPA, I assume?) > It just crashed when creating a pixbuf from a file. I was just doing a > very simple trial of a few features: > public class CairoTest { > public static void main(String[] args) throws IOException { You didn't call Gtk.init() first. That's obligatory. http://java-gnome.sourceforge.net/4.0/doc/api/org/gnome/gtk/Gtk.html#init(java.lang.String[]) Annoyingly, not having done so should have resulted in an Exception being thrown when you tried to use anything else in java-gnome. We used to have some great code that would check you'd initialized properly. Apparently we messed that up when we changed the initialization last cycle to deal with the GLib g_set_prgname() bug. http://article.gmane.org/gmane.comp.gnome.bindings.java.devel/1425 refers. Not sure why we aren't getting an Exception anymore. Someone will need to fix that. Anyway, call Gtk.init() and you're on your way. AfC Sydney |
From: William T. <wil...@gm...> - 2010-02-09 10:38:47
|
On 9 February 2010 05:01, Andrew Cowie <an...@op...> wrote: > On Sat, 2010-02-06 at 10:52 +0000, William Temperley wrote: > >> I've posted the VM crash dump here: >> http://pastebin.com/m7587cc22 > > The relevant part is: > > Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) > C [libpixbufloader-gif.so+0x1b76] > > Java frames: (J=compiled Java code, j=interpreted, Vv=VM code) > j org.gnome.gdk.GdkPixbuf.gdk_pixbuf_new_from_file(Ljava/lang/String;)J+0 > j org.gnome.gdk.GdkPixbuf.createPixbufFromFile(Ljava/lang/String;)J+21 > j org.gnome.gdk.Pixbuf.checkPixbufFromFile(Ljava/lang/String;)J+44 > j org.gnome.gdk.Pixbuf.<init>(Ljava/lang/String;)V+2 > j uk.ac.ox.map.carto.canvas.CairoTest.main([Ljava/lang/String;)V+69 > v ~StubRoutines::call_stub > > which is nothing unusual at all. > > >> I'm on a fairly standard Ubuntu Karmic AMD64 install - using Java-gnome-4.0.14. > > Sure, that's fine. > > (java-gnome from the PPA, I assume?) > No - built from source. >> It just crashed when creating a pixbuf from a file. I was just doing a >> very simple trial of a few features: > > >> public class CairoTest { >> public static void main(String[] args) throws IOException { > > You didn't call Gtk.init() first. That's obligatory. > http://java-gnome.sourceforge.net/4.0/doc/api/org/gnome/gtk/Gtk.html#init(java.lang.String[]) > > Annoyingly, not having done so should have resulted in an Exception > being thrown when you tried to use anything else in java-gnome. > > We used to have some great code that would check you'd initialized > properly. Apparently we messed that up when we changed the > initialization last cycle to deal with the GLib g_set_prgname() bug. > http://article.gmane.org/gmane.comp.gnome.bindings.java.devel/1425 > refers. Not sure why we aren't getting an Exception anymore. Someone > will need to fix that. > > Anyway, call Gtk.init() and you're on your way. > > AfC > Sydney > Thanks Andrew. Glad it's a simple fix - apologies for the noise. Will |
From: Andrew C. <an...@op...> - 2010-02-10 04:13:23
|
On Tue, 2010-02-09 at 10:38 +0000, William Temperley wrote: > Thanks Andrew. Glad it's a simple fix - apologies for the noise. Not at all. I looked into it; if the first thing you'd done had been b = new Button(); it would have bailed out with the Exception I mentioned. Alas. We'll come up with something deeper, I imagine. AfC Sydney |