itext pdf字段未在文档方向中填充

时间:2017-02-10 08:40:02

标签: java android pdf itext

我以编程方式创建PDF,将Document方向设置为:

    private static unsafe byte[] ConvertStruct<T>(T str) where T: struct
    {
        T* ptr = &str;
        int size = Marshal.SizeOf(str);
        var arr = new byte[size];
        Marshal.Copy((IntPtr) ptr, arr, 0, size);
        return arr;
    }

创建的文档看起来不错: enter image description here

当我尝试填充空白字段时,它们会以错误的方向显示

public Document createStableFordPDF(Context ctx){
    Document document = new Document(PageSize.A4.rotate());
    try {
        PdfWriter writer = PdfWriter.getInstance(document,
                new FileOutputStream(ctx.getExternalCacheDir().getAbsolutePath()+"/StableFord.pdf"));

        document.open();
...

查看已创建的文件: enter image description here

如何以正确的方向填充这些字段?

1 个答案:

答案 0 :(得分:0)

塞缪尔说,我成功地为我的田地设置了一个ro .. 我的PdfCellEvent类: 公共类MyCellField实现PdfPCellEvent {

public MyCellField(String fieldname) {
    this.fieldname = fieldname;
    this.color = BaseColor.BLACK;
}

 @Override
public void cellLayout(PdfPCell cell, Rectangle rectangle, PdfContentByte[] canvases) {
    final PdfWriter writer = canvases[0].getPdfWriter();
    final TextField textField = new TextField(writer, rectangle, fieldname);
    textField.setAlignment(Element.ALIGN_CENTER);
    textField.setTextColor(color);
    textField.setFontSize(10);
    textField.setRotationFromPage(PageSize.A4.rotate());
try {
        final PdfFormField field = textField.getTextField();
        writer.addAnnotation(field);
    } catch (final IOException ioe) {
        throw new ExceptionConverter(ioe);
    } catch (final DocumentException de) {
        throw new ExceptionConverter(de);
    }
}