I found this in the PDF spec for BBox:
/
//A rectangle in default user space coordinates specifying the location of the viewport on the page.// //The two coordinate pairs of the rectangle shall be specified in normalized form; that is, lower-left followed by upper-right, relative to the measuring coordinate system. This ordering shall determine the orientation of the measuring coordinate system (that is, the direction of the positive x and yaxes) in this viewport, which may have a different rotation from the page./


So my understanding is that instead of 0,0,100,100 you should try e.g. 0,100,100,0 or 100,0,0,100 for the BBox.

I didn't test it myself because your code isn't complete. Please tell whether it worked or not.

Tilman


Am 22.04.2015 um 10:39 schrieb phi...@free.fr:
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-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: users-h...@pdfbox.apache.org


Reply via email to