简体   繁体   中英

How to change adobe readers zoom level?

I have a Jasper Report which creates a PDF in Java Spring. I have been trying to change the zoom level for hours and have not been successful. Whenever I open the pdf's using Adobe reader, its 149% (and coworkers is even worse). There was a similar question which did not help.

I have tried the following property names and none of them have worked

The values I have tried are

  • 0.5
  • 1.1
  • 2

I have checked my Adobe Reader properties and zoom is set to default, and accessibility is also off.

As Villat indicated in comment one way to set zoom level is " this.zoom=50; "

You can do this either by indicating it in jrxml

<property name="net.sf.jasperreports.export.pdf.javascript" value="this.zoom=50;"/>

or

by setting it to the SimplePdfExporterConfiguration if exporting from java

....
SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
configuration.setPdfJavaScript("this.zoom=50;");
exporter.setConfiguration(configuration);

However

It is up to the reader (application used to open pdf), to decide if it will/can execute the javascript.

For example in standard Adobe Acrobat Reader DC a user can manually turn this off under menu Edit>>Preferences

喜好

Furthermore, if the reader is already open it seems to not always like to change the zoom level through javascript, my installed reader works properly only if it opens with the pdf.

Alternative solution

If you are exporting in java you can post elaborate the pdf adding a OpenAction, see Bruno Lowagie 's answer https://stackoverflow.com/a/24095098/5292302

 public void manipulatePdf(String src, String dest) throws IOException, DocumentException { PdfReader reader = new PdfReader(src); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest)); PdfDestination pdfDest = new PdfDestination(PdfDestination.XYZ, 0, reader.getPageSize(1).getHeight(), 0.75f); PdfAction action = PdfAction.gotoLocalPage(1, pdfDest, stamper.getWriter()); stamper.getWriter().setOpenAction(action); stamper.close(); reader.close(); }

Hence once exported, you call a similar method, if memory allows it you can also do this in memory using a ByteArrayOutputStream or similar.

This solution is more reliable, but in the the end it's always up to to the reader that user is using if it will be respected or not.

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