2012-09-12 79 views
0

我試圖從Android中的傳統應用程序打開標準PDF表單,使用iText覆蓋表單字段並傳遞給Android Reader上的Adobe Reader以填寫表單。Android iText addTemplate Stamp pdf表單字段超出現有PDF文檔

我已經能夠手動創建TextFields,但是我希望有一個PDF文件作爲模板來加速過程並更好地控制質量。

這是我到目前爲止的代碼,這遵循itext示例。

AssetFileDescriptor descriptor = getAssets().openFd("standardWO_Template_v1_fo.pdf"); 
      File templateFile = new File(descriptor.getFileDescriptor().toString()); 
      PdfReader reader = new PdfReader(intent.getData().getPath()); 
      reader.selectPages("1"); 
      PdfReader templateReader = new PdfReader(templateFile.getAbsolutePath()); 
      PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(file)); 
      // Stamp the template onto the document 
      PdfImportedPage page = stamper.getImportedPage(templateReader, 1); 
      PdfContentByte cb = stamper.getOverContent(1); 
      cb.addTemplate(page, 0, 0); 

我遇到的問題是在最後一行。 cb.addTemplate(page,0,0);

Eclipse報告以下錯誤。 java.awt.geom.AffineTransform類型無法解析。它是從所需的.class文件間接引用的

從我已經能夠告訴java.awt.geom.AffineTransform將不適用於Android僅Java。

有沒有不同的方式來完成我的任務或讓AffineTransform在Android中工作?

回答

2

經過一些更多的搜索,我發現這種方法。首先,我必須從使用我的android項目中的iText5.3.1庫更改爲droidText庫。

一旦我安裝了droidText庫就能夠使用下面的代碼。 (和ctrl-o在eclipse中)

File templateFile = new File(dir.getAbsolutePath() + "/templates/standardWO.pdf"); 
      // Read the incoming file 
      PdfReader reader = new PdfReader(intent.getData().getPath()); 
      // Read the template form information 
      PdfReader templateReader = new PdfReader(templateFile.getAbsolutePath()); 
      // Create the stamper from the incoming file. 
      PdfStamper stamper = new PdfStamper(templateReader, new FileOutputStream(file)); 
      // Import the template information 
      PdfImportedPage iPage = stamper.getImportedPage(reader, 1); 
      // get the direct content 
      PdfContentByte cb = stamper.getUnderContent(1); 
      // Add the imported page to the content 
      cb.addTemplate(iPage, 0, 0); 
      stamper.close(); 
      Log.v(TAG, "Opening file in adobe reader: " + file.getAbsolutePath()); 
      loadDocInReader(file); 
+0

嘿,謝謝尼克,對於這個特定位的信息。我正在嘗試在eclipse中的java應用程序中使用pdfReader API。這是給一個:pdfreader不能解析爲類型錯誤。你能告訴我,在這裏做什麼? –