pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From phi...@free.fr
Subject Rotate text
Date Wed, 22 Apr 2015 08:39:13 GMT
Hello,

when I generate the PDF using this method, the page is landscaped but not the input field
text.

How do I rotate the text?

Many thanks.

Philippe

----------------------------------

	byte[] generateSimpleTemplate() throws IOException, COSVisitorException {

		try (PDDocument template = new PDDocument();
				InputStream fontStream = getClass().getResourceAsStream("/META-INF/fonts/arial.ttf");
				ByteArrayOutputStream resultStream = new ByteArrayOutputStream()) {
			final PDPage page = new PDPage(PDPage.PAGE_SIZE_A4);
			page.setRotation(90);
			template.addPage(page);

			final PDTrueTypeFont font = PDTrueTypeFont.loadTTF(template, fontStream);

			// add a new AcroForm and add that to the document
			final PDAcroForm acroForm = new PDAcroForm(template);
			template.getDocumentCatalog().setAcroForm(acroForm);

			// Add and set the resources and default appearance
			final PDResources res = new PDResources();
			final String fontName = res.addFont(font);
			acroForm.setDefaultResources(res);
			final String da = "/" + fontName + " 12 Tf 0 g";

			final COSDictionary cosDict = new COSDictionary();

			final COSArray rect = new COSArray();

			rect.add(new COSFloat(0f)); // lower x boundary
			rect.add(new COSFloat(0f)); // lower y boundary
			rect.add(new COSFloat(100f)); // upper x boundary
			rect.add(new COSFloat(100f)); // upper y boundary

			cosDict.setItem(COSName.RECT, rect);
			cosDict.setItem(COSName.FT, COSName.getPDFName("Tx")); // Field Type
			cosDict.setItem(COSName.TYPE, COSName.ANNOT);
			cosDict.setItem(COSName.SUBTYPE, COSName.getPDFName("Widget"));
			cosDict.setItem(COSName.DA, new COSString(da));

			// add a form field to the form
			final PDTextbox textBox = new PDTextbox(acroForm, cosDict);
			textBox.setPartialName("SampleField");

---------------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Mime
View raw message