diff --git a/src/Gui/ApplicationPy.cpp b/src/Gui/ApplicationPy.cpp index 7a7185d432..6384187a62 100644 --- a/src/Gui/ApplicationPy.cpp +++ b/src/Gui/ApplicationPy.cpp @@ -44,6 +44,8 @@ #include #include +#include + #include "Application.h" #include "ApplicationPy.h" #include "BitmapFactory.h" @@ -773,8 +775,10 @@ PyObject* ApplicationPy::sExport(PyObject * /*self*/, PyObject *args) view3d->viewAll(); } QPrinter printer(QPrinter::ScreenResolution); - // setPdfVersion sets the printed PDF Version to comply with PDF/A-1b, more details under: https://www.kdab.com/creating-pdfa-documents-qt/ - printer.setPdfVersion(QPagedPaintDevice::PdfVersion_A1b); + // setPdfVersion sets the printed PDF Version to what is chosen in + // Preferences/Import-Export/PDF more details under: + // https://www.kdab.com/creating-pdfa-documents-qt/ + printer.setPdfVersion(Gui::Dialog::DlgSettingsPDF::evaluatePDFVersion()); printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFileName(fileName); printer.setCreator(QString::fromStdString(App::Application::getNameWithVersion())); diff --git a/src/Gui/CMakeLists.txt b/src/Gui/CMakeLists.txt index 0d89a55715..cf97f6f7e9 100644 --- a/src/Gui/CMakeLists.txt +++ b/src/Gui/CMakeLists.txt @@ -418,6 +418,7 @@ SET(Gui_UIC_SRCS PreferencePages/DlgSettingsUI.ui PreferencePages/DlgSettingsViewColor.ui PreferencePages/DlgSettingsWorkbenches.ui + PreferencePages/DlgSettingsPDF.ui Dialogs/DlgCheckableMessageBox.ui Dialogs/DlgToolbars.ui Dialogs/DlgTreeWidget.ui @@ -659,6 +660,7 @@ SET(Dialog_Settings_CPP_SRCS Dialogs/DlgOnlineHelpImp.cpp Dialogs/DlgPreferencesImp.cpp PreferencePages/DlgSettings3DViewImp.cpp + PreferencePages/DlgSettingsPDF.cpp PreferencePages/DlgSettingsCacheDirectory.cpp Dialogs/DlgSettingsColorGradientImp.cpp PreferencePages/DlgSettingsDocumentImp.cpp @@ -681,6 +683,7 @@ SET(Dialog_Settings_HPP_SRCS Dialogs/DlgOnlineHelpImp.h Dialogs/DlgPreferencesImp.h PreferencePages/DlgSettings3DViewImp.h + PreferencePages/DlgSettingsPDF.h PreferencePages/DlgSettingsCacheDirectory.h Dialogs/DlgSettingsColorGradientImp.h PreferencePages/DlgSettingsDocumentImp.h @@ -721,6 +724,7 @@ SET(Dialog_Settings_SRCS PreferencePages/DlgSettingsUI.ui PreferencePages/DlgSettingsViewColor.ui PreferencePages/DlgSettingsWorkbenches.ui + PreferencePages/DlgSettingsPDF.ui ) SOURCE_GROUP("Dialog\\Settings" FILES ${Dialog_Settings_SRCS}) diff --git a/src/Gui/EditorView.cpp b/src/Gui/EditorView.cpp index 0ad911d0b8..c62f278309 100644 --- a/src/Gui/EditorView.cpp +++ b/src/Gui/EditorView.cpp @@ -57,6 +57,8 @@ #include #include +#include + using namespace Gui; namespace Gui @@ -511,9 +513,10 @@ void EditorView::printPdf() QStringLiteral("%1 (*.pdf)").arg(tr("PDF file"))); if (!filename.isEmpty()) { QPrinter printer(QPrinter::ScreenResolution); - // setPdfVersion sets the printied PDF Version to comply with PDF/A-1b, more details under: + // setPdfVersion sets the printed PDF Version to what is chosen in + // Preferences/Import-Export/PDF more details under: // https://www.kdab.com/creating-pdfa-documents-qt/ - printer.setPdfVersion(QPagedPaintDevice::PdfVersion_A1b); + printer.setPdfVersion(Gui::Dialog::DlgSettingsPDF::evaluatePDFVersion()); printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFileName(filename); printer.setCreator(QString::fromStdString(App::Application::getNameWithVersion())); diff --git a/src/Gui/MDIView.cpp b/src/Gui/MDIView.cpp index c8c8d8fb68..253e8bb9b2 100644 --- a/src/Gui/MDIView.cpp +++ b/src/Gui/MDIView.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include "MDIView.h" #include "MDIViewPy.h" @@ -261,8 +262,10 @@ void MDIView::printPdf() QStringLiteral("%1 (*.pdf)").arg(tr("PDF file"))); if (!filename.isEmpty()) { QPrinter printer(QPrinter::ScreenResolution); - // setPdfVersion sets the printied PDF Version to comply with PDF/A-1b, more details under: https://www.kdab.com/creating-pdfa-documents-qt/ - printer.setPdfVersion(QPagedPaintDevice::PdfVersion_A1b); + // setPdfVersion sets the printed PDF Version to what is chosen in + // Preferences/Import-Export/PDF more details under: + // https://www.kdab.com/creating-pdfa-documents-qt/ + printer.setPdfVersion(Gui::Dialog::DlgSettingsPDF::evaluatePDFVersion()); printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFileName(filename); printer.setCreator(QString::fromStdString(App::Application::getNameWithVersion())); diff --git a/src/Gui/PreferencePages/DlgSettingsPDF.cpp b/src/Gui/PreferencePages/DlgSettingsPDF.cpp new file mode 100644 index 0000000000..b43bdbe130 --- /dev/null +++ b/src/Gui/PreferencePages/DlgSettingsPDF.cpp @@ -0,0 +1,103 @@ +#include "PreCompiled.h" + +#include +#include + +#include "DlgSettingsPDF.h" +#include "ui_DlgSettingsPDF.h" + + +using namespace Gui::Dialog; + +/* TRANSLATOR Gui::Dialog::DlgSettingsPDF */ + +DlgSettingsPDF::DlgSettingsPDF(QWidget* parent) + : PreferencePage( parent ) + , ui(new Ui_DlgSettingsPDF) +{ + ui->setupUi(this); + ui->warningLabel->setWordWrap(true); + connect(ui->comboBox, + QOverload::of(&QComboBox::currentIndexChanged), + this, + &DlgSettingsPDF::onComboBoxIndexChanged); +} + +DlgSettingsPDF::~DlgSettingsPDF() = default; + +void DlgSettingsPDF::saveSettings() +{ + ui->comboBox->onSave(); +} + +void DlgSettingsPDF::loadSettings() +{ + ui->comboBox->onRestore(); + int currentIndex = ui->comboBox->currentIndex(); +#if QT_VERSION < QT_VERSION_CHECK(6,8,0) + if (currentIndex == 3) { + Base::Console().Warning("When using another copy of FreeCAD you had set the PDF version to X4, but this build of FreeCAD does not support it. Using 1.4 instead.\n"); + currentIndex = 0; + ui->comboBox->setCurrentIndex(0); + } + ui->comboBox->removeItem(3); // PdfVersion_X4 +#endif + onComboBoxIndexChanged(currentIndex); +} + +QPagedPaintDevice::PdfVersion DlgSettingsPDF::evaluatePDFVersion() +{ + auto hGrp = App::GetApplication() + .GetUserParameter() + .GetGroup("BaseApp") + ->GetGroup("Preferences") + ->GetGroup("Mod"); + + const int ver = hGrp->GetInt("PDFVersion"); + + switch (ver) { + case 1: + return QPagedPaintDevice::PdfVersion_A1b; + case 2: + return QPagedPaintDevice::PdfVersion_1_6; +#if QT_VERSION >= QT_VERSION_CHECK(6,8,0) + case 3: + return QPagedPaintDevice::PdfVersion_X4; +#endif + default: + return QPagedPaintDevice::PdfVersion_1_4; + } +} + +void DlgSettingsPDF::onComboBoxIndexChanged(int index) +{ + switch (index) { + case 1: + ui->warningLabel->setText( + tr("This archival PDF format does not support transparency or layers. All content must be self-contained and static.")); + break; + case 2: + ui->warningLabel->setText( + tr("While this version supports more modern features, older PDF readers may not fully handle it.")); + break; + case 3: + ui->warningLabel->setText( + tr("This PDF format is intended for professional printing and requires all fonts to be embedded; some interactive features may not be supported.")); + break; + default: + ui->warningLabel->setText( + tr("This PDF version has limited support for modern features like embedded multimedia and advanced transparency effects.")); + break; + } +} + +void DlgSettingsPDF::changeEvent(QEvent* e) +{ + if (e->type() == QEvent::LanguageChange) { + ui->retranslateUi(this); + } + + QWidget::changeEvent(e); +} + +#include "moc_DlgSettingsPDF.cpp" diff --git a/src/Gui/PreferencePages/DlgSettingsPDF.h b/src/Gui/PreferencePages/DlgSettingsPDF.h new file mode 100644 index 0000000000..f4e55b1700 --- /dev/null +++ b/src/Gui/PreferencePages/DlgSettingsPDF.h @@ -0,0 +1,42 @@ +#ifndef GUI_DIALOG_DLGSETTINGSPDF_H +#define GUI_DIALOG_DLGSETTINGSPDF_H + +#include +#include +#include + +namespace Gui { +namespace Dialog { +class Ui_DlgSettingsPDF; + +/** +* The DlgSettingsPDF class implements a preference page to change settings +* for the PDF Import-Export. +*/ +class GuiExport DlgSettingsPDF: public PreferencePage +{ + Q_OBJECT + +public: + explicit DlgSettingsPDF(QWidget* parent = nullptr); + ~DlgSettingsPDF() override; + + void saveSettings() override; + void loadSettings() override; + static QPagedPaintDevice::PdfVersion evaluatePDFVersion(); + +protected: + void changeEvent(QEvent *e) override; + +private: + void onComboBoxIndexChanged(int index); + + std::unique_ptr ui; + +// Q_DISABLE_COPY_MOVE(DlgSettingsPDF) +}; + +} // namespace Dialog +} // namespace Gui + +#endif // GUI_DIALOG_DLGSETTINGSPDF_H diff --git a/src/Gui/PreferencePages/DlgSettingsPDF.ui b/src/Gui/PreferencePages/DlgSettingsPDF.ui new file mode 100644 index 0000000000..47b30028f4 --- /dev/null +++ b/src/Gui/PreferencePages/DlgSettingsPDF.ui @@ -0,0 +1,109 @@ + + + Gui::Dialog::DlgSettingsPDF + + + + 0 + 0 + 446 + 462 + + + + PDF + + + + 6 + + + 9 + + + + + PDF Export + + + + + + + + PDF Version: + + + + + + + This is the PDF Version FreeCAD will use to export to PDF. + + + PDFVersion + + + Mod + + + + PDF/1.4 + + + + + PDF/A-1b + + + + + PDF/1.6 + + + + + PDF/X-4 + + + + + + + + + + true + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + qPixmapFromMimeSource + + + Gui::PrefComboBox + QComboBox +
Gui/PrefWidgets.h
+
+
+ + +
diff --git a/src/Gui/View3DInventor.cpp b/src/Gui/View3DInventor.cpp index 999eb24483..11a722fbdf 100644 --- a/src/Gui/View3DInventor.cpp +++ b/src/Gui/View3DInventor.cpp @@ -58,6 +58,8 @@ #include #include +#include + #include "View3DInventor.h" #include "View3DSettings.h" #include "Application.h" @@ -254,8 +256,9 @@ void View3DInventor::printPdf() if (!filename.isEmpty()) { Gui::WaitCursor wc; QPrinter printer(QPrinter::ScreenResolution); - // setPdfVersion sets the printied PDF Version to comply with PDF/A-1b, more details under: https://www.kdab.com/creating-pdfa-documents-qt/ - printer.setPdfVersion(QPagedPaintDevice::PdfVersion_A1b); + // setPdfVersion sets the printed PDF Version to what is chosen in Preferences/Import-Export/PDF + // more details under: https://www.kdab.com/creating-pdfa-documents-qt/ + printer.setPdfVersion(Gui::Dialog::DlgSettingsPDF::evaluatePDFVersion()); printer.setOutputFormat(QPrinter::PdfFormat); printer.setPageOrientation(QPageLayout::Landscape); printer.setOutputFileName(filename); diff --git a/src/Gui/resource.cpp b/src/Gui/resource.cpp index cdf3485ccd..f0d630a281 100644 --- a/src/Gui/resource.cpp +++ b/src/Gui/resource.cpp @@ -46,6 +46,7 @@ #include "PreferencePages/DlgSettingsViewColor.h" #include "PreferencePages/DlgSettingsWorkbenchesImp.h" #include "PreferencePages/DlgSettingsAdvanced.h" +#include "PreferencePages/DlgSettingsPDF.h" #include "Dialogs/DlgToolbarsImp.h" #include "Dialogs/DlgActionsImp.h" @@ -88,6 +89,7 @@ WidgetFactorySupplier::WidgetFactorySupplier() new PrefPageProducer ( QT_TRANSLATE_NOOP("QObject","Display") ); DlgSettingsUI::attachObserver(); new PrefPageProducer ( QT_TRANSLATE_NOOP("QObject","Workbenches") ); + new PrefPageProducer ( QT_TRANSLATE_NOOP("QObject","Import-Export") ); new PrefPageProducer ( QT_TRANSLATE_NOOP("QObject", "Python")); new PrefPageProducer ( QT_TRANSLATE_NOOP("QObject", "Python")); new PrefPageProducer ( QT_TRANSLATE_NOOP("QObject", "Python")); diff --git a/src/Mod/Spreadsheet/Gui/SpreadsheetView.cpp b/src/Mod/Spreadsheet/Gui/SpreadsheetView.cpp index c734b51386..c4cab0eaed 100644 --- a/src/Mod/Spreadsheet/Gui/SpreadsheetView.cpp +++ b/src/Mod/Spreadsheet/Gui/SpreadsheetView.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include @@ -302,9 +303,10 @@ void SheetView::printPdf() QStringLiteral("%1 (*.pdf)").arg(tr("PDF file"))); if (!filename.isEmpty()) { QPrinter printer(QPrinter::ScreenResolution); - // setPdfVersion sets the printied PDF Version to comply with PDF/A-1b, more details under: + // setPdfVersion sets the printed PDF Version to what is chosen in + // Preferences/Import-Export/PDF more details under: // https://www.kdab.com/creating-pdfa-documents-qt/ - printer.setPdfVersion(QPagedPaintDevice::PdfVersion_A1b); + printer.setPdfVersion(Gui::Dialog::DlgSettingsPDF::evaluatePDFVersion()); printer.setPageOrientation(QPageLayout::Landscape); printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFileName(filename); diff --git a/src/Mod/TechDraw/Gui/PagePrinter.cpp b/src/Mod/TechDraw/Gui/PagePrinter.cpp index 52c00216e8..024cdee61e 100644 --- a/src/Mod/TechDraw/Gui/PagePrinter.cpp +++ b/src/Mod/TechDraw/Gui/PagePrinter.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include @@ -183,9 +184,9 @@ void PagePrinter::printAllPdf(QPrinter* printer, App::Document* doc) QString documentName = QString::fromUtf8(doc->getName()); QPdfWriter pdfWriter(outputFile); - // set the printed PDF Version to comply with PDF/A-1b, more details under: - // https://www.kdab.com/creating-pdfa-documents-qt/ - pdfWriter.setPdfVersion(QPagedPaintDevice::PdfVersion_A1b); + // setPdfVersion sets the printed PDF Version to what is chosen in Preferences/Import-Export/PDF + // more details under: https://www.kdab.com/creating-pdfa-documents-qt/ + pdfWriter.setPdfVersion(Gui::Dialog::DlgSettingsPDF::evaluatePDFVersion()); pdfWriter.setTitle(documentName); pdfWriter.setCreator(QString::fromStdString(App::Application::getNameWithVersion()) @@ -352,7 +353,7 @@ void PagePrinter::printPdf(ViewProviderPage* vpPage, const std::string& file) // set up the pdfwriter QString outputFile = QString::fromStdString(filespec); QPdfWriter pdfWriter(outputFile); - pdfWriter.setPdfVersion(QPagedPaintDevice::PdfVersion_A1b); + pdfWriter.setPdfVersion(Gui::Dialog::DlgSettingsPDF::evaluatePDFVersion()); QPageLayout pageLayout = pdfWriter.pageLayout(); auto marginsdb = pageLayout.margins(QPageLayout::Millimeter); QString documentName = QString::fromUtf8(vpPage->getDrawPage()->getNameInDocument());