Exemplo n.º 1
0
void SearchDocumentJob::run()
{
    Q_ASSERT(m_document);

    for (int i = 0; i < m_document->numPages(); ++i) {
        int ipage = (startPage + i) % m_document->numPages();
        Poppler::Page *page = m_document->page(ipage);
    
        double sLeft, sTop, sRight, sBottom;
        float scaleW = 1.f / page->pageSizeF().width();
        float scaleH = 1.f / page->pageSizeF().height();
        bool found;
        found = page->search(m_search, sLeft, sTop, sRight, sBottom,
                             Poppler::Page::FromTop,
                             Poppler::Page::IgnoreCase);
        while (found) {
            QRectF result;
            result.setLeft(sLeft * scaleW);
            result.setTop(sTop * scaleH);
            result.setRight(sRight * scaleW);
            result.setBottom(sBottom * scaleH);
            m_matches.append(QPair<int, QRectF>(ipage, result));
            found = page->search(m_search, sLeft, sTop, sRight, sBottom,
                                 Poppler::Page::NextResult,
                                 Poppler::Page::IgnoreCase);
        }

        delete page;
    }
}
void guFolderInspector::extractIsbnsFromPdf(QString fileName, QList<QString> &ISBNList)
{
    //PDFDoc *doc;
    //doc = new PDFDoc()
    //qDebug() << "file:" << fileName;
    Poppler::Document* document;
    document = Poppler::Document::load(fileName,0,0);


    //Poppler::Document::
    if (!document || document->isLocked()) {

        // ... error message ....
        delete document;
        return;
    }
    // Paranoid safety check
    if (!document) {
        // ... error message ...
        return;
    }

    Poppler::Page* pdfPage;
    isbnMethods find;

    // Access page of the PDF file
    int numOfPages = document->numPages(); //количество страниц
    int numOfSearchPages = 15;
    //qDebug() << "num of pages " << numOfPages;
    if(numOfPages < numOfSearchPages)
    {
        numOfSearchPages = numOfPages;
    }
    for ( int pageNumber = 0 ; pageNumber < numOfSearchPages ; pageNumber++)
    {
        pdfPage = document->page(pageNumber);  // Document starts at page 0
        if (!pdfPage) {
            // ... error message ...
            continue;
        }

        //QtMsgHandler qInstallMsgHandler ( QtMsgHandler handler )
        QString pageContent;
        pageContent = pdfPage->text(QRectF(QPointF(0,0),pdfPage->pageSizeF()));

        find.findIsbns(pageContent, ISBNList);

        // ... use image ...
        //qDebug() << pageContent;
    }

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

    //Finally, don't forget to destroy the document:

    delete document;
}
Exemplo n.º 3
0
void PageSizesJob::run()
{
    Q_ASSERT(m_document);

    for (int i = 0; i < m_document->numPages(); ++i) {
        Poppler::Page *page = m_document->page(i);
        m_pageSizes.append(page->pageSizeF());
        delete page;
    }
}
Exemplo n.º 4
0
void RenderPageJob::run()
{
    Q_ASSERT(m_document);

    Poppler::Page *page = m_document->page(m_index);
    float scale = 72.0f * (float(m_width) / page->pageSizeF().width());
    QImage image = page->renderToImage(scale, scale);
    // Note: assuming there's exactly one handler (PDFCanvas) to catch ownership of this when PDFDocument emits a signal with this
    m_page = m_window->createTextureFromImage(image);
    delete page;
}
void TestMetaData::checkPageSize()
{
    Poppler::Document *doc;

    doc = Poppler::Document::load("../../../test/unittestcases/truetype.pdf");
    QVERIFY( doc );
    Poppler::Page *page = doc->page(0);
    QCOMPARE( page->pageSize(), QSize(595, 842) );
    QCOMPARE( page->pageSizeF(), QSizeF(595.22, 842) );

    delete page;
    delete doc;
}
Exemplo n.º 6
0
void KisPDFImportWidget::updateMaxCanvasSize()
{
    m_maxWidthInch = 0., m_maxHeightInch = 0.;
    for (QList<int>::const_iterator it = m_pages.constBegin(); it != m_pages.constEnd(); ++it) {
        Poppler::Page *p = m_pdfDoc->page(*it);
        QSizeF size = p->pageSizeF();
        if (size.width() > m_maxWidthInch) {
            m_maxWidthInch = size.width();
        }
        if (size.height() > m_maxHeightInch) {
            m_maxHeightInch = size.height();
        }
    }
    m_maxWidthInch /= 72.;
    m_maxHeightInch /= 72.;
    dbgFile << m_maxWidthInch << "" << m_maxHeightInch;
    updateResolution();
}