Bug 124192 - KPDF ignores user specified margins
Summary: KPDF ignores user specified margins
Status: RESOLVED FIXED
Alias: None
Product: kpdf
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: unspecified Linux
: NOR normal (vote)
Target Milestone: ---
Assignee: Albert Astals Cid
URL:
Keywords:
: 131990 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-03-24 16:44 UTC by Jean-Marc Tremeaux
Modified: 2006-12-10 23:48 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jean-Marc Tremeaux 2006-03-24 16:44:54 UTC
Version:           0.5.1 (using KDE 3.5.1, Debian Package 4:3.5.1-4 (testing/unstable))
Compiler:          Target: i486-linux-gnu
OS:                Linux (i686) release 2.6.15.6

When manually setting margins in print -> properties, KPDF ignores them.
I have some PDF documents with too short margins, so the text on the border is eaten.

How to reproduce :
- Open PDF file (in kpdf or konqui's kpdf part)
- Print -> Properties -> Margins
- Set big margins (e.g. 6cm)
- Click OK
- Check preview and hit "print"

Also, margins are never saved. When I come back into the margins dialog, "use personalized margins" is checked and all margins are set to 0.

Note that I tried the same with konqui/khtml and it works fine, including saving the margins.
Comment 1 Burt Bicksler 2006-07-06 19:43:06 UTC
I see the same thing, running on Fedora Core 4.  Margin settings appear to be applied in the tab, and appear to be saved.  But when you print the margins are not being applied, and after printing when you open the dialog tab again the custom margin values have been reset to 0 again.

KDF 0.5.3

Comment 2 Theodor Milkov 2006-10-10 16:48:08 UTC
I have the same problem as well: kpdf 3.5.4-0ubuntu2
Comment 3 Ryan Volz 2006-10-30 05:28:49 UTC
I can confirm that this is still an issue with KPDF 0.5.5 (Gentoo).  Other KDE applications honor and save the margins correctly.
Comment 4 Pino Toscano 2006-11-09 23:26:58 UTC
*** Bug 131990 has been marked as a duplicate of this bug. ***
Comment 5 Albert Astals Cid 2006-11-17 23:16:12 UTC
SVN commit 605710 by aacid:

Fix kpdf ignoring user defined margins when printing

@translators, it introduces a four new messages, hope it's ok for you, if not please shout and i will revert the change.

BUGS: 124192
CCMAIL: kde-i18n-doc@kde.org


 M  +27 -5     core/generator_pdf/generator_pdf.cpp  
 M  +0 -2      part.cpp  


--- branches/KDE/3.5/kdegraphics/kpdf/core/generator_pdf/generator_pdf.cpp #605709:605710
@@ -409,14 +409,21 @@
 bool PDFGenerator::print( KPrinter& printer )
 {
     QString ps = printer.option("PageSize");
+    int paperWidth, paperHeight;
+    int marginTop, marginLeft, marginRight, marginBottom;
+    marginTop = (int)printer.option("kde-margin-top").toDouble();
+    marginLeft = (int)printer.option("kde-margin-left").toDouble();
+    marginRight = (int)printer.option("kde-margin-right").toDouble();
+    marginBottom = (int)printer.option("kde-margin-bottom").toDouble();
+
     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());
+        paperWidth = ps.left(hPos).toInt();
+        paperHeight = ps.mid(hPos+1).toInt();
     }
     else
     {
@@ -426,17 +433,32 @@
         dummy.setPageSize((QPrinter::PageSize)(ps.isEmpty() ? KGlobal::locale()->pageSize() : pageNameToPageSize(ps)));
 
         QPaintDeviceMetrics metrics(&dummy);
-        globalParams->setPSPaperWidth(metrics.width());
-        globalParams->setPSPaperHeight(metrics.height());
+        paperWidth = metrics.width();
+        paperHeight = metrics.height();
     }
 
     KTempFile tf( QString::null, ".ps" );
-    PSOutputDev *psOut = new PSOutputDev(tf.name().latin1(), pdfdoc->getXRef(), pdfdoc->getCatalog(), 1, pdfdoc->getNumPages(), psModePS);
+    globalParams->setPSPaperWidth(paperWidth);
+    globalParams->setPSPaperHeight(paperHeight);
+    PSOutputDev *psOut = new PSOutputDev(tf.name().latin1(), pdfdoc->getXRef(), pdfdoc->getCatalog(), 1, pdfdoc->getNumPages(), psModePS, marginRight, marginBottom, paperWidth - marginLeft, paperHeight - marginTop);
 
     if (psOut->isOk())
     {
         std::list<int> pages;
 
+        double xScale = ((double)paperWidth - (double)marginLeft - (double)marginRight) / (double)paperWidth;
+        double yScale = ((double)paperHeight - (double)marginBottom - (double)marginTop) / (double)paperHeight;
+
+        if ( abs((int)(xScale * 100) - (int)(yScale * 100)) > 5 ) {
+            int result = KMessageBox::questionYesNo(0,
+                                       i18n("The margins you specified are changing the page aspect ratio. Do you want to print with the aspect ratio changed or do you want the margins to be adapted so that aspect ratio is preserved?"),
+                                       i18n("Aspect ratio change"),
+                                       i18n("Print with specified margins"),
+                                       i18n("Print adapting margins to keep aspect ratio"),
+                                       "kpdfStrictlyObeyMargins");
+            if (result == KMessageBox::Yes) psOut->setScale(xScale, yScale);
+        }
+
         if (!printer.previewOnly())
         {
             QValueList<int> pageList = printer.pageList();
--- branches/KDE/3.5/kdegraphics/kpdf/part.cpp #605709:605710
@@ -791,7 +791,6 @@
 
     printer.setMinMax(1, m_document->pages());
     printer.setPreviewOnly( true );
-    printer.setMargins(0, 0, 0, 0);
 
     // if some pages are landscape and others are not the most common win as kprinter does
     // not accept a per page setting
@@ -923,7 +922,6 @@
     printer.setPageSelection(KPrinter::ApplicationSide);
     printer.setMinMax(1, m_document->pages());
     printer.setCurrentPage(m_document->currentPage()+1);
-    printer.setMargins(0, 0, 0, 0);
 
     // if some pages are landscape and others are not the most common win as kprinter does
     // not accept a per page setting
Comment 6 richlv 2006-12-06 17:24:36 UTC
ooooh... i was battling this problem for quite some time and was not sure whether it's me, ppd file or whatnot...
thanks for this fix. in which kde version could we see this ?
Comment 7 Albert Astals Cid 2006-12-10 23:48:45 UTC
Should be there with KDE 3.5.6