add a setting to enable/disable pdfMerger use

preferencesAboutTextFull
Clément Fauconnier 3 years ago
parent 41de5ae2f5
commit 0530ab151b
  1. 1
      resources/etc/OpenBoard.config
  2. 107
      src/adaptors/UBExportFullPDF.cpp
  3. 1
      src/core/UBSettings.cpp
  4. 1
      src/core/UBSettings.h

@ -129,6 +129,7 @@ ExportBackgroundColor=false
Margin=20
PageFormat=A4
Resolution=300
UsePDFMerger=true
ZoomBehavior=4
[Podcast]

@ -82,67 +82,84 @@ void UBExportFullPDF::saveOverlayPdf(UBDocumentProxy* pDocumentProxy, const QStr
if (!pDocumentProxy || filename.length() == 0 || pDocumentProxy->pageCount() == 0)
return;
//PDF
qDebug() << "exporting document to PDF Merger" << filename;
QPrinter pdfPrinter;
/*
PDFMerger is supposed to be working only for PDFs using 1.0 to 1.4 standard, but I encountered no issue using 1.7 documents.
Just tested with a few documents though so it could be a total mess to restore it without any possibility to disable it if an issue is encountered
A new setting is introduced to handle that possibility.
Also, calling simpleExporter here instead of the following code was done because I (wrongly) assumed that both codes was doing nearly the same thing, as I never
tested to remove the part of pdf-merger throwing an exception if pdf version is > 1.4 and that calling the following lines without modifying the version check
throws an exception and finally calls simpleExporter->persistsDocument
calling simpleExporter directly also resulted in fixing two issues where pdf overlay could be badly scaled (not matching with scale of annotations)
*/
bool usePDFMerger = UBSettings::settings()->pdfUsePDFMerger->get().toBool();
if (usePDFMerger)
{
//PDF
qDebug() << "exporting document to PDF Merger" << filename;
QPrinter pdfPrinter;
pdfPrinter.setOutputFormat(QPrinter::PdfFormat);
pdfPrinter.setResolution(UBSettings::settings()->pdfResolution->get().toInt());
pdfPrinter.setOutputFileName(filename);
pdfPrinter.setFullPage(true);
pdfPrinter.setOutputFormat(QPrinter::PdfFormat);
pdfPrinter.setResolution(UBSettings::settings()->pdfResolution->get().toInt());
pdfPrinter.setOutputFileName(filename);
pdfPrinter.setFullPage(true);
QPainter* pdfPainter = 0;
QPainter* pdfPainter = 0;
for(int pageIndex = 0 ; pageIndex < pDocumentProxy->pageCount(); pageIndex++)
{
UBGraphicsScene* scene = UBPersistenceManager::persistenceManager()->loadDocumentScene(pDocumentProxy, pageIndex);
// set background to white, no grid for PDF output
bool isDark = scene->isDarkBackground();
UBPageBackground pageBackground = scene->pageBackground();
for(int pageIndex = 0 ; pageIndex < pDocumentProxy->pageCount(); pageIndex++)
{
UBGraphicsScene* scene = UBPersistenceManager::persistenceManager()->loadDocumentScene(pDocumentProxy, pageIndex);
// set background to white, no grid for PDF output
bool isDark = scene->isDarkBackground();
UBPageBackground pageBackground = scene->pageBackground();
bool exportDark = isDark && UBSettings::settings()->exportBackgroundColor->get().toBool();
bool exportDark = isDark && UBSettings::settings()->exportBackgroundColor->get().toBool();
if (UBSettings::settings()->exportBackgroundGrid->get().toBool())
{
scene->setBackground(exportDark, pageBackground);
}
else
{
scene->setBackground(exportDark, UBPageBackground::plain);
}
if (UBSettings::settings()->exportBackgroundGrid->get().toBool())
{
scene->setBackground(exportDark, pageBackground);
}
else
{
scene->setBackground(exportDark, UBPageBackground::plain);
}
// set high res rendering
scene->setRenderingQuality(UBItem::RenderingQualityHigh, UBItem::CacheNotAllowed);
scene->setRenderingContext(UBGraphicsScene::PdfExport);
// set high res rendering
scene->setRenderingQuality(UBItem::RenderingQualityHigh, UBItem::CacheNotAllowed);
scene->setRenderingContext(UBGraphicsScene::PdfExport);
// pageSize is the output PDF page size; it is set to equal the scene's boundary size; if the contents
// of the scene overflow from the boundaries, they will be scaled down.
QSize pageSize = scene->sceneSize();
// pageSize is the output PDF page size; it is set to equal the scene's boundary size; if the contents
// of the scene overflow from the boundaries, they will be scaled down.
QSize pageSize = scene->sceneSize();
UBGraphicsPDFItem *pdfItem = qgraphicsitem_cast<UBGraphicsPDFItem*>(scene->backgroundObject());
UBGraphicsPDFItem *pdfItem = qgraphicsitem_cast<UBGraphicsPDFItem*>(scene->backgroundObject());
if (pdfItem) mHasPDFBackgrounds = true;
if (pdfItem) mHasPDFBackgrounds = true;
pdfPrinter.setPaperSize(QSizeF(pageSize.width()*mScaleFactor, pageSize.height()*mScaleFactor), QPrinter::Point);
pdfPrinter.setPaperSize(QSizeF(pageSize.width()*mScaleFactor, pageSize.height()*mScaleFactor), QPrinter::Point);
if (!pdfPainter) pdfPainter = new QPainter(&pdfPrinter);
if (!pdfPainter) pdfPainter = new QPainter(&pdfPrinter);
if (pageIndex != 0) pdfPrinter.newPage();
if (pageIndex != 0) pdfPrinter.newPage();
//render to PDF
scene->setDrawingMode(true);
scene->render(pdfPainter, QRectF(), scene->normalizedSceneRect());
//render to PDF
scene->setDrawingMode(true);
scene->render(pdfPainter, QRectF(), scene->normalizedSceneRect());
//restore screen rendering quality
scene->setRenderingContext(UBGraphicsScene::Screen);
scene->setRenderingQuality(UBItem::RenderingQualityNormal, UBItem::CacheAllowed);
//restore screen rendering quality
scene->setRenderingContext(UBGraphicsScene::Screen);
scene->setRenderingQuality(UBItem::RenderingQualityNormal, UBItem::CacheAllowed);
//restore background state
scene->setDrawingMode(false);
scene->setBackground(isDark, pageBackground);
}
//restore background state
scene->setDrawingMode(false);
scene->setBackground(isDark, pageBackground);
}
if (pdfPainter) delete pdfPainter;
if (pdfPainter) delete pdfPainter;
}
else
{
mSimpleExporter->persistsDocument(pDocumentProxy, filename);
}
}

@ -405,6 +405,7 @@ void UBSettings::init()
pdfMargin = new UBSetting(this, "PDF", "Margin", "20");
pdfPageFormat = new UBSetting(this, "PDF", "PageFormat", "A4");
pdfUsePDFMerger = new UBSetting(this, "PDF", "UsePDFMerger", "true");
pdfResolution = new UBSetting(this, "PDF", "Resolution", "300");
pdfZoomBehavior = new UBSetting(this, "PDF", "ZoomBehavior", "4");

@ -357,6 +357,7 @@ class UBSettings : public QObject
UBSetting* svgViewBoxMargin;
UBSetting* pdfMargin;
UBSetting* pdfPageFormat;
UBSetting* pdfUsePDFMerger;
UBSetting* pdfResolution;
UBSetting* pdfZoomBehavior;

Loading…
Cancel
Save