我以编程方式创建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;
}
当我尝试填充空白字段时,它们会以错误的方向显示
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();
...
如何以正确的方向填充这些字段?
答案 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);
}
}