I found a couple of examples by the iText author that use the Graphics2D API and the Apache Batik library to draw the SVG in a PDF.
http://itextpdf.com/examples/iia.php?id=269
http://itextpdf.com/examples/iia.php?id=263
For my purposes, I needed to take a string of SVG and draw that in a PDF at a certain size and location while maintaining the vector nature of the p_w_picpath (no rasterization).
I wanted to bypass the SVG file that seems prevalent in the SAXSVGDocumentFactory.createSVGDocument() functions. I found the following post helpful for using a SVG text string instead of a flat file.
You have to create a StringReader from your String and pass that to the SAXSVGDocumentFactory#createDocument(String, Reader) method. The URI that you pass as the first parameter as a String will be the base document URI of the SVG document. This should only be important if your SVG references any external files.
Best regards,
Daniel
Java Source derived from the iText examples:
Java Source derived from the iText examples:
// SVG as a text string.String svg ="";// Create the PDF document.// rootPath is the present working directory path.Document document =newDocument();PdfWriter writer =PdfWriter.getInstance(document,newFileOutputStream(newFile(rootPath +"svg.pdf")));document.open();// Add paragraphs to the document...document.add(newParagraph("Paragraph 1"));document.add(newParagraph(" "));// Boilerplate for drawing the SVG to the PDF.String parser =XMLResourceDescriptor.getXMLParserClassName();SAXSVGDocumentFactory factory =newSAXSVGDocumentFactory(parser);UserAgent userAgent =newUserAgentAdapter();DocumentLoader loader =newDocumentLoader(userAgent);BridgeContext ctx =newBridgeContext(userAgent, loader);ctx.setDynamicState(BridgeContext.DYNAMIC);GVTBuilder builder =newGVTBuilder();PdfContentByte cb = writer.getDirectContent();// Parse the SVG and draw it to the PDF.Graphics2D g2d =newPdfGraphics2D(cb,725,400);SVGDocument chart = factory.createSVGDocument(rootPath,newStringReader(svg));GraphicsNode chartGfx = builder.build(ctx, chart);chartGfx.paint(g2d);g2d.dispose();// Add paragraphs to the document...document.add(newParagraph("Paragraph 2"));document.add(newParagraph(" "));document.close();
Note that this will draw a SVG to the PDF you are working on. The SVG appears as a floating layer above text. I'm still working on moving/scaling it and having it rest inline with text, but hopefully that is outside the immediate scope of the question.
Hope this was able to help.
Cheers
EDIT: I was able to implement my svg as an inline object using the following. The commented lines are for adding a quick border to check positioning.
// Create your graphics here - draw on the g2 Graphics object
g2.dispose();
cb.addTemplate(tp,0,100);// 0, 100 = x,y positioning of graphics in PDF page
document.close();
官方例子:
/** * Reads an SVG Image file into an com.itextpdf.text.Image instance to embed it into a PDF * @param svgPath SVG filepath * @param writer PdfWriter instance * @return Instance of com.itextpdf.text.Image holding the SVG file * @throws IOException * @throws BadElementException */
系统中统计数据,由于调用统计过程,执行时间超过了weblogic设置的时间,提示如下错误:
统计数据出错!
原因:The transaction is no longer active - status: 'Rolling Back. [Reason=weblogic.transaction.internal
Totally five patchs committed to erlang otp, just small patchs.
IMO, erlang really is a interesting programming language, I really like its concurrency feature.
but the functional programming style
两个步骤:
1.用w命令找到要踢出的用户,比如下面:
[root@localhost ~]# w
18:16:55 up 39 days, 8:27, 3 users, load average: 0.03, 0.03, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
package edu.xidian.graph;
class MyStack {
private final int SIZE = 20;
private int[] st;
private int top;
public MyStack() {
st = new int[SIZE];
top = -1;
}
public void push(i