Index: okular/core/document.cpp
===================================================================
--- okular/core/document.cpp.orig
+++ okular/core/document.cpp
@@ -3373,6 +3373,28 @@ bool Document::saveDocumentArchive( cons
     return true;
 }
 
+QPrinter::Orientation Document::orientation() const
+{
+    double width, height;
+    int landscape, portrait;
+    const Okular::Page *currentPage;
+
+    // if some pages are landscape and others are not, the most common wins, as
+    // QPrinter does not accept a per-page setting
+    landscape = 0;
+    portrait = 0;
+    for (uint i = 0; i < pages(); i++)
+    {
+        currentPage = page(i);
+        width = currentPage->width();
+        height = currentPage->height();
+        if (currentPage->orientation() == Okular::Rotation90 || currentPage->orientation() == Okular::Rotation270) qSwap(width, height);
+        if (width > height) landscape++;
+        else portrait++;
+    }
+    return (landscape > portrait) ? QPrinter::Landscape : QPrinter::Portrait;
+}
+
 void DocumentPrivate::requestDone( PixmapRequest * req )
 {
     if ( !req )
Index: okular/core/document.h
===================================================================
--- okular/core/document.h.orig
+++ okular/core/document.h
@@ -19,11 +19,11 @@
 #include <QtCore/QObject>
 #include <QtCore/QStringList>
 #include <QtCore/QVector>
+#include <QtGui/QPrinter>
 #include <QtXml/QDomDocument>
 
 #include <kmimetype.h>
 
-class QPrinter;
 class QPrintDialog;
 class KComponentData;
 class KBookmark;
@@ -579,6 +579,16 @@ class OKULAR_EXPORT Document : public QO
          */
         bool saveDocumentArchive( const QString &fileName );
 
+        /**
+         * Returns the orientation of the document (for printing purposes). This
+         * is used in the KPart to initialize the print dialog and in the
+         * generators to check whether the document needs to be rotated or not.
+         *
+         * @since 0.14 (KDE 4.8)
+         */
+        QPrinter::Orientation orientation() const;
+
+
     public Q_SLOTS:
         /**
          * This slot is called whenever the user changes the @p rotation of
Index: okular/core/fileprinter.cpp
===================================================================
--- okular/core/fileprinter.cpp.orig
+++ okular/core/fileprinter.cpp
@@ -33,22 +33,44 @@
 
 using namespace Okular;
 
+// Deprecated overload for binary compatibility
 int FilePrinter::printFile( QPrinter &printer, const QString file, FileDeletePolicy fileDeletePolicy,
                             PageSelectPolicy pageSelectPolicy, const QString &pageRange )
 {
+    return printFile( printer, file, QPrinter::Portrait, fileDeletePolicy, pageSelectPolicy, pageRange );
+}
+
+int FilePrinter::printFile( QPrinter &printer, const QString file,
+                            QPrinter::Orientation documentOrientation, FileDeletePolicy fileDeletePolicy,
+                            PageSelectPolicy pageSelectPolicy, const QString &pageRange )
+{
     FilePrinter fp;
-    return fp.doPrintFiles( printer, QStringList( file ), fileDeletePolicy, pageSelectPolicy, pageRange );
+    return fp.doPrintFiles( printer, QStringList( file ), fileDeletePolicy, pageSelectPolicy, pageRange,
+                            documentOrientation );
 }
 
+// Deprecated function kept for binary compatibility
+// This is deprecated because it cannot support different original orientations
+// for each document in the list.
 int FilePrinter::printFiles( QPrinter &printer, const QStringList &fileList, FileDeletePolicy fileDeletePolicy )
 {
     FilePrinter fp;
-    return fp.doPrintFiles( printer, fileList, fileDeletePolicy, FilePrinter::ApplicationSelectsPages, QString() );
+    return fp.doPrintFiles( printer, fileList, fileDeletePolicy, FilePrinter::ApplicationSelectsPages, QString(),
+                            QPrinter::Portrait );
 }
 
+// Deprecated overload for binary compatibility
 int FilePrinter::doPrintFiles( QPrinter &printer, QStringList fileList, FileDeletePolicy fileDeletePolicy,
                                PageSelectPolicy pageSelectPolicy, const QString &pageRange )
 {
+    return doPrintFiles( printer, fileList, fileDeletePolicy, pageSelectPolicy, pageRange,
+                         QPrinter::Portrait );
+}
+
+int FilePrinter::doPrintFiles( QPrinter &printer, QStringList fileList, FileDeletePolicy fileDeletePolicy,
+                               PageSelectPolicy pageSelectPolicy, const QString &pageRange,
+                               QPrinter::Orientation documentOrientation )
+{
 
     if ( fileList.size() < 1 ) {
         return -8;
@@ -120,7 +142,7 @@ int FilePrinter::doPrintFiles( QPrinter
 
         bool useCupsOptions = cupsAvailable();
         argList = printArguments( printer, fileDeletePolicy, pageSelectPolicy, 
-                                  useCupsOptions, pageRange, exe ) << fileList;
+                                  useCupsOptions, pageRange, exe, documentOrientation ) << fileList;
         kDebug(OkularDebug) << "Executing" << exe << "with arguments" << argList;
 
         ret = KProcess::execute( exe, argList );
@@ -283,11 +305,20 @@ QSize FilePrinter::psPaperSize( QPrinter
 
 
 
-
+// Deprecated overload for binary compatibility
 QStringList FilePrinter::printArguments( QPrinter &printer, FileDeletePolicy fileDeletePolicy,
                                          PageSelectPolicy pageSelectPolicy, bool useCupsOptions,
                                          const QString &pageRange, const QString &version )
 {
+    return printArguments( printer, fileDeletePolicy, pageSelectPolicy, useCupsOptions,
+                           pageRange, version, QPrinter::Portrait );
+}
+
+QStringList FilePrinter::printArguments( QPrinter &printer, FileDeletePolicy fileDeletePolicy,
+                                         PageSelectPolicy pageSelectPolicy, bool useCupsOptions,
+                                         const QString &pageRange, const QString &version,
+                                         QPrinter::Orientation documentOrientation )
+{
     QStringList argList;
 
     if ( ! destination( printer, version ).isEmpty() ) {
@@ -306,8 +337,8 @@ QStringList FilePrinter::printArguments(
         argList << pages( printer, pageSelectPolicy, pageRange, useCupsOptions, version );
     }
 
-    if ( useCupsOptions && ! cupsOptions( printer ).isEmpty() ) {
-        argList << cupsOptions( printer );
+    if ( useCupsOptions && ! cupsOptions( printer, documentOrientation ).isEmpty() ) {
+        argList << cupsOptions( printer, documentOrientation );
     }
 
     if ( ! deleteFile( printer, fileDeletePolicy, version ).isEmpty() ) {
@@ -411,16 +442,22 @@ QStringList FilePrinter::pages( QPrinter
     return QStringList(); // AllPages
 }
 
+// Deprecated overload for binary compatibility
 QStringList FilePrinter::cupsOptions( QPrinter &printer )
 {
+    return cupsOptions( printer, QPrinter::Portrait );
+}
+
+QStringList FilePrinter::cupsOptions( QPrinter &printer, QPrinter::Orientation documentOrientation )
+{
     QStringList optionList;
 
     if ( ! optionMedia( printer ).isEmpty() ) {
         optionList << optionMedia( printer );
     }
 
-    if ( ! optionOrientation( printer ).isEmpty() ) {
-        optionList << optionOrientation( printer );
+    if ( ! optionOrientation( printer, documentOrientation ).isEmpty() ) {
+        optionList << optionOrientation( printer, documentOrientation );
     }
 
     if ( ! optionDoubleSidedPrinting( printer ).isEmpty() ) {
@@ -524,12 +561,23 @@ QString FilePrinter::mediaPaperSource( Q
     }
 }
 
+// Deprecated overload for binary compatibility
 QStringList FilePrinter::optionOrientation( QPrinter &printer )
 {
-    switch ( printer.orientation() ) {
-    case QPrinter::Portrait:   return QStringList("-o") << "portrait";
-    case QPrinter::Landscape:  return QStringList("-o") << "landscape";
-    default:                   return QStringList();
+    return optionOrientation( printer, QPrinter::Portrait );
+}
+
+QStringList FilePrinter::optionOrientation( QPrinter &printer, QPrinter::Orientation documentOrientation )
+{
+    // portrait and landscape options rotate the document according to the document orientation
+    // If we want to print a landscape document as one would expect it, we have to pass the
+    // portrait option so that the document is not rotated additionaly
+    if ( printer.orientation() == documentOrientation ) {
+        // the user wants the document printed as is
+        return QStringList("-o") << "portrait";
+    } else {
+        // the user expects the document being rotated by 90 degrees
+        return QStringList("-o") << "landscape";
     }
 }
 
Index: okular/core/fileprinter.h
===================================================================
--- okular/core/fileprinter.h.orig
+++ okular/core/fileprinter.h
@@ -16,10 +16,13 @@
 
 #include <QtCore/QList>
 #include <QtCore/QString>
+#include <QtGui/QPrinter>
+
+// For KDE_DEPRECATED
+#include <kdemacros.h>
 
 #include <okular/core/okular_export.h>
 
-class QPrinter;
 class QSize;
 
 namespace Okular {
@@ -51,9 +54,12 @@ public:
      *
      *  Only supports CUPS and LPR on *NIX.  Page Range only supported in CUPS.
      *  Most settings unsupported by LPR, some settings unsupported by CUPS.
+     *  The documentOrientation parameter was added in version 0.14.
+     *
      *
      * @param printer the print settings to use
      * @param file the file to print
+     * @param documentOrientation the orientation stored in the document itself
      * @param fileDeletePolicy if the application or system deletes the file
      * @param pageSelectPolicy if the application or system selects the pages to print
      * @param pageRange page range to print if SystemSlectsPages and user chooses Selection in Print Dialog
@@ -66,13 +72,45 @@ public:
      *          -2 if the KProcess could not be started
      *          -1 if the KProcess crashed
      *          otherwise the KProcess exit code
+     *
+     * @since 0.14 (KDE 4.8)
      */
 
     static int printFile( QPrinter &printer, const QString file,
+                          QPrinter::Orientation documentOrientation,
                           FileDeletePolicy fileDeletePolicy = FilePrinter::ApplicationDeletesFiles,
                           PageSelectPolicy pageSelectPolicy = FilePrinter::ApplicationSelectsPages,
                           const QString &pageRange = QString() );
 
+    /** Print a file using the settings in QPrinter (compatibility overload)
+     *
+     *  Only supports CUPS and LPR on *NIX.  Page Range only supported in CUPS.
+     *  Most settings unsupported by LPR, some settings unsupported by CUPS.
+     *
+     * @param printer the print settings to use
+     * @param file the file to print
+     * @param fileDeletePolicy if the application or system deletes the file
+     * @param pageSelectPolicy if the application or system selects the pages to print
+     * @param pageRange page range to print if SystemSlectsPages and user chooses Selection in Print Dialog
+     *
+     * @returns Returns exit code:
+     *          -9 if lpr not found
+     *          -8 if empty file name
+     *          -7 if unable to find file
+     *          -6 if invalid printer state
+     *          -5 if print to file copy failed
+     *          -2 if the KProcess could not be started
+     *          -1 if the KProcess crashed
+     *          otherwise the KProcess exit code
+     *
+     * @deprecated Use the overload which takes the documentOrientation instead.
+     */
+
+    static KDE_DEPRECATED int printFile( QPrinter &printer, const QString file,
+                                         FileDeletePolicy fileDeletePolicy = FilePrinter::ApplicationDeletesFiles,
+                                         PageSelectPolicy pageSelectPolicy = FilePrinter::ApplicationSelectsPages,
+                                         const QString &pageRange = QString() );
+
     /** Print a list of files using the settings in QPrinter
      *
      *  Only supports CUPS and LPR on *NIX.
@@ -90,9 +128,11 @@ public:
      *          -2 if the KProcess could not be started
      *          -1 if the KProcess crashed
      *          otherwise the KProcess exit code
+     *
+     * @deprecated Use printFile instead, passing the documentOrientation for each file.
      */
 
-    static int printFiles( QPrinter &printer, const QStringList &fileList,
+    static KDE_DEPRECATED int printFiles( QPrinter &printer, const QStringList &fileList,
                            FileDeletePolicy fileDeletePolicy = FilePrinter::ApplicationDeletesFiles );
 
     /** Return the list of pages selected by the user in the Print Dialog
@@ -149,14 +189,23 @@ protected:
     bool detectCupsService();
     bool detectCupsConfig();
 
-    int doPrintFiles( QPrinter &printer, const QStringList fileList,
+    KDE_DEPRECATED int doPrintFiles( QPrinter &printer, const QStringList fileList,
                              FileDeletePolicy fileDeletePolicy, PageSelectPolicy pageSelectPolicy,
                              const QString &pageRange );
+    int doPrintFiles( QPrinter &printer, const QStringList fileList,
+                             FileDeletePolicy fileDeletePolicy, PageSelectPolicy pageSelectPolicy,
+                             const QString &pageRange,
+                             QPrinter::Orientation documentOrientation );
 
-    QStringList printArguments( QPrinter &printer,
+    KDE_DEPRECATED QStringList printArguments( QPrinter &printer,
                                        FileDeletePolicy fileDeletePolicy, PageSelectPolicy pageSelectPolicy,
                                        bool useCupsOptions, const QString &pageRange, const QString &version );
 
+    QStringList printArguments( QPrinter &printer,
+                                        FileDeletePolicy fileDeletePolicy, PageSelectPolicy pageSelectPolicy,
+                                       bool useCupsOptions, const QString &pageRange, const QString &version,
+                                       QPrinter::Orientation documentOrientation );
+
     QStringList destination( QPrinter &printer, const QString &version );
     QStringList copies( QPrinter &printer, const QString &version );
     QStringList jobname( QPrinter &printer, const QString &version );
@@ -165,11 +214,13 @@ protected:
     QStringList pages( QPrinter &printer, PageSelectPolicy pageSelectPolicy,
                               const QString &pageRange, bool useCupsOptions, const QString &version );
 
-    QStringList cupsOptions( QPrinter &printer );
+    KDE_DEPRECATED QStringList cupsOptions( QPrinter &printer );
+    QStringList cupsOptions( QPrinter &printer, QPrinter::Orientation documentOrientation );
     QStringList optionMedia( QPrinter &printer );
     QString mediaPageSize( QPrinter &printer );
     QString mediaPaperSource( QPrinter &printer );
-    QStringList optionOrientation( QPrinter &printer );
+    KDE_DEPRECATED QStringList optionOrientation( QPrinter &printer );
+    QStringList optionOrientation( QPrinter &printer, QPrinter::Orientation documentOrientation );
     QStringList optionDoubleSidedPrinting( QPrinter &printer );
     QStringList optionPageOrder( QPrinter &printer );
     QStringList optionCollateCopies( QPrinter &printer );
Index: okular/generators/djvu/generator_djvu.cpp
===================================================================
--- okular/generators/djvu/generator_djvu.cpp.orig
+++ okular/generators/djvu/generator_djvu.cpp
@@ -216,7 +216,7 @@ bool DjVuGenerator::print( QPrinter& pri
         tf.setAutoRemove( false );
         const QString fileName = tf.fileName();
         tf.close();
-        int ret = Okular::FilePrinter::printFile( printer, fileName,
+        int ret = Okular::FilePrinter::printFile( printer, fileName, document()->orientation(),
                                                   Okular::FilePrinter::SystemDeletesFiles,
                                                   Okular::FilePrinter::ApplicationSelectsPages,
                                                   document()->bookmarkedPageRange() );
Index: okular/generators/dvi/dviRenderer.cpp
===================================================================
--- okular/generators/dvi/dviRenderer.cpp.orig
+++ okular/generators/dvi/dviRenderer.cpp
@@ -766,9 +766,9 @@ void dviRenderer::exportPDF()
 }
 
 
-void dviRenderer::exportPS(const QString& fname, const QStringList& options, QPrinter* printer)
+void dviRenderer::exportPS(const QString& fname, const QStringList& options, QPrinter* printer, QPrinter::Orientation orientation)
 {
-  KSharedPtr<DVIExport> exporter(new DVIExportToPS(*this, parentWidget, fname, options, printer));
+  KSharedPtr<DVIExport> exporter(new DVIExportToPS(*this, parentWidget, fname, options, printer, orientation));
   if (exporter->started())
     all_exports_[exporter.data()] = exporter;
 }
Index: okular/generators/dvi/dviRenderer.h
===================================================================
--- okular/generators/dvi/dviRenderer.h.orig
+++ okular/generators/dvi/dviRenderer.h
@@ -29,6 +29,7 @@
 #include <QVector>
 #include <QTimer>
 #include <QMutex>
+#include <QtGui/QPrinter>
 
 class Anchor;
 class DocumentWidget;
@@ -37,7 +38,6 @@ class dviRenderer;
 class ghostscript_interface;
 //class infoDialog;
 class QEventLoop;
-class QPrinter;
 class KProgressDialog;
 class PreBookmark;
 class TeXFontDefinition;
@@ -154,7 +154,7 @@ public:
 //void          editor_finished(const DVISourceEditor*);
 
 public slots:
-  void          exportPS(const QString& fname = QString(), const QStringList& options = QStringList(), QPrinter* printer = 0);
+  void          exportPS(const QString& fname = QString(), const QStringList& options = QStringList(), QPrinter* printer = 0, QPrinter::Orientation orientation = QPrinter::Portrait);
   void          exportPDF();
 
 //void          showInfo();
Index: okular/generators/dvi/dviexport.cpp
===================================================================
--- okular/generators/dvi/dviexport.cpp.orig
+++ okular/generators/dvi/dviexport.cpp
@@ -287,9 +287,11 @@ DVIExportToPS::DVIExportToPS(dviRenderer
                              QWidget* parent_widget,
                              const QString& output_name,
                              const QStringList& options,
-                             QPrinter* printer)
+                             QPrinter* printer,
+                             QPrinter::Orientation orientation)
   : DVIExport(parent, parent_widget),
-    printer_(printer)
+    printer_(printer),
+    orientation_(orientation)
 {
   // None of these should happen. Paranoia checks.
   if (!parent.dviFile)
@@ -456,7 +458,7 @@ void DVIExportToPS::finished_impl(int ex
     const QFileInfo output(output_name_);
     if (output.exists() && output.isReadable()) {
         // I'm not 100% sure on this, think we still need to select pages in export to ps above
-        Okular::FilePrinter::printFile( (*printer_), output_name_,
+        Okular::FilePrinter::printFile( (*printer_), output_name_, orientation_,
                                 Okular::FilePrinter::ApplicationDeletesFiles,
                                 Okular::FilePrinter::ApplicationSelectsPages,
                                 QString() );
Index: okular/generators/dvi/dviexport.h
===================================================================
--- okular/generators/dvi/dviexport.h.orig
+++ okular/generators/dvi/dviexport.h
@@ -22,11 +22,11 @@
 #include <ksharedptr.h>
 
 #include <QObject>
+#include <QtGui/QPrinter>
 
 
 class dviRenderer;
 class fontProgressDialog;
-class QPrinter;
 class KProcess;
 class QStringList;
 
@@ -124,12 +124,14 @@ public:
    *  passed to the external process's argv command line.
    *  @param printer having generated the PostScript file, it is passed
    *  to @c printer (if not null).
+   *  @param orientation the original orientation of the document
    */
   DVIExportToPS(dviRenderer& parent,
                 QWidget* parent_widget,
                 const QString& output_name,
                 const QStringList& options,
-                QPrinter* printer);
+                QPrinter* printer,
+                QPrinter::Orientation orientation = QPrinter::Portrait);
 
 private:
   virtual void abort_process_impl();
@@ -138,6 +140,7 @@ private:
   QPrinter* printer_;
   QString output_name_;
   QString tmpfile_name_;
+  QPrinter::Orientation orientation_;
 };
 
 #endif
Index: okular/generators/dvi/generator_dvi.cpp
===================================================================
--- okular/generators/dvi/generator_dvi.cpp.orig
+++ okular/generators/dvi/generator_dvi.cpp
@@ -483,7 +483,7 @@ bool DviGenerator::print( QPrinter& prin
 
     QEventLoop el;
     m_dviRenderer->setEventLoop( &el );
-    m_dviRenderer->exportPS( tf.fileName(), printOptions, &printer );
+    m_dviRenderer->exportPS( tf.fileName(), printOptions, &printer, document()->orientation() );
 
     tf.close();
 
Index: okular/generators/poppler/generator_pdf.cpp
===================================================================
--- okular/generators/poppler/generator_pdf.cpp.orig
+++ okular/generators/poppler/generator_pdf.cpp
@@ -919,6 +919,7 @@ bool PDFGenerator::print( QPrinter& prin
         delete psConverter;
         tf.close();
         int ret = Okular::FilePrinter::printFile( printer, tempfilename,
+                                                  document()->orientation(),
                                                   Okular::FilePrinter::SystemDeletesFiles,
                                                   Okular::FilePrinter::ApplicationSelectsPages,
                                                   document()->bookmarkedPageRange() );
Index: okular/generators/spectre/generator_ghostview.cpp
===================================================================
--- okular/generators/spectre/generator_ghostview.cpp.orig
+++ okular/generators/spectre/generator_ghostview.cpp
@@ -144,7 +144,7 @@ bool GSGenerator::print( QPrinter& print
     if ( exportStatus == SPECTRE_STATUS_SUCCESS && endStatus == SPECTRE_STATUS_SUCCESS )
     {
         tf.setAutoRemove( false );
-        int ret = Okular::FilePrinter::printFile( printer, fileName,
+        int ret = Okular::FilePrinter::printFile( printer, fileName, document()->orientation(),
                                                   Okular::FilePrinter::SystemDeletesFiles,
                                                   Okular::FilePrinter::ApplicationSelectsPages,
                                                   document()->bookmarkedPageRange() );
Index: okular/part.cpp
===================================================================
--- okular/part.cpp.orig
+++ okular/part.cpp
@@ -1939,24 +1939,7 @@ void Part::slotPrint()
 
 void Part::setupPrint( QPrinter &printer )
 {
-    double width, height;
-    int landscape, portrait;
-    const Okular::Page *page;
-
-    // if some pages are landscape and others are not the most common win as QPrinter does
-    // not accept a per page setting
-    landscape = 0;
-    portrait = 0;
-    for (uint i = 0; i < m_document->pages(); i++)
-    {
-        page = m_document->page(i);
-        width = page->width();
-        height = page->height();
-        if (page->orientation() == Okular::Rotation90 || page->orientation() == Okular::Rotation270) qSwap(width, height);
-        if (width > height) landscape++;
-        else portrait++;
-    }
-    if (landscape > portrait) printer.setOrientation(QPrinter::Landscape);
+    printer.setOrientation(m_document->orientation());
 
     // title
     QString title = m_document->metaData( "DocumentTitle" ).toString();
