Bonjour,
J'imprime un JEditorPane grace au code suivant (épuré) :
Au préalable j'ai chargé une page HTML dans le jep :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 public void print() { PrinterJob job = PrinterJob.getPrinterJob(); job.setJobName("Report"); job.setPrintable (new Printable() { public int print(Graphics g, PageFormat pageFormat, int pageIndex) { if (pageIndex > 0) { return(NO_SUCH_PAGE); } else { Graphics2D g2d = (Graphics2D)g; jep.paint(g2d); jep.setSize( 500, 500);//to force repaint return(PAGE_EXISTS); } } } ); if (job.printDialog()) { try { job.print(); } catch (PrinterException e) { System.err.println(e.getMessage()); } } }
jep.setPage (url); //url contient le chemin d'accès à la page html
Tout cela fonctionne très bien.
Maintenant, je voudrais faire la même chose, mais vers un PDF. Je voudrais simplement utiliser le Graphics2D pour céer le PDF.
Mes nombreuses recherches sur le NET n'ont pas abouties. Seul GNUpdf semblait correspondre, mais ne fonctionne pas (fichier corrompu).
Une piste ?
Christian
Partager