POSITON

/*
 * $Id: ComplexText.java,v 1.3 2005/05/09 11:52:08 blowagie Exp $
 * $Name:  $
 *
 * This code is part of the 'iText Tutorial'.
 * You can find the complete tutorial at the following address:
 * http://itextdocs.lowagie.com/tutorial/
 *
 * This code is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * itext-questions@lists.sourceforge.net
 */
package com.lowagie.examples.fonts.styles;

import java.io.FileOutputStream;
import java.io.IOException;

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Font;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.ColumnText;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;
/**
 * Adding text at an absolute position.
 */
public class ComplexText {
    /**
     * Adding text at absolute positions.
     * @param args no arguments needed
     */
    public static void main(String[] args) {
        
        System.out.println("Text at absolute positions");
        
        // step 1: creation of a document-object
        Document document = new Document();
        
        try {
            
            // step 2: creation of the writer
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("complextext.pdf"));
            
            // step 3: we open the document
            document.open();
            
            // step 4: we grab the ContentByte and do some stuff with it
            PdfContentByte cb = writer.getDirectContent();
            
            // first we draw some lines to be able to visualize the text alignment functions
            cb.setLineWidth(0f);
            cb.moveTo(250, 500);
            cb.lineTo(250, 800);
            cb.moveTo(50, 700);
            cb.lineTo(400, 700);
            cb.moveTo(50, 650);
            cb.lineTo(400, 650);
            cb.moveTo(50, 600);
            cb.lineTo(400, 600);
            cb.stroke();
            
            // we construct a font
            BaseFont bf = BaseFont.createFont("c://windows//fonts//arialuni.ttf", BaseFont.IDENTITY_H, true);
            Font ft = new Font(bf, 12);
            // This is the text:
            String text = "/u0623/u0648/u0631/u0648/u0628/u0627, /u0628/u0631/u0645/u062c/u064a/u0627/u062a /u0627/u0644/u062d/u0627/u0633/u0648/u0628 + /u0627/u0646/u062a/u0631/u0646/u064a/u062a :";
            Phrase center = new Phrase(text + " Center", ft);
            ColumnText.showTextAligned(cb, PdfContentByte.ALIGN_CENTER, center, 250, 700, 0, PdfWriter.RUN_DIRECTION_RTL, 0);
            ColumnText.showTextAligned(cb, PdfContentByte.ALIGN_RIGHT, new Phrase(text + " Right", ft), 250, 650, 20, PdfWriter.RUN_DIRECTION_RTL, 0);
            ColumnText.showTextAligned(cb, PdfContentByte.ALIGN_LEFT, new Phrase("Some text Left aligned", ft), 250, 600, 20);
            float size = ColumnText.getWidth(center, PdfWriter.RUN_DIRECTION_RTL, 0);
            cb.setRGBColorStroke(255, 0, 0);
            cb.rectangle(250 - size/2, 690, size, 30);
            cb.stroke();
        }
        catch(DocumentException de) {
            System.err.println(de.getMessage());
        }
        catch(IOException ioe) {
            System.err.println(ioe.getMessage());
        }
        
        // step 5: we close the document
        document.close();
    }
}
 
### 使用 jQuery 修改 HTML 元素的 Position 属性 为了修改 HTML 元素的位置属性,可以利用 jQuery 提供的强大功能来简化 CSS 操作。下面展示了一个具体的例子,说明如何通过 jQuery 将某个元素的位置设置为相对定位: ```javascript $(function() { // 选择目标元素并为其添加 position:relative 样式 $(".target-element").css("position", "relative"); }); ``` 如果希望动态调整已经设定过位置类型的元素的具体坐标,则可以通过 `top` 和 `left` 属性进一步控制其精确位置[^3]。 对于绝对定位(absolute positioning),由于此类元素会脱离正常的文档流,因此可能需要额外处理父容器的高度等问题以防止布局异常。此时建议采用 JavaScript 或者 jQuery 来计算高度并将该值显式赋予父级节点[^2]。 当涉及到更复杂的尺寸测量时,比如考虑内边距、外边框甚至页边空白的影响,jQuery 的 `.width()`、`.height()` 方法族提供了多种方式获取或指定这些度量单位[^4]。 #### 设置不同类型的定位模式 除了上述提到的方式之外,还可以根据实际需求灵活运用其他几种常见的定位类型,如固定定位 (`fixed`) 或静态定位 (`static`) 等等。这里给出一段通用代码用于切换不同的定位模式: ```javascript // 定义一个函数用来更改元素的位置属性 function setPositionType(selector, type) { $(selector).css({ 'position': type, top: (type === 'absolute' || type === 'fixed') ? '0px' : '', left: (type === 'absolute' || type === 'fixed') ? '0px' : '' }); } // 调用此方法可轻松改变任意选定元素的位置行为 setPositionType('.example', 'absolute'); ``` 这段脚本不仅能够有效地变更所选元素的位置特性,还兼顾到了某些特定情况下必要的附加样式声明,从而确保页面显示效果的一致性和预期性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值