简体   繁体   中英

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

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); 

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM