2018-11-21 19:30:15 +01:00
|
|
|
#include "pdfviewermainwindow.h"
|
|
|
|
#include "ui_pdfviewermainwindow.h"
|
|
|
|
|
|
|
|
#include "pdfdocumentreader.h"
|
2018-12-01 11:36:07 +01:00
|
|
|
#include "pdfvisitor.h"
|
2019-01-20 17:55:06 +01:00
|
|
|
#include "pdfstreamfilters.h"
|
2018-11-21 19:30:15 +01:00
|
|
|
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
|
|
|
namespace pdfviewer
|
|
|
|
{
|
|
|
|
|
|
|
|
PDFViewerMainWindow::PDFViewerMainWindow(QWidget *parent) :
|
|
|
|
QMainWindow(parent),
|
|
|
|
ui(new Ui::PDFViewerMainWindow)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
connect(ui->actionOpen, &QAction::triggered, this, &PDFViewerMainWindow::onActionOpenTriggered);
|
|
|
|
}
|
|
|
|
|
|
|
|
PDFViewerMainWindow::~PDFViewerMainWindow()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PDFViewerMainWindow::onActionOpenTriggered()
|
|
|
|
{
|
|
|
|
QString fileName = QFileDialog::getOpenFileName(this, tr("Select PDF document"), "K:/Programming/PDF/testpdf", tr("PDF document (*.pdf)"));
|
|
|
|
if (!fileName.isEmpty())
|
|
|
|
{
|
|
|
|
pdf::PDFDocumentReader reader;
|
|
|
|
pdf::PDFDocument document = reader.readFromFile(fileName);
|
2018-12-01 11:36:07 +01:00
|
|
|
pdf::PDFStatisticsCollector collector;
|
|
|
|
pdf::PDFApplyVisitor(document, &collector);
|
2018-11-21 19:30:15 +01:00
|
|
|
|
|
|
|
if (reader.isSuccessfull())
|
|
|
|
{
|
|
|
|
QMessageBox::information(this, tr("PDF Reader"), tr("Document '%1' was successfully loaded!").arg(fileName));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-11-25 14:48:08 +01:00
|
|
|
QMessageBox::information(this, tr("PDF Reader"), tr("Document read error: %1").arg(reader.getErrorMessage()));
|
2018-11-21 19:30:15 +01:00
|
|
|
}
|
2019-01-20 17:55:06 +01:00
|
|
|
|
|
|
|
const pdf::PDFCatalog* catalog = document.getCatalog();
|
|
|
|
const pdf::PDFPage* page = catalog->getPage(0);
|
|
|
|
const pdf::PDFObject& contents = page->getContents();
|
|
|
|
|
|
|
|
if (contents.isStream())
|
|
|
|
{
|
|
|
|
const pdf::PDFStream* stream = contents.getStream();
|
|
|
|
const QByteArray* compressed = stream->getContent();
|
|
|
|
pdf::PDFFlateDecodeFilter fd;
|
|
|
|
QByteArray uncompressed = fd.apply(*compressed, &document, pdf::PDFObject());
|
|
|
|
}
|
2018-11-21 19:30:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace pdfviewer
|