Skip to content

Commit c01156e

Browse files
committed
export cropped pdf
1 parent e3f62a9 commit c01156e

File tree

4 files changed

+35
-23
lines changed

4 files changed

+35
-23
lines changed

.travis.yml

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,6 @@ compiler: gcc
33

44
jobs:
55
include:
6-
- os: linux
7-
dist: xenial
8-
arch: amd64
9-
services:
10-
- xvfb
11-
addons:
12-
apt:
13-
update: true
14-
packages:
15-
- build-essential
16-
- gcc
17-
- cmake
18-
- extra-cmake-modules
19-
- qt5-default
20-
- libkf5parts-dev
21-
- libkf5texteditor-dev
22-
- libpoppler-qt5-dev
23-
- libpoppler-cpp-dev
24-
- libpoppler-glib-dev
25-
- kdelibs5-dev
26-
- ktexteditor-katepart
27-
- gettext
286
- os: linux
297
dist: bionic
308
arch: amd64

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.4
1+
0.5

mainwindow.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,37 @@ void MainWindow::exportPNG() {
103103
QString fname = QFileDialog::getSaveFileUrl().toLocalFile();
104104
std::cout << "Export as " << fname.toStdString() << std::endl;
105105
crop.save(fname, "png", -1);
106+
appendLog(QString("Exported as ") + fname);
107+
}
108+
109+
void MainWindow::exportPDF() {
110+
QString pdf(getFilePath(dir, "livetikz_preview.pdf"));
111+
QString pdf_crop(getFilePath(dir, "crop.pdf"));
112+
113+
QStringList arguments;
114+
arguments << pdf;
115+
arguments << pdf_crop;
116+
117+
std::cout << "Crop " << pdf.toStdString() << " to " << pdf_crop.toStdString() << std::endl;
118+
119+
QProcess* crop = new QProcess(this);
120+
crop->setWorkingDirectory(workdir.absolutePath());
121+
crop->start(QString("pdfcrop"), arguments);
122+
crop->waitForFinished();
123+
124+
QString fname = QFileDialog::getSaveFileUrl().toLocalFile();
125+
std::cout << "Export as " << fname.toStdString() << std::endl;
106126

127+
QFile::remove(fname);
128+
if(QFile::exists(pdf_crop)) {
129+
QFile::copy(pdf_crop, fname);
130+
appendLog(QString("Exported as ") + fname);
131+
} else {
132+
std::cout << "Install pdfcrop from texlive-extra-utils to get a cropped PDF" << std::endl;
133+
QFile::copy(pdf, fname);
134+
appendLog(QString("Exported as ") + fname);
135+
appendLog("Install pdfcrop from texlive-extra-utils to get a cropped PDF");
136+
}
107137
}
108138

109139
void MainWindow::render(double scale) {
@@ -329,6 +359,7 @@ MainWindow::MainWindow() : currentDoc(NULL), renderProcess(NULL), currentPage(0)
329359
connect(prevImage, SIGNAL(triggered()), this, SLOT(gotoPreviousImage()));
330360
connect(nextImage, SIGNAL(triggered()), this, SLOT(gotoNextImage()));
331361
connect(exportImgPng, SIGNAL(triggered()), this, SLOT(exportPNG()));
362+
connect(exportImgPdf, SIGNAL(triggered()), this, SLOT(exportPDF()));
332363

333364
connect((QObject *)doc, SIGNAL(textChanged(KTextEditor::Document *)), this,
334365
SLOT(textChanged(KTextEditor::Document *)));
@@ -473,6 +504,7 @@ void MainWindow::setupUI() {
473504
createGUI(katePart);
474505

475506
exportImgPng = toolBar()->addAction(QIcon::fromTheme("image"), "Save as PNG");
507+
exportImgPdf = toolBar()->addAction(QIcon::fromTheme("x-office-document"), "Save as PDF");
476508

477509
toolBar()->addSeparator();
478510
prevImage = toolBar()->addAction(QIcon::fromTheme("go-previous"), "Previous image");

mainwindow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public slots:
5555
void gotoNextImage();
5656
void updateTemplate(const QString& filename);
5757
void exportPNG();
58+
void exportPDF();
5859

5960
private:
6061
void setupActions();
@@ -118,6 +119,7 @@ public slots:
118119
QAction* nextImage;
119120
QAction* prevImage;
120121
QAction* exportImgPng;
122+
QAction* exportImgPdf;
121123

122124
int currentPage;
123125
bool usersaved;

0 commit comments

Comments
 (0)