Rotate watermark text at 45 degree angle across the center Apache PDFBox

Rotate watermark text at 45 degree angle across the center Apache PDFBox

By : Krishna
Date : November 21 2020, 07:01 PM
I hope this helps . What I do is to first rotate based on the calculated angle. In this "rotated world" I do a horizontal offset so that the text is in the middle, and also move the text vertically a bit lower, so that it is in the "vertical" middle of an imagined diagonal line (horizontal in the "rotated world").
code :
try (PDDocument doc = new PDDocument())
    PDPage page = new PDPage();

    PDFont font = PDType1Font.HELVETICA_BOLD;
    try (PDPageContentStream cs =
            new PDPageContentStream(doc, page, PDPageContentStream.AppendMode.APPEND, true, true))
        // use this long constructor when working on existing PDFs
        float fontHeight = 110;
        String text = "Watermark";

        float width = page.getMediaBox().getWidth();
        float height = page.getMediaBox().getHeight();
        int rotation = page.getRotation();
        switch (rotation)
            case 90:
                width = page.getMediaBox().getHeight();
                height = page.getMediaBox().getWidth();
                cs.transform(Matrix.getRotateInstance(Math.toRadians(90), height, 0));
            case 180:
                cs.transform(Matrix.getRotateInstance(Math.toRadians(180), width, height));
            case 270:
                width = page.getMediaBox().getHeight();
                height = page.getMediaBox().getWidth();
                cs.transform(Matrix.getRotateInstance(Math.toRadians(270), 0, width));
        float stringWidth = font.getStringWidth(text) / 1000 * fontHeight;
        float diagonalLength = (float) Math.sqrt(width * width + height * height);
        float angle = (float) Math.atan2(height, width);
        float x = (diagonalLength - stringWidth) / 2; // "horizontal" position in rotated world
        float y = -fontHeight / 4; // 4 is a trial-and-error thing, this lowers the text a bit
        cs.transform(Matrix.getRotateInstance(angle, 0, 0));
        cs.setFont(font, fontHeight);
        //cs.setRenderingMode(RenderingMode.STROKE); // for "hollow" effect

        PDExtendedGraphicsState gs = new PDExtendedGraphicsState();
        gs.getCOSObject().setItem(COSName.BM, COSName.MULTIPLY);
        // gs.setBlendMode(BlendMode.MULTIPLY); // will work in 2.0.14

        // some API weirdness here. When int, range is 0..255.
        // when float, this would be 0..1f
        cs.setNonStrokingColor(255, 0, 0);
        cs.setStrokingColor(255, 0, 0);

        cs.newLineAtOffset(x, y);

Share : facebook icon twitter icon
Rotate a square by an angle in degree

Rotate a square by an angle in degree

By : developer
Date : March 29 2020, 07:55 AM
I hope this helps you . It's such a simple thing -- you've got the formula wrong for all of your y-values.
It should be:
code :
ya_new = sin(theta) * (xa - x) + cos(theta) * (ya - y) + y
Unity | Rotate the gameObject by specified angle (0~360 degree)

Unity | Rotate the gameObject by specified angle (0~360 degree)

By : toad
Date : March 29 2020, 07:55 AM
around this issue Use RotateAround.
code :
// Rotate around world y.
transform.RotateAround(transform.position, Vector3.up, angle);

// Rotate around local y.
transform.RotateAround(transform.position, transform.up, angle);
Apache PdfBox Rotate Crop Box Only Not Text

Apache PdfBox Rotate Crop Box Only Not Text

By : Warut Kritrungraung
Date : March 29 2020, 07:55 AM
hope this fix your issue So this might not work for everyone but I figured it out for my specific requirement. TextToPDF has a method called setLandscape before creating the pdf from text. textToPDF.setLandscape(true);
Rotate object 360 degree with some tilted angle or in ellipse shape using css or js

Rotate object 360 degree with some tilted angle or in ellipse shape using css or js

By : Tom Bender
Date : March 29 2020, 07:55 AM
This might help you To give the arm a 3d look you need to rotate it in the X axis - this is in addition to the Z axis rotation that you're already doing.
code :
.scara-arm {
  transform: rotateZ(0deg) rotateX(55deg);
.circle-small {
  perspective: 75em;
How to rotate the watermark text to a certain angle using react-image-process

How to rotate the watermark text to a certain angle using react-image-process

By : user3137809
Date : March 29 2020, 07:55 AM
wish of those help This is not possible with the selected library. The only supported rotation is of the image itself when you set the "mode" to "rotate". However, then you cannot apply the waterMark. There is no option to rotate just the watermark text.
See More: https://www.npmjs.com/package/react-image-process
Related Posts Related Posts :
  • Template engine recommendations
  • Help with hash tables and quadratic probing in Java
  • javax.persistence.NoResultException: getSingleResult() did not retrieve any entities
  • What does look and feel (java swing) mean?
  • Android Lightweight HTML Template Engine
  • Setting unique key constraint for Db4oEmbedded EmbeddedConfiguration
  • How can I handle user defined exceptions and after handling them resume the flow of program
  • Latest org.json
  • How to create web service client in a .jsp page?
  • Java Runtime command line Process
  • Android: add badge to icons internal to my app
  • spymemcached - is it possible to disable the logging system?
  • Java Logger with Servlets
  • replace special characters in string in java
  • why won't Eclipse use the compiler I specify for my project?
  • Google Web Toolkit, what can I do with it?
  • doubt on private members and Methods
  • How do I check if output stream of a socket is closed?
  • Is there a clean cut way of adding NOP records to an AFP file using Java?
  • Move multiple BufferedImage in Java2D?
  • how to learn Drools or another rule engine fast
  • Date Sorting - Latest to Oldest
  • unable to add objects to saved collection in GAE using JDO
  • Spring, Hibernate, Blob lazy loading
  • Including Applet in JSP page
  • Original object is also changed when values of cloned object are changed
  • Drag and drop + custom drawing in Android
  • Creating a time series with jfreechart
  • Hibernate Criteria: Perform JOIN in Subquery/DetachedCriteria
  • How to check if my string is equal to null?
  • Connect two client sockets
  • How to reference a .dll from a .jar file
  • Invoke web-services in JSF
  • servlet connection to DB
  • Can I un-assign (clear) all fields of an instance?
  • Java parsing XML document gives "Content not allowed in prolog." error
  • Deploy Play! application as executable jar
  • Castor: how to map a simple list of strings?
  • Hibernate Transient Extends problem
  • Posting a JSON array to webservice in Android
  • How to search for duplicate values in a huge text file having around Half Million records
  • Easy way to get a test file into JUnit
  • cast across classloader?
  • Image manipulation
  • Java - JPA - Generators - @SequenceGenerator
  • What's a good Java-based Master-Slave communication mechanism?
  • Design Help/Suggestion required
  • NullPointerException in com.sun.tools.jxc.SchemaGenTask
  • time required to finish the multithreaded program?
  • Traditional IO vs memory-mapped
  • Using StringBuilder to process csv files to save heap space
  • Response Time is different for mulitiple execution of the application with the same request Performance problem
  • Java - Weblogic - JMX : request available free memory on all servers
  • Error: Can't find common super class of
  • JNI problem when calling a native library that loads another native library
  • calling Stanford POS Tagger maxentTagger from java program
  • Notification framework for java
  • hide keyboard in android?
  • Alternative of JPA
  • How to get Java XP Look and Feel
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk