Hi Paulo, I guess this is one for you.
Since version 1.2.1 there seems to be a bug in the PDF Graphics2D implementation. As you can see in the attached documents, the version created with 1.1.4 renders rotated texts perfectly while 1.2.1 vertically squeezes the rotated text. Is this a bug? Regards, Christian
GraphicsTest-1.1.4.pdf
Description: Adobe PDF document
GraphicsTest-1.2.1.pdf
Description: Adobe PDF document
package ujac.test.itext;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfTemplate;
import com.lowagie.text.pdf.PdfWriter;
public class GraphicsTest {
public static void main(String[] args) {
try {
FileOutputStream os = new FileOutputStream("GraphicsTest.pdf");
Document document = new Document(PageSize.A4, 25, 25, 25, 25);
PdfWriter documentWriter = PdfWriter.getInstance(document, os);
document.open();
PdfContentByte cb = documentWriter.getDirectContent();
cb.saveState();
PdfTemplate template = cb.createTemplate(500, 500);
Graphics2D g = template.createGraphics(500, 500);
Font font = new java.awt.Font("Helvetica", Font.PLAIN, 20);
g.setFont(font);
g.drawString("normal text output", 10, 250);
Font rotatedFont = font.deriveFont(AffineTransform.getRotateInstance(Math.PI * 1.5));
g.setFont(rotatedFont);
g.drawString("rotated text output", 20, 200);
cb.restoreState();
// creating image from template
Image img = Image.getInstance(template);
img.setAbsolutePosition(100, 100);
document.add(img);
//document.add(new Paragraph(20, "Test paragraph", font));
document.close();
documentWriter.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
