2012-07-11 16 views
1

我正嘗試使用Conversion API將html轉換爲PDF。 這裏是我的代碼GAE 1.7轉換API Java html - > pdf ConversionResult始終返回test.pdf

public byte[] toPDF(String html){ 
    Asset asset = new Asset("text/html", html.getBytes(), "in.html"); 
    Document document = new Document(asset); 
    Conversion conversion = new Conversion(document, "application/pdf"); 
    ConversionService service = ConversionServiceFactory.getConversionService(); 
    ConversionResult result = service.convert(conversion); 
    if (result.success()) { 
     for (Asset assetResult : result.getOutputDoc().getAssets()) { 
      return assetResult.getData(); 
     } 
    return null; 
    } else { 
     // Do stuff with result.getErrorCode()); 
     return null; 
    } 
} 

ConversionResult對象總是返回檢驗.pdf(從轉換API)字節,而不是(PDF)從我的HTML PDF新轉換的字節。 有誰知道這個問題是什麼?是否因爲我在本地主機上使用了轉換API?如果是,是否有解決方法?

在此先感謝。

奧爾本

回答

1

開發應用程序服務器不完全支持轉換API。這只是一個非常基本的存根實現,總是返回一個固定的文件。

+0

非常感謝。那麼除了生產以外,沒有其他方法可以測試該API了嗎? – user1517136 2012-07-16 12:01:06