0

Can help? I just get a blank view with vertical scrollbar. Can check the code? I think the trouble starts at item.setPixmap(pixmap); because the pixmap is the same size of image that is the image is loaded into it. thanks

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <poppler-qt4.h>
#include <QGraphicsPixmapItem>
#include <QGraphicsRotation>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
ui->setupUi(this);

QString filename;

Poppler::Document* document = Poppler::Document::load("/home/pc/Documenti/ICS-TR-06-16.pdf");
if (!document || document->isLocked())
{

  // ... error message ....

  delete document;
  return;
}

qDebug("doc %i \n",document->numPages()); //gives 11

// Access page of the PDF file
Poppler::Page* pdfPage = document->page(1);  // Document starts at page 0
if (pdfPage == 0) {
  // ... error message ...
  return;
}

// Generate a QImage of the rendered page
QImage image = pdfPage->renderToImage(72.0,72.0,0,0,pdfPage->pageSize().width(),pdfPage->pageSize().height());
if (image.isNull()) {
  // ... error message ...
  return;
}

qDebug("img %i %i \n",image.width(),image.height()); //gives 612 792
QGraphicsScene* scene=new QGraphicsScene();


QPixmap pixmap;
pixmap=QPixmap::fromImage(image);
qDebug("pix %i %i \n",pixmap.width(),pixmap.height()); //gives 612 792



QGraphicsPixmapItem item;
item.setPixmap(pixmap);
qDebug("itpix %i %i \n",item.pixmap().width(),item.pixmap().height()); //gives 612 792
//qDebug("ite %i %i \n",);

    scene->addItem(&item);
    this->ui->graphicsView->setScene(scene);

 this->ui->graphicsView->show();
// ... use image ...

// after the usage, the page must be deleted
delete pdfPage;
}

MainWindow::~MainWindow()
{
if (document!=0) delete document;
delete ui;
}    
4

1 回答 1

0

乍一看,我看不出有什么问题。

但是,冒着说明显而易见的风险,您确定 PDF 的第一页不是空白的吗?

于 2011-07-31T10:07:50.443 回答