title: Rotate watermark text at 45 degree angle across the center Apache PDFBox
body: <p>I want to add a text to the PDF using PDFBox API and rotate it by 45 Degree and place it at the center of the page, The text is dynamic and should be placed in the center always, I got everything else to work except centering piece, I'll appreciate any help.
  I have this code:</p>
  
  <pre><code>Point2D.Float pageCenter = getCenter(page);
  
  float stringWidth = getStringWidth(watermarkText, font, fontSize);
  float textX = pageCenter.x - stringWidth / 2F + center.x;
  System.out.println(textX);
  float textY = pageCenter.y + center.y;
  //System.out.println("Inside cross"+textX+", "+textY);
  fontSize = 110.0f;  
  cs.transform(Matrix.getRotateInstance(Math.toRadians(45), textX, textY));
  cs.moveTo(0, 0);
  cs.lineTo(125, 0);
  r0.setNonStrokingAlphaConstant(0.20f);
  </code></pre>
  
  <p>This is the result i want:
  <a href="https://i.stack.imgur.com/uXjVV.png" rel="nofollow noreferrer">Output PDF</a></p>