public PDFRenderTargetImpl( PdfContentByte cb, double width, double height, double topLeftX, double topLeftY, Rectangle size, float marginLeft, float marginRight, float marginTop, float marginBottom, boolean landscape) { this.cb = cb; this.marginTop = marginTop; this.marginLeft = marginLeft; this.marginBottom = marginBottom; this.marginRight = marginRight; this.pageSize = size; this.landscape = landscape; double centerX = topLeftX + width / 2; double centerY = topLeftY + height / 2; // Transform double pageWidth = size.getWidth() - marginLeft - marginRight; double pageHeight = size.getHeight() - marginTop - marginBottom; double ratioWidth = pageWidth / width; double ratioHeight = pageHeight / height; double scale = (float) (ratioWidth < ratioHeight ? ratioWidth : ratioHeight); double translateX = (marginLeft + pageWidth / 2.) / scale; double translateY = (marginBottom + pageHeight / 2.) / scale; cb.transform(AffineTransform.getTranslateInstance(-centerX * scale, centerY * scale)); cb.transform(AffineTransform.getScaleInstance(scale, scale)); cb.transform(AffineTransform.getTranslateInstance(translateX, translateY)); FontFactory.register("/org/gephi/preview/fonts/LiberationSans.ttf", "ArialMT"); }