GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — mxgraph/java/examples/com/mxgraph/examples/PdfExport.java at master · AndychenCL/mxgraph

Expand file tree

/

PdfExport.java

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
75 lines (66 loc) · 1.87 KB
/

PdfExport.java

Copy path

File metadata and controls

75 lines (66 loc) · 1.87 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package com.mxgraph.examples;
import java.awt.Graphics2D;
import java.io.FileOutputStream;
import com.mxpdf.text.Document;
import com.mxpdf.text.Rectangle;
import com.mxpdf.text.pdf.PdfContentByte;
import com.mxpdf.text.pdf.PdfWriter;
import com.mxgraph.canvas.mxGraphics2DCanvas;
import com.mxgraph.canvas.mxICanvas;
import com.mxgraph.model.mxCell;
import com.mxgraph.util.mxCellRenderer;
import com.mxgraph.util.mxRectangle;
import com.mxgraph.util.mxCellRenderer.CanvasFactory;
import com.mxgraph.view.mxGraph;
// This example requires iText from http://www.lowagie.com/iText/
public class PdfExport
{
public PdfExport() throws Exception
{
// Creates graph with model
mxGraph graph = new mxGraph();
Object parent = graph.getDefaultParent();
graph.getModel().beginUpdate();
try
{
Object v1 = graph.insertVertex(parent, null, "Hello", 20, 20, 80,
30);
mxCell v2 = (mxCell) graph.insertVertex(parent, null, "World!",
240, 150, 80, 30);
graph.insertEdge(parent, null, "e1", v1, v2);
}
finally
{
graph.getModel().endUpdate();
}
mxRectangle bounds = graph.getGraphBounds();
Document document = new Document(new Rectangle((float) (bounds
.getWidth()), (float) (bounds.getHeight())));
PdfWriter writer = PdfWriter.getInstance(document,
new FileOutputStream("example.pdf"));
document.open();
final PdfContentByte cb = writer.getDirectContent();
mxGraphics2DCanvas canvas = (mxGraphics2DCanvas) mxCellRenderer
.drawCells(graph, null, 1, null, new CanvasFactory()
{
public mxICanvas createCanvas(int width, int height)
{
Graphics2D g2 = cb.createGraphics(width, height);
return new mxGraphics2DCanvas(g2);
}
});
canvas.getGraphics().dispose();
document.close();
}
public static void main(String[] args)
{
try
{
new PdfExport();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.