diff -ru 20.5\org\apache\fop\render\pdf\PDFRenderer.java namchinov\org\apache\fop\render\pdf\PDFRenderer.java
--- 20.5\org\apache\fop\render\pdf\PDFRenderer.java	Wed Jun 23 17:56:47 2004
+++ namchinov\org\apache\fop\render\pdf\PDFRenderer.java	Tue Nov 04 17:08:56 2003
@@ -376,9 +376,9 @@
                 closeText();
 
                 SVGDocument svg = ((SVGImage) image).getSVGDocument();
-                currentStream.add("ET\nq\n");
+//                currentStream.add("ET\nq\n");
                 renderSVGDocument(svg, x, y, fs);
-                currentStream.add("Q\nBT\n");
+//                currentStream.add("Q\nBT\n");
             } catch (FopImageException e) {}
 
         } else {
@@ -537,6 +537,19 @@
         // this.currentYPosition -= area.getEffectiveHeight();
     }
 
+    java.util.Vector pendingSVG = new java.util.Vector();
+    public class SVGInfo {
+        public Document d;
+        public int x;
+        public int y;
+        public FontState fs;
+        public SVGInfo(Document d, int x, int y, FontState fs) {
+            this.d = d;
+            this.x = x;
+            this.y = y;
+            this.fs = fs;
+        }
+    }
     /**
      * render SVG area to PDF
      *
@@ -546,7 +559,8 @@
         // place at the current instream offset
         int x = this.currentXPosition;
         int y = this.currentYPosition;
-        renderSVGDocument(area.getSVGDocument(), x, y, area.getFontState());
+//        renderSVGDocument(area.getSVGDocument(), x, y, area.getFontState());
+        pendingSVG.add(new SVGInfo(area.getSVGDocument(), x, y, area.getFontState()));
     }
 
     /**
@@ -888,6 +902,22 @@
         this.pdfDoc.output(outputStream);
     }
 
+
+    private void processPendingBorders() {
+        for (int i = pendingBorders.size() - 1; i >= 0; i--) {
+            PrintRenderer.BorderInfo borderInfo = (PrintRenderer.BorderInfo) pendingBorders.remove(i);
+            addLine(borderInfo.x, borderInfo.y, borderInfo.w, borderInfo.h, borderInfo.width, borderInfo.c);
+        }
+    }
+    private void processPendingSVG() {
+        for (int i = pendingSVG.size() - 1; i >= 0; i--) {
+            SVGInfo svgInfo = (SVGInfo) pendingSVG.remove(i);
+            closeText();
+            currentStream.add("ET\nq\n");
+            renderSVGDocument(svgInfo.d, svgInfo.x, svgInfo.y, svgInfo.fs);
+            currentStream.add("Q\nBT\n");
+        }
+    }
     /**
      * render page into PDF
      *
@@ -904,6 +934,9 @@
         renderRegions(page);
 
         closeText();
+
+        processPendingBorders();
+        processPendingSVG();
 
         float w = page.getWidth();
         float h = page.getHeight();
diff -ru 20.5\org\apache\fop\render\PrintRenderer.java namchinov\org\apache\fop\render\PrintRenderer.java
--- 20.5\org\apache\fop\render\PrintRenderer.java	Wed Jun 23 17:58:49 2004
+++ namchinov\org\apache\fop\render\PrintRenderer.java	Tue Nov 04 18:23:12 2003
@@ -219,6 +219,25 @@
         addRect(x, y, w, h, pdfcol, pdfcol);
     }
 
+
+    protected java.util.Vector pendingBorders = new java.util.Vector();
+    public class BorderInfo {
+        public int x;
+        public int y;
+        public int w;
+        public int h;
+        public int width;
+        public PDFColor c;
+        public BorderInfo(int x, int y, int w, int h, int width, PDFColor c) {
+            this.x = x;
+            this.y = y;
+            this.w = w;
+            this.h = h;
+            this.width = width;
+            this.c = c;
+        }
+    }
+
     protected void doFrame(Area area) {
         int w, h;
         int rx = this.currentAreaContainerXPosition;
@@ -233,8 +252,6 @@
         w = w + area.getPaddingLeft() + area.getPaddingRight();
         h = h + area.getPaddingTop() + area.getPaddingBottom();
 
-        doBackground(area, rx, ry, w, h);
-
         // rx = rx - area.getBorderLeftWidth();
         // ry = ry + area.getBorderTopWidth();
         // w = w + area.getBorderLeftWidth() + area.getBorderRightWidth();
@@ -265,19 +282,43 @@
         int right = area.getBorderRightWidth();
         int top = area.getBorderTopWidth();
         int bottom = area.getBorderBottomWidth();
+
+        doBackground(area, rx + 500/*(left == 0 ? 500 : left)*/, ry - 500/*(top == 0 ? 500 : top)*/, w - 500/*left - right / 2*/, h - 500/*bottom*/);
+
         // If style is solid, use filled rectangles
-        if (top != 0)
+/*        if (top != 0)
             addFilledRect(rx, ry, w, top,
                           new PDFColor(bp.getBorderColor(BorderAndPadding.TOP)));
         if (left != 0)
-            addFilledRect(rx - left, ry - h - bottom, left, h + top + bottom,
+            addFilledRect(rx, ry - h, left, h,
                           new PDFColor(bp.getBorderColor(BorderAndPadding.LEFT)));
         if (right != 0)
-            addFilledRect(rx + w, ry - h - bottom, right, h + top + bottom,
+            addFilledRect(rx + w, ry - h, right, h,
                           new PDFColor(bp.getBorderColor(BorderAndPadding.RIGHT)));
         if (bottom != 0)
-            addFilledRect(rx, ry - h - bottom, w, bottom,
-                          new PDFColor(bp.getBorderColor(BorderAndPadding.BOTTOM)));
+            addFilledRect(rx, ry - h, w, bottom,
+                          new PDFColor(bp.getBorderColor(BorderAndPadding.BOTTOM)));*/
+
+        if (top != 0)
+//            addLine(rx - top / 2, ry, rx + w + top / 2, ry, top,
+//                    new PDFColor(bp.getBorderColor(BorderAndPadding.TOP)));
+            pendingBorders.add(new BorderInfo(rx - Math.max(left / 2, 500), ry, rx + w + Math.max(left / 2, 500), ry, top,
+                    new PDFColor(bp.getBorderColor(BorderAndPadding.TOP))));
+        if (left != 0)
+//            addLine(rx, ry + left / 2, rx, ry - h - left / 2, left,
+//                    new PDFColor(bp.getBorderColor(BorderAndPadding.LEFT)));
+            pendingBorders.add(new BorderInfo(rx, ry + Math.max(top / 2, 500), rx, ry - h/* - top*/, left,
+                    new PDFColor(bp.getBorderColor(BorderAndPadding.LEFT))));
+        if (right != 0)
+//            addLine(rx + w, ry + right / 2, rx + w, ry - h - right / 2, right,
+//                    new PDFColor(bp.getBorderColor(BorderAndPadding.RIGHT)));
+            pendingBorders.add(new BorderInfo(rx + w, ry + Math.max(top / 2, 500), rx + w, ry - h/* - top*/, right,
+                    new PDFColor(bp.getBorderColor(BorderAndPadding.RIGHT))));
+        if (bottom != 0)
+//            addLine(rx - bottom / 2, ry - h, rx + w + bottom / 2, ry - h, bottom,
+//                    new PDFColor(bp.getBorderColor(BorderAndPadding.BOTTOM)));
+            pendingBorders.add(new BorderInfo(rx - Math.max(left / 2, 500), ry - h, rx + w + Math.max(left / 2, 500), ry - h, bottom,
+                    new PDFColor(bp.getBorderColor(BorderAndPadding.BOTTOM))));
     }
 
     /**
