Bug 100003

Summary: kpdf does not respect default kde paper settings
Product: [Applications] kpdf Reporter: Felix Kurth <felix>
Component: generalAssignee: Albert Astals Cid <aacid>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Gentoo Packages   
OS: Linux   
Latest Commit: Version Fixed In:
Attachments: Patch that may fix the page size problem
Second try to fix paper size problem

Description Felix Kurth 2005-02-22 14:52:25 UTC
Version:            (using KDE KDE 3.3.92)
Installed from:    Gentoo Packages
Compiler:          gcc (GCC) 3.4.3 20050110 (Gentoo Linux 3.4.3.20050110, ssp-3.4.3.20050110-0, pie-8.7.7) 
OS:                Linux

Printing any document from kpdf always causes my printer to ask me to insert letter paper. 
But in kde-settings a4 is my default paper type, and the pdfs are in a4. Also the printers (cups) paper size is a4.
This does not happen with acroread, it does not happen with kghostview nor does it happen when printing the pdf on the command line.
Comment 1 Albert Astals Cid 2005-02-22 20:05:51 UTC
True, the code that makes the print is not 100% correct, i'm working on that.
Comment 2 Felix Kurth 2005-02-27 21:11:29 UTC
Its not fixed in rc1. This bug is annoying, you should realy fix it before the 3.4 release.
Comment 3 Albert Astals Cid 2005-02-27 21:15:40 UTC
And you should be more polite. It is not going to be fixed for KDE 3.4.0
Comment 4 Felix Kurth 2005-02-27 21:59:16 UTC
This prevents all non-letter users (even you ?) from printing with kpdf. I would call this a showstoper.
Comment 5 Albert Astals Cid 2005-02-27 22:07:57 UTC
But i don't have a working patch and KDE is not going to stop only for kpdf so it'll have to wait for KDE 3.4.1.

I'll tell you how a dirty fix, create a file called /etc/xpdfrc and put inside of it
psPaperSize             A4
That will make kpdf print allways using A4
Comment 6 Albert Astals Cid 2005-02-27 23:02:20 UTC
Well, i've found that it may not be that hard to fix, are you in position to try a patch?
Comment 7 Albert Astals Cid 2005-02-27 23:06:19 UTC
Created attachment 9875 [details]
Patch that may fix the page size problem

If you don't know how to apply a patch do not hesitate to ask
Comment 8 Felix Kurth 2005-02-27 23:33:08 UTC
Does not work here. Patch applys fine, but it does not solve the problem.
Comment 9 Albert Astals Cid 2005-02-27 23:46:29 UTC
Created attachment 9876 [details]
Second try to fix paper size problem

Well, i did a big error as removed a line to make it look better and forgot to
add it :-(
Please try with this patch.
Comment 10 Felix Kurth 2005-02-28 00:01:00 UTC
You're great man! It seems to work now. My printer doesnt complain now. Will do some further tests tomorow. Thank you very much.
Comment 11 Albert Astals Cid 2005-02-28 19:01:45 UTC
CVS commit by aacid: 

Print to the correct page size
Olaf can you check that fixes your wrong paper format complaining printer too?
CCMAIL: 98837@bugs.kde.org
BUGS: 100003


  M +24 -0     generator_pdf.cpp   1.23


--- kdegraphics/kpdf/core/generator_pdf/generator_pdf.cpp  #1.22:1.23
@@ -14,4 +14,6 @@
 #include <qimage.h>
 #include <qapplication.h>
+#include <qpaintdevicemetrics.h>
+#include <qregexp.h>
 #include <klocale.h>
 #include <kpassdlg.h>
@@ -297,4 +299,26 @@ void PDFGenerator::generateSyncTextPage(
 bool PDFGenerator::print( KPrinter& printer )
 {
+    QString ps = printer.option("PageSize");
+    if (ps.find(QRegExp("w\\d+h\\d+")) == 0)
+    {
+        // size not supported by Qt, KPrinter gives us the size as wWIDTHhHEIGHT
+        // remove the w
+        ps = ps.mid(1);
+        int hPos = ps.find("h");
+        globalParams->setPSPaperWidth(ps.left(hPos).toInt());
+        globalParams->setPSPaperHeight(ps.mid(hPos+1).toInt());
+    }
+    else
+    {
+        // size is supported by Qt, we get either the pageSize name or nothing because the default pageSize is used
+        QPrinter dummy(QPrinter::PrinterResolution);
+        dummy.setFullPage(true);
+        dummy.setPageSize((QPrinter::PageSize)(ps.isEmpty() ? KGlobal::locale()->pageSize() : pageNameToPageSize(ps)));
+
+        QPaintDeviceMetrics metrics(&dummy);
+        globalParams->setPSPaperWidth(metrics.width());
+        globalParams->setPSPaperHeight(metrics.height());
+    }
+
     KTempFile tf( QString::null, ".ps" );
     PSOutputDev *psOut = new PSOutputDev(tf.name().latin1(), pdfdoc->getXRef(), pdfdoc->getCatalog(), 1, pdfdoc->getNumPages(), psModePS);