Create PDF file with default “zoom to page level” (pdfbox)

故事扮演 提交于 2020-01-11 07:54:10

问题


I create a PDF file using pdfbox 2.0. when i open this pdf file in Adobe reader (windows), by default its open with zoom fit width.

What I need pdf file open with default zoom to page level.

My try:
Set zoom level at 100.

PDPageXYZDestination dest = new PDPageXYZDestination();    
dest.setPage(pagea);    
dest.setZoom(1);    
dest.setTop(new Float(PDRectangle.A4.getHeight()).intValue());    
PDActionGoTo action = new PDActionGoTo();    
action.setDestination(dest);    
document.getDocumentCatalog().setOpenAction(action); 

回答1:


Use PDPageFitDestination instead of PDPageXYZDestination - so your code looks like this now:

PDPageFitDestination dest = new PDPageFitDestination();
PDActionGoTo action = new PDActionGoTo();    
action.setDestination(dest);    
document.getDocumentCatalog().setOpenAction(action);


来源:https://stackoverflow.com/questions/35619737/create-pdf-file-with-default-zoom-to-page-level-pdfbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!