@@ -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
109139void 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" );
0 commit comments