qt開啟
pdf檔案,效果如下:
開啟pdf檔案
載入程序式
執行時,別忘了把dll檔案放入
release
目錄下,不然會
crash
的,執行不了。
qt讀取
pdf檔案採用的是
mupdf
庫。將編譯好的庫檔案放入工程目錄下
include
和lib
在該工程中的.pro檔案加入外部庫,我使用的是
64位的庫檔案,
minggw32
位的請使用
x86的庫檔案,新增
include
庫檔案。
mainwindow.**件內容如下:
#ifndef mainwindow_h
#define mainwindow_h
#include
#include
namespace ui {
class mainwindow;
class mainwindow : public qmainwindow
q_object
public:
explicit mainwindow(qwidget *parent = 0);
~mainwindow();
private slots:
void on_actionopenpdf_triggered();
private:
ui::mainwindow *ui;
#endif // mainwindow_h
mainwindow.cpp檔案內容如下:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "include/mupdf-qt.h"
#include
#include
mainwindow::mainwindow(qwidget *parent) :
qmainwindow(parent),
ui(new ui::mainwindow)
ui->setupui(this);
this->setwindowtitle(tr("灝夏星辰 -開啟
pdf檔案
"));
this->setwindowicon(qicon(":/new/prefix1/image.png"));
ui->scrollarea->setframeshape(qframe::noframe); //設定滑動區域無邊框
mainwindow::~mainwindow()
delete ui;
void mainwindow::on_actionopenpdf_triggered()
* 思路:
* 將開啟的
pdf每頁提取成,將每張放入乙個
label
控制項中,
* 設定乙個垂直布局,將多個
label
控制項垂直起來放入
widget
* 然後將
widget
放入scrollarea
控制項中
qstring filename = qfiledialog::getopenfilename(this, tr("選擇檔案
"), tr(""), tr("pdf
檔案(*.pdf)"));
if(filename.isnull() || !filename.contains(".pdf")) return;
mupdf::document * document = mupdf::loaddocument(filename); //將
pdf檔案載入進
document
qwidget * widget = new qwidget(this);
qvboxlayout *vboxlayout=new qvboxlayout();
for(int i = 0; i < document->numpages(); i ++) //根據獲取到的
pdf頁數迴圈
qlabel * label = new qlabel(this);
qimage image = document->page(i)->renderimage(2.0, 2.0); //擷取
pdf檔案中的相應
label->setpixmap(qpixmap::fromimage(image)); //將該放進
label中
vboxlayout->addwidget(label);
vboxlayout->setalignment(widget,qt::aligncenter);
widget->setlayout(vboxlayout); //設定布局
ui->scrollarea->setwidget(widget); //設定
widget
**路徑: (64位可用)
poppler讀取pdf**路徑:位可用)
使用 pdfminer 讀取 pdf 檔案
python 語言讀取 pdf 檔案是乙個令人頭疼的事情,本文將使用的 包 pdfminer 的文件中就曾評價 pdf is evil 本文提供使用該 包讀取 pdf 檔案的具體 實現提取英文 pdf 文字中的單詞的功能。具體 如下 import re import pandas as pd fro...
python讀取pdf檔案
pdfplumber是乙個可以處理pdf格式資訊的庫。可以查詢關於每個文字字元 矩陣 和行的詳細資訊,也可以對 進行提取並進行視覺化除錯。文件參考 安裝直接採用pip即可。命令列中輸入 pip install pdfplumber import pdfplumber with pdfplumber....
qt 讀取檔案
當去取檔案時,發現如果檔案路徑是絕對路徑,可以讀取成功,如果是專案路徑讀取失敗,readqss qstring qssfile qfile file qssfile qstring curpath qdir currentpath 獲取系統當前目錄 qfile file e qtexercise c...