svg

I got something working so I just thought I'd contribute the framework code of what I did to get there for anyone interested.

First off, I doubt this will ever work as a domino agent etc. The solution needs access to a Base64 encoder and decoder. I'm using the classes in the sun.misc.* package on sun's j2se 1.4.2_01, but these aren't distributed as a part of the supported java API. I don't think they are available as part of the domino JVM, but I haven't looked.


Step 1)
Generate the xml from a document(s) containing a pasted image in a richtext field. I'm using a notes 6.5 client to generate the xml. The code to do this looks something like:

DxlExporter exporter = session.createDxlExporter();
exporter.setConvertNotesBitmapsToGIF(true);
String dxl = exporter.exportDxl(collection);


Step 2)
Create a XSL stylesheet to process the xml. It traverses the domino items in the exported dxl to get to the binary gif file image dump. This data is base64 encoded. Now, I doubt that there is a base64 decoder available in standard XSLT so that leads us to step 3.


Step 3)
Extend the standard XSLT functionality. I'm using Apache Xalan for XSL transforming. You have to create a java class that takes the xml image data from the domino dxl and send it to your java class. My java class does the following:
- get input from caller
- base64 decode the input
- transform the result to png
- base64 encode the result
- return the encoded result to the XSLT caller
This actually isn't as hard as it may seem. It's looks something like this (comments welcome):

------------

String s;

BASE64Encoder encoder = new BASE64Encoder();
BASE64Decoder decoder = new BASE64Decoder();

ByteArrayInputStream input = new ByteArrayInputStream(s.getBytes());
ByteArrayOutputStream output = new ByteArrayOutputStream();

ByteArrayOutputStream decoded = new ByteArrayOutputStream();
decoder.decodeBuffer(input, decoded);
input.close();

BufferedImage im = ImageIO.read(new ByteArrayInputStream(decoded.toByteArray()));
ByteArrayOutputStream png = new ByteArrayOutputStream();
ImageIO.write(im, "png", png);

encoder.encode(new ByteArrayInputStream(png.toByteArray()), output);

return output.toString();

------------

Extending Apache Xalan is easier than I initially thought, but you may want to try it with something simpler before attempting this. You also have to set a few things in your XSL so that the transformer can find your java code. You also have to make sure the class is available for your JVM. I did this by packaging the class in a jar file a putting it in my jvm/lib/ext directory so it is available to Xalan-J.


Step 4)
Your output from of the transform must be using XSL-FO if you want to use FOP to create a pdf.
I used the fo:instream-foreign-object when adding the resulting image dump back to the xml. It looks something like this:

<fo:instream-foreign-object>
<svg:svg width="{$width}" height="{$height}">
<svg:image width="{$width}" height="{$height}">
<xsl:attribute name="xlink:href">
<xsl:value-of select="concat('data:image/png;base64,', mystuff:png(.))"/>
</xsl:attribute>
</svg:image>
</svg:svg>
</fo:instream-foreign-object>

Is there a better way of doing this than using the xlink:href attribute? Comments welcome!
Anyway, here my call to the XSLT extension is mystuff:png(). You set this up at the top of you stylesheet (see extension-element-prefixes, Apache Xalan docs).


Step 5)
Transform the resulting xml (with included image data) using Apache FOP to create a pdf file.


In summary, to do this you need to have some knowledge of:

java
xml namespaces
xslt
xsl-fo
some svg

Good luck!



评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值