我正在尝试在SWT中实现以下代码,但我没有太多运气。有人可以给我一个暗示如何与SWT一起使用PDF渲染库吗?我认为主要问题是我无法弄清楚如何将页面板附加到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

谢谢!

有帮助吗?

解决方案

...或者您可能会看支持支持SWT的Jpodrenderer ...(GPL)

其他提示

您可以使用秋千/ SWT桥。有一个 教程 在eclipse.org上。

您有一些钱可以花,尝试PDFONE,它更快,也可以应付eNbedded字体。

你也可以看 http://www.jpedal.org/support_sieclipse.php 这是用于日食的免费PDF查看器插件。您可以下载包括完整工作区项目的开源代码。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top