|
|
@ -82,67 +82,84 @@ void UBExportFullPDF::saveOverlayPdf(UBDocumentProxy* pDocumentProxy, const QStr |
|
|
|
if (!pDocumentProxy || filename.length() == 0 || pDocumentProxy->pageCount() == 0) |
|
|
|
if (!pDocumentProxy || filename.length() == 0 || pDocumentProxy->pageCount() == 0) |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
//PDF
|
|
|
|
/*
|
|
|
|
qDebug() << "exporting document to PDF Merger" << filename; |
|
|
|
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. |
|
|
|
QPrinter pdfPrinter; |
|
|
|
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.setOutputFormat(QPrinter::PdfFormat); |
|
|
|
pdfPrinter.setResolution(UBSettings::settings()->pdfResolution->get().toInt()); |
|
|
|
pdfPrinter.setResolution(UBSettings::settings()->pdfResolution->get().toInt()); |
|
|
|
pdfPrinter.setOutputFileName(filename); |
|
|
|
pdfPrinter.setOutputFileName(filename); |
|
|
|
pdfPrinter.setFullPage(true); |
|
|
|
pdfPrinter.setFullPage(true); |
|
|
|
|
|
|
|
|
|
|
|
QPainter* pdfPainter = 0; |
|
|
|
QPainter* pdfPainter = 0; |
|
|
|
|
|
|
|
|
|
|
|
for(int pageIndex = 0 ; pageIndex < pDocumentProxy->pageCount(); pageIndex++) |
|
|
|
for(int pageIndex = 0 ; pageIndex < pDocumentProxy->pageCount(); pageIndex++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
UBGraphicsScene* scene = UBPersistenceManager::persistenceManager()->loadDocumentScene(pDocumentProxy, pageIndex); |
|
|
|
UBGraphicsScene* scene = UBPersistenceManager::persistenceManager()->loadDocumentScene(pDocumentProxy, pageIndex); |
|
|
|
// set background to white, no grid for PDF output
|
|
|
|
// set background to white, no grid for PDF output
|
|
|
|
bool isDark = scene->isDarkBackground(); |
|
|
|
bool isDark = scene->isDarkBackground(); |
|
|
|
UBPageBackground pageBackground = scene->pageBackground(); |
|
|
|
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()) |
|
|
|
if (UBSettings::settings()->exportBackgroundGrid->get().toBool()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
scene->setBackground(exportDark, pageBackground); |
|
|
|
scene->setBackground(exportDark, pageBackground); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
scene->setBackground(exportDark, UBPageBackground::plain); |
|
|
|
scene->setBackground(exportDark, UBPageBackground::plain); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// set high res rendering
|
|
|
|
// set high res rendering
|
|
|
|
scene->setRenderingQuality(UBItem::RenderingQualityHigh, UBItem::CacheNotAllowed); |
|
|
|
scene->setRenderingQuality(UBItem::RenderingQualityHigh, UBItem::CacheNotAllowed); |
|
|
|
scene->setRenderingContext(UBGraphicsScene::PdfExport); |
|
|
|
scene->setRenderingContext(UBGraphicsScene::PdfExport); |
|
|
|
|
|
|
|
|
|
|
|
// pageSize is the output PDF page size; it is set to equal the scene's boundary size; if the contents
|
|
|
|
// 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.
|
|
|
|
// of the scene overflow from the boundaries, they will be scaled down.
|
|
|
|
QSize pageSize = scene->sceneSize(); |
|
|
|
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
|
|
|
|
//render to PDF
|
|
|
|
scene->setDrawingMode(true); |
|
|
|
scene->setDrawingMode(true); |
|
|
|
scene->render(pdfPainter, QRectF(), scene->normalizedSceneRect()); |
|
|
|
scene->render(pdfPainter, QRectF(), scene->normalizedSceneRect()); |
|
|
|
|
|
|
|
|
|
|
|
//restore screen rendering quality
|
|
|
|
//restore screen rendering quality
|
|
|
|
scene->setRenderingContext(UBGraphicsScene::Screen); |
|
|
|
scene->setRenderingContext(UBGraphicsScene::Screen); |
|
|
|
scene->setRenderingQuality(UBItem::RenderingQualityNormal, UBItem::CacheAllowed); |
|
|
|
scene->setRenderingQuality(UBItem::RenderingQualityNormal, UBItem::CacheAllowed); |
|
|
|
|
|
|
|
|
|
|
|
//restore background state
|
|
|
|
//restore background state
|
|
|
|
scene->setDrawingMode(false); |
|
|
|
scene->setDrawingMode(false); |
|
|
|
scene->setBackground(isDark, pageBackground); |
|
|
|
scene->setBackground(isDark, pageBackground); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (pdfPainter) delete pdfPainter; |
|
|
|
if (pdfPainter) delete pdfPainter; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
mSimpleExporter->persistsDocument(pDocumentProxy, filename); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|