Aiuto implementazione Java Pdf-renderer esempio in SWT?
-
23-10-2019 - |
Domanda
Sto cercando di implementare il seguente codice nel SWT e non sto avendo molta fortuna. Qualcuno potrebbe darmi un suggerimento su come utilizzare la libreria Pdf-Render con SWT? Credo che il problema principale è che non riesco a capire come collegare un PagePanel ad un guscio SWT.
package pdfpaneltest;
import com.sun.pdfview.PDFFile;
import com.sun.pdfview.PDFPage;
import com.sun.pdfview.PagePanel;
import java.io.*;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import javax.swing.*;
/**
* An example of using the PagePanel class to show PDFs. For more advanced
* usage including navigation and zooming, look ad the
* com.sun.pdfview.PDFViewer class.
*
* @author joshua.marinacci@sun.com
*/
public class Main {
public static void setup() throws IOException {
//set up the frame and panel
JFrame frame = new JFrame("PDF Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
PagePanel panel = new PagePanel();
frame.add(panel);
frame.pack();
frame.setVisible(true);
//load a pdf from a byte buffer
File file = new File("test.pdf");
RandomAccessFile raf = new RandomAccessFile(file, "r");
FileChannel channel = raf.getChannel();
ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY,
0, channel.size());
PDFFile pdffile = new PDFFile(buf);
// show the first page
PDFPage page = pdffile.getPage(0);
panel.showPage(page);
}
public static void main(final String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
Main.setup();
} catch (IOException ex) {
ex.printStackTrace();
}
}
});
}
}
https://pdf-renderer.dev.java.net/examples. html
Grazie!
Soluzione
... oppure si può avere uno sguardo a jPodRenderer che supporta SWT ... (GPL)
Altri suggerimenti
Si potrebbe utilizzare il Ponte girevole / SWT. C'è un esercitazione su eclipse.org.
Si avete qualche soldo da spendere, provare PDFOne, che è più veloce e anche in grado di far fronte con i font enbedded.
You could also look at http://www.jpedal.org/support_siEclipse.php which is a free PDF viewer plugin for Eclipse. You can download the Open Source code including the full workspace project.