2017-02-10 13 views
0

に充填されていない私はこのような原稿の向きを設定し、プログラムでPDFを作成します:空のフィールドを埋め、彼らが作成した文書を参照してください。間違った方向にiTextのPDFフィールドが文書の向き

public void fillStablefordPDF(Context ctx) { 
    OutputStream output = null; 
    try { 
     output = new FileOutputStream(ctx.getExternalCacheDir().getAbsolutePath() + "/StableFord_filled.pdf"); 
    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 
    } 

    try { 
     PdfReader reader = new PdfReader(new FileInputStream(ctx.getExternalCacheDir().getAbsolutePath() + "/StableFord.pdf")); 
     PdfStamper stamper = new PdfStamper(reader, output); 
     AcroFields acroFields = stamper.getAcroFields(); 
     ... 
     acroFields.setField("Name", "TOM"); 

を表示されます210 enter image description here

これらのフィールドに正しい方向を記入するにはどうすればよいですか?

サミュエル・マイPdfCellEventクラス 言ったように私は私のフィールドにrorationを設定することで成功し
+1

を実装していますが、フィールドに回転値を追加する必要があります:あなたの塗りつぶされたPDFがあります出力を期待通りに構築するには、例を掘り下げることができるかどうか確認してください。 –

+1

代わりに 'PageSize.A4.rotate()'を 'new RectangleReadOnly(842,595)'に置き換えてください。 – mkl

答えて

0

: パブリッククラス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); 
    } 
} 
関連する問題