trying to restore pdf-merger

preferencesAboutTextFull
Clément Fauconnier 2 years ago
parent d562cd103e
commit bee87e38d5
  1. 50
      src/adaptors/UBExportFullPDF.cpp
  2. 9
      src/pdf-merger/Parser.cpp

@ -82,7 +82,55 @@ void UBExportFullPDF::saveOverlayPdf(UBDocumentProxy* pDocumentProxy, const QStr
if (!pDocumentProxy || filename.length() == 0 || pDocumentProxy->pageCount() == 0)
return;
mSimpleExporter->persistsDocument(pDocumentProxy, filename);
//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);
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();
scene->setBackground(false, UBPageBackground::plain);
// set high res rendering
scene->setRenderingQuality(UBItem::RenderingQualityHigh, UBItem::CacheNotAllowed);
scene->setRenderingContext(UBGraphicsScene::PdfExport);
QSize pageSize = scene->nominalSize();
UBGraphicsPDFItem *pdfItem = qgraphicsitem_cast<UBGraphicsPDFItem*>(scene->backgroundObject());
if (pdfItem) mHasPDFBackgrounds = true;
pdfPrinter.setPaperSize(QSizeF(pageSize.width()*mScaleFactor, pageSize.height()*mScaleFactor), QPrinter::Point);
if (!pdfPainter) pdfPainter = new QPainter(&pdfPrinter);
if (pageIndex != 0) pdfPrinter.newPage();
//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 background state
scene->setDrawingMode(false);
scene->setBackground(isDark, pageBackground);
}
if (pdfPainter) delete pdfPainter;
}

@ -142,7 +142,14 @@ void Parser::_getFileContent(const char * fileName)
{
verPos += strlen(header);
char ver = _fileContent[verPos];
if( ver < '0' || ver > '4' )
/* As every previous standard is contained in newer ones, a lot of documents that would not use
* features > 1.4 are probably correctly exportable. Some optimizations and fixes have been added since 1.4, but after some tests I didn't encountered any issues.
* As an attempt (until 1.5 to 1.7 version can be really supported)to measure what would be the impact of using this library as-is,
* we allow document with version > 1.4 to be parsed by it.
* The big advantage to using it is that exported PDFs are real PDFs (with searchable content), not heavy images.
* If an exception is thrown, actual behavior (heavy images) is used.
*/
if( ver < '0' || ver > '7' )
{
stringstream errorMsg;
errorMsg<<" File with verion 1."<<ver<<" is not currently supported by merge library\n";

Loading…
Cancel
Save