[haXe] pdf generation with alivepdf & haxe
Glen Blanchard
blanchard.glen+haxe at gmail.com
Tue Dec 4 02:11:33 CET 2007
Just looking at it quickly, if you are running swhx then this is
fairly easy to do.
Just call a flash method from neko that creates your pdf using
org.alivepdf.pdf.PDF class that returns the results of
savePDF(Method.LOCAL)
Then with the bytearray returned you should be able to write it using
the neko.io classes you mentioned.
Of course the better way would be to convert all the .as files to .hx
files and make it a library that everybody could use even just from
neko without swhx, but that would be a lot of work.
example psudeo code
Flash:
import org.alivepdf.pdf.PDF;
import org.alivepdf.saving.Method;
public function generatePDF():ByteArray {
var pdf:PDF = new PDF();
// add pages/content etc...
return pdf.savePDF(Method.local);
}
Haxe:
// create window/remoting server/flash instance
var pdf = flash.generatePDF.call([]);
var output = neko.io.File.write("mypdf.pdf", true);
output.writeBytes(pdf.join(""));
output.close();
The only problems you may run into is converting the ByteArray to a
string for writeBytes.
Either do it in haxe using above method of pdf.join("") or do in in
flash using ByteArray.toString();
Hope it helps
Glen.
On Dec 4, 2007 10:30 AM, Jan Viehweger <forum at jan-viehweger.de> wrote:
> hello list, hello nicolas!
>
> this is my very first post to the list - and of coure not the last one,
> cause haxe rocks and i'm trying find out the whole power of this amazing
> language.
>
> untill now i was one of theese stupid zinc users who spend a lot of
> money for a buggy tools. i was very frustrated about the poor database
> features and the missing commandline features which is a must have in a
> productive workflow. while googeling for some custom sqlite extension
> for zinc i stumbled over haxe, which supports sqlite by default - and of
> course "for free"! yes man - this is i was looking for!!! - why nowbody
> told me before?!
>
> now to the point:
> in many of my applications (of course flash/flex/haxe) i need the
> possibility to dynamicaly generate pdf's.
> until now i'didnt find a proper solution, cause haxe (still) does not
> support this feature (correct if i'm wrong).
>
> so my first idea was:
> using the cli version of php in combination with the fpdf class. ok,
> this worked somehow but distributing the whole php package was'nt that
> elegant.
>
> second idea:
> using a very cool tool i found called BAMBALAM. this is tiny little
> programm for wrapping php files in a single exe so you can use it as a
> standalone programm. yes - this was cool for some day's, and it worked.
> but one thing disappoints me: now i had 3 different languages to handel:
> actionscript, haxe and php ...
>
> third, and last idea:
> yesterday i found a very amazing project called "ALIVEPDF" on
> bytearray.org. alivepdf is an actionscript 3 open-source pdf library.
> alivepdf is based on fpdf - which is a good old friend of mine :+).
> alivepdf targets to types of pdf generation: LOCAL and REMOTE. the local
> way is done by adobe air. the remote one by a php script.
> its very easy to create pdf with alivepdf as you can see in
> videotutorials on the projects website (www.alivepdf.org). the cool
> thing is, that you write your whole pdfcode in as3, and for grafix you
> can use the whole drawing api too!!!
>
> so whats the problem now?
> as i mentioned, saving pdf files local is done by adobe air. but i dont
> want to use air - couse i'm a haxe guy :+). i saw in the first
> videotorial
> (http://www.alivepdf.org/wp-content/tutorials/alivepdf-tutorial-getting-started.swf)
>
> that the whole pdfcode is stored in a flash bytearray which is then
> written into file by an air method. i ask myself if haxe could do this
> file save stuff to. in the haxe/neko api i found the neko.io class which
> also has a "writeBytes" method. but as i'm a very first beginner in haxe
> i dont know how to get started with that feature.
>
> here my question: could someone help me ore write a little example which
> produces a simple hello world pdf with alivepdf & haxe?
> i think this could be very usefull for the whole haxe comunity cause in
> my opinion this is the first proper solution for generating pdf in haxe.
> it would also be possible to make the alivepdf class available as an
> haxe lib ...
>
> so this for now - sorry for my long post an my bad english.
> hopefully some is interessted and expirienced enough to help me (and the
> community too)
>
> bye janosch,
>
>
> ---------- Forwarded message ----------
> From: "Dipl. Des. Jan Viehweger" <mail at jan-viehweger.de>
> To: haxe at lists.motion-twin.com
> Date: Tue, 04 Dec 2007 01:27:37 +0100
> Subject: pdf generation with alivepdf & haxe
> hello list, hello nicolas!
>
> this is my very first post to the list - and of coure not the last one,
> cause haxe rocks and i'm trying find out the whole power of this amazing
> language.
>
> untill now i was one of theese stupid zinc users who spend a lot of
> money for a buggy tools. i was very frustrated about the poor database
> features and the missing commandline features which is a must have in a
> productive workflow. while googeling for some custom sqlite extension
> for zinc i stumbled over haxe, which supports sqlite by default - and of
> course "for free"! yes man - this is i was looking for!!! - why nowbody
> told me before?!
>
> now to the point:
> in many of my applications (of course flash/flex/haxe) i need the
> possibility to dynamicaly generate pdf's.
> until now i'didnt find a proper solution, cause haxe (still) does not
> support this feature (correct if i'm wrong).
>
> so my first idea was:
> using the cli version of php in combination with the fpdf class. ok,
> this worked somehow but distributing the whole php package was'nt that
> elegant.
>
> second idea:
> using a very cool tool i found called BAMBALAM. this is tiny little
> programm for wrapping php files in a single exe so you can use it as a
> standalone programm. yes - this was cool for some day's, and it worked.
> but one thing disappoints me: now i had 3 different languages to handel:
> actionscript, haxe and php ...
>
> third, and last idea:
> yesterday i found a very amazing project called "ALIVEPDF" on
> bytearray.org. alivepdf is an actionscript 3 open-source pdf library.
> alivepdf is based on fpdf - which is a good old friend of mine :+).
> alivepdf targets to types of pdf generation: LOCAL and REMOTE. the local
> way is done by adobe air. the remote one by a php script.
> its very easy to create pdf with alivepdf as you can see in
> videotutorials on the projects website (www.alivepdf.org). the cool
> thing is, that you write your whole pdfcode in as3, and for grafix you
> can use the whole drawing api too!!!
>
> so whats the problem now?
> as i mentioned, saving pdf files local is done by adobe air. but i dont
> want to use air - couse i'm a haxe guy :+). i saw in the first
> videotorial
> (http://www.alivepdf.org/wp-content/tutorials/alivepdf-tutorial-getting-started.swf)
>
> that the whole pdfcode is stored in a flash bytearray which is then
> written into file by an air method. i ask myself if haxe could do this
> file save stuff to. in the haxe/neko api i found the neko.io class which
> also has a "writeBytes" method. but as i'm a very first beginner in haxe
> i dont know how to get started with that feature.
>
> here my question: could someone help me ore write a little example which
> produces a simple hello world pdf with alivepdf & haxe?
> i think this could be very usefull for the whole haxe comunity cause in
> my opinion this is the first proper solution for generating pdf in haxe.
> it would also be possible to make the alivepdf class available as an
> haxe lib ...
>
> so this for now - sorry for my long post an my bad english.
> hopefully some is interessted and expirienced enough to help me (and the
> community too)
>
> bye janosch,
>
>
>
>
>
> --
> haXe - an open source web programming language
> http://haxe.org
>
More information about the Haxe
mailing list