Pregunta

I'm trying to use Aspose PDF Kit (4.7.0) to display a PDF in JScrollPane as documented in their javadoc, using PdfViewer.showPdf() method.

The result is that I can only see 1 page of my -very simple- document and it is not being correctly rendered: Pdf rendering result

Here is my code below:

import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;

import com.aspose.pdf.kit.PdfViewer;

public class SimplePdfViewer extends JFrame
{
    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = -494213537688110764L;

    public SimplePdfViewer()
    {
        try
        {
            // Aspose license initialisation
            Aspose.init();

            PdfViewer pdfviewer = new PdfViewer();
            pdfviewer.openPdfFile("src/main/resources/10 pages.pdf");

            //decode the pdf page, I also tried pdfViewer.decodeAllPages() and only the last one is displayed.
            pdfviewer.decodePage(1);

            pdfviewer.setPdfPageParameters(1, 1);

            JScrollPane displayScrollPane = pdfviewer.showPdf();
            getContentPane().add(displayScrollPane, BorderLayout.CENTER);
        }
        catch (Exception e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
            getContentPane().add(new JLabel(e.getMessage()));
        }

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        pack();
        setVisible(true);
    }

    public static void main(String[] args)
    {
        new SimplePdfViewer();
    }
}

Am I missing something ?

¿Fue útil?

Solución

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top