@ -32,6 +32,7 @@
# include <QtCore>
# include <QtSvg>
# include <QPrinter>
# include <QPdfWriter>
# include "core/UBApplication.h"
# include "core/UBSettings.h"
@ -40,6 +41,7 @@
# include "domain/UBGraphicsScene.h"
# include "domain/UBGraphicsSvgItem.h"
# include "domain/UBGraphicsPDFItem.h"
# include "document/UBDocumentProxy.h"
@ -66,14 +68,14 @@ void UBExportPDF::persist(UBDocumentProxy* pDocumentProxy)
bool UBExportPDF : : persistsDocument ( UBDocumentProxy * pDocumentProxy , const QString & filename )
{
QPrinter pdfPrinter ;
QPdfWriter pdfWriter ( filename ) ;
qDebug ( ) < < " exporting document to PDF " < < filename ;
pdfPrinter . setOutputFormat ( QPrinter : : PdfFormat ) ;
pdfPrinter . setResolution ( UBSettings : : settings ( ) - > pdfResolution - > get ( ) . toInt ( ) ) ;
pdfPrinter . setOutputFileName ( filename ) ;
pdfPrinter . setFullPage ( true ) ;
pdfWriter . setResolution ( UBSettings : : settings ( ) - > pdfResolution - > get ( ) . toInt ( ) ) ;
pdfWriter . setPageMargins ( QMarginsF ( ) ) ;
pdfWriter . setTitle ( pDocumentProxy - > name ( ) ) ;
pdfWriter . setCreator ( " OpenBoard PDF export " ) ;
//need to calculate screen resolution
QDesktopWidget * desktop = UBApplication : : desktop ( ) ;
@ -85,37 +87,48 @@ bool UBExportPDF::persistsDocument(UBDocumentProxy* pDocumentProxy, const QStrin
int existingPageCount = pDocumentProxy - > pageCount ( ) ;
for ( int pageIndex = 0 ; pageIndex < existingPageCount ; pageIndex + + )
{
for ( int pageIndex = 0 ; pageIndex < existingPageCount ; pageIndex + + ) {
UBGraphicsScene * scene = UBPersistenceManager : : persistenceManager ( ) - > loadDocumentScene ( pDocumentProxy , pageIndex ) ;
UBApplication : : showMessage ( tr ( " Exporting page %1 of %2 " ) . arg ( pageIndex + 1 ) . arg ( existingPageCount ) ) ;
// set background to white, no crossing for PDF output
bool isDark = scene - > isDarkBackground ( ) ;
bool isCrossed = scene - > isCrossedBackground ( ) ;
scene - > setBackground ( false , false ) ;
QSize pageSize = scene - > nominalSize ( ) ;
// 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 ( ) ;
// set high res rendering
scene - > setRenderingQuality ( UBItem : : RenderingQualityHigh ) ;
scene - > setRenderingContext ( UBGraphicsScene : : NonScreen ) ;
//setting page size to appropriate value
pdfPrinter . setPaperSize ( QSizeF ( pageSize . width ( ) * scaleFactor , pageSize . height ( ) * scaleFactor ) , QPrinter : : Point ) ;
if ( painterNeedsBegin ) painterNeedsBegin = ! pdfPainter . begin ( & pdfPrinter ) ;
//render to PDF
scene - > render ( & pdfPainter , QRectF ( ) , scene - > normalizedSceneRect ( ) ) ;
// Setting output page size
QPageSize outputPageSize = QPageSize ( QSizeF ( pageSize . width ( ) * scaleFactor , pageSize . height ( ) * scaleFactor ) , QPageSize : : Point ) ;
pdfWriter . setPageSize ( outputPageSize ) ;
// Call begin only once
if ( painterNeedsBegin )
painterNeedsBegin = ! pdfPainter . begin ( & pdfWriter ) ;
if ( pageIndex < existingPageCount - 1 ) pdfPrinter . newPage ( ) ;
else if ( pageIndex < existingPageCount )
pdfWriter . newPage ( ) ;
//restore screen rendering quality
// Render the scene
scene - > render ( & pdfPainter , QRectF ( ) , scene - > normalizedSceneRect ( ) ) ;
// Restore screen rendering quality
scene - > setRenderingContext ( UBGraphicsScene : : Screen ) ;
scene - > setRenderingQuality ( UBItem : : RenderingQualityNormal ) ;
//r estore background state
// R estore background state
scene - > setBackground ( isDark , isCrossed ) ;
}
if ( ! painterNeedsBegin ) pdfPainter . end ( ) ;
if ( ! painterNeedsBegin )
pdfPainter . end ( ) ;
return true ;
}