細 文字列「__FORCETOC__」を「{{#seo: |title={{PAGENAME}} : Exploring Electronics and SUSE Linux | MochiuWiki |keywords=MochiuWiki,Mochiu,Wiki,Mochiu Wiki,Electric Circuit,Electric,pcb,Mathematics,AVR,TI,STMicro,AVR,ATmega,MSP430,STM,Arduino,Xilinx,FPGA,Verilog,HDL,PinePhone,Pine Phone,Raspberry,Raspberry Pi,C,C++,C#,Qt,Qml,MFC,Shell,Bash,Zsh,Fish,SUSE,SLE,Suse Enterprise,Suse Linux,openSUSE,open SUSE,Leap,Linux,uCLnux,Podman,電気回路,電子回路,基板,プリント基板 |description={{PAGENAME}} - 電子回路とSUSE Linuxに関する情報 | This pag… |
|||
| (同じ利用者による、間の1版が非表示) | |||
| 37行目: | 37行目: | ||
<br><br> | <br><br> | ||
== | == Qtライブラリ == | ||
==== | ==== PDFの作成 ==== | ||
Qtでは、簡単にPDFを作成する機能が用意されている。<br> | Qtでは、簡単にPDFを作成する機能が用意されている。<br> | ||
<syntaxhighlight lang="c++"> | <syntaxhighlight lang="c++"> | ||
| 76行目: | 76行目: | ||
painter.end(); | painter.end(); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<br><br> | |||
== Popplerライブラリ == | |||
Popplerライブラリは、QPdfWriterライブラリと比較して、より高度なPDF操作や読み込みに適している。<br> | |||
<br> | <br> | ||
==== Poppler- | ==== PDFの作成 ==== | ||
Poppler- | 以下の例では、HTMLコンテンツを含むPDFファイルを作成している。<br> | ||
<syntaxhighlight lang="c++"> | |||
#include <QCoreApplication> | |||
#include <QPainter> | |||
#include <QPdfWriter> | |||
#include <QTextDocument> | |||
int main(int argc, char *argv[]) | |||
{ | |||
QCoreApplication a(argc, argv); | |||
QPdfWriter writer("output.pdf"); | |||
writer.setPageSize(QPageSize(QPageSize::A4)); | |||
QPainter painter(&writer); | |||
painter.setPen(Qt::black); | |||
QTextDocument doc; | |||
doc.setHtml("<h1>Hello, PDF!</h1>" | |||
"<p>This is a sample PDF created with Poppler and Qt.</p>"); | |||
doc.setPageSize(writer.pageRect().size()); | |||
doc.drawContents(&painter); | |||
painter.end(); | |||
return 0; | |||
} | |||
</syntaxhighlight> | |||
<br> | |||
==== PDFの表示 ==== | |||
以下の例では、指定されたPDFファイルの最初のページを画像として表示している。<br> | |||
<syntaxhighlight lang="c++"> | |||
#include <QCoreApplication> | |||
#include <QLabel> | |||
#include <QImage> | |||
#include <poppler-qt5.h> | |||
int main(int argc, char *argv[]) | |||
{ | |||
QCoreApplication a(argc, argv); | |||
Poppler::Document *document = Poppler::Document::load("input.pdf"); | |||
if (!document || document->isLocked()) { | |||
delete document; | |||
return -1; | |||
} | |||
Poppler::Page *page = document->page(0); | |||
if (page == nullptr) { | |||
delete document; | |||
return -1; | |||
} | |||
QImage image = page->renderToImage(72.0, 72.0); | |||
QLabel label; | |||
label.setPixmap(QPixmap::fromImage(image)); | |||
label.show(); | |||
delete page; | |||
delete document; | |||
return a.exec(); | |||
} | |||
</syntaxhighlight> | |||
<br> | |||
==== PDFの操作 ==== | |||
以下の例では、PDFファイルのページ数の取得、メタデータの読み取り、特定のページからのテキストを抽出している。<br> | |||
<syntaxhighlight lang="c++"> | |||
#include <QCoreApplication> | |||
#include <poppler-qt5.h> | |||
#include <QDebug> | |||
int main(int argc, char *argv[]) | |||
{ | |||
QCoreApplication a(argc, argv); | |||
Poppler::Document *document = Poppler::Document::load("input.pdf"); | |||
if (!document || document->isLocked()) { | |||
qDebug() << "Could not open PDF file"; | |||
delete document; | |||
return -1; | |||
} | |||
// ページ数の取得 | |||
int pageCount = document->numPages(); | |||
qDebug() << "Number of pages:" << pageCount; | |||
// メタデータの読み取り | |||
qDebug() << "Title:" << document->info("Title"); | |||
qDebug() << "Author:" << document->info("Author"); | |||
qDebug() << "Subject:" << document->info("Subject"); | |||
qDebug() << "Keywords:" << document->info("Keywords"); | |||
qDebug() << "Creator:" << document->info("Creator"); | |||
qDebug() << "Producer:" << document->info("Producer"); | |||
qDebug() << "Creation date:" << document->info("CreationDate"); | |||
qDebug() << "Modification date:" << document->info("ModDate"); | |||
// 特定のページのテキスト抽出(例:最初のページ) | |||
if (pageCount > 0) { | |||
Poppler::Page *page = document->page(0); | |||
if (page) { | |||
QString text = page->text(QRectF()); | |||
qDebug() << "Text from first page:" << text; | |||
delete page; | |||
} | |||
} | |||
delete document; | |||
return 0; | |||
} | |||
</syntaxhighlight> | |||
<br> | |||
==== その他 : PDFを画像に変換 ==== | |||
<syntaxhighlight lang="c++"> | <syntaxhighlight lang="c++"> | ||
#include <QCoreApplication> | #include <QCoreApplication> | ||
| 116行目: | 234行目: | ||
<br><br> | <br><br> | ||
{{#seo: | |||
|title={{PAGENAME}} : Exploring Electronics and SUSE Linux | MochiuWiki | |||
|keywords=MochiuWiki,Mochiu,Wiki,Mochiu Wiki,Electric Circuit,Electric,pcb,Mathematics,AVR,TI,STMicro,AVR,ATmega,MSP430,STM,Arduino,Xilinx,FPGA,Verilog,HDL,PinePhone,Pine Phone,Raspberry,Raspberry Pi,C,C++,C#,Qt,Qml,MFC,Shell,Bash,Zsh,Fish,SUSE,SLE,Suse Enterprise,Suse Linux,openSUSE,open SUSE,Leap,Linux,uCLnux,Podman,電気回路,電子回路,基板,プリント基板 | |||
|description={{PAGENAME}} - 電子回路とSUSE Linuxに関する情報 | This page is {{PAGENAME}} in our wiki about electronic circuits and SUSE Linux | |||
|image=/resources/assets/MochiuLogo_Single_Blue.png | |||
}} | |||
__FORCETOC__ | __FORCETOC__ | ||
[[カテゴリ:Qt]] | [[カテゴリ:Qt]] | ||