2016-07-10 48 views
0

我已經編寫了可以返回PDF文件的restful webservice,並且此PDF將出現在瀏覽器中的IFrame中。 這部分很好。如何在java中設置pdf響應的默認縮放值

但是,我遇到困難的事情是,PDF文件在瀏覽器上打開選定的縮放值'自動縮放',但我想顯示這個PDF的縮放值'頁面寬度'選定。 請在下面找到返回PDF的方法。

/** 
* @param file 
* @return Response object. 
*/ 
private Response processRequest(final String filePath) 
{ 

    File file = new File(filePath); 

    PDPageFitDestination dest = new PDPageFitDestination(); 
    PDActionGoTo action = new PDActionGoTo();  
    action.setDestination(dest); 

    ByteArrayOutputStream output = new ByteArrayOutputStream(); 

    PDDocument pd=null; 
    try 
    { 
    pd = PDDocument.load(file); 
    pd.getDocumentCatalog().setOpenAction(action); 
    pd.save(output); 
    } 
    catch(IOException e) 
    { 
    e.printStackTrace(); 
    } 
    catch(COSVisitorException e) 
    { 
    e.printStackTrace(); 
    } 

    //ResponseBuilder responseBuilder = Response.ok((Object)file); 

    ResponseBuilder responseBuilder = Response.ok(output.toByteArray()); 
    responseBuilder.header("Content-Type", "application/pdf; filename=return.pdf"); 
    responseBuilder.header("Content-Disposition", "inline"); 
    return responseBuilder.build(); 
    } 

我想通過提供針對任何標頭值放大值將返回變焦值「頁寬」 PDF,但沒有得到這頭與它有關。 請提供您在這方面的建議。

+0

您正在測試什麼瀏覽器/ PDF查看器?並非所有瀏覽器/ PDF查看器都支持將PDF打開到指定的縮放級別。 Adobe Acrobat通過使用「打開操作」來完成此操作。 –

+0

@BrandonHaugen感謝您對我的問題的關注。目前我正在使用「Mozilla Firefox 24」和打開PDF「Adobe Acrobat Reader 11」。 –

+0

@BrandonHaugen我已經按照您的建議實施,但仍然使用「自動縮放」而不是「頁寬」作爲默認縮放值打開PDF。對此有何想法? –

回答

0

我解決了我的問題。只需要在請求URL中使用pdf特定參數。有關詳細信息,請轉至PDFOpenParameters