سؤال

I am trying to use the iText Stamper to change a PDF file so that it will always open with full page display. I tried,

PdfStamper stamper = new PdfStamper(new PdfReader(src), new FileOutputStream(dest));
PdfWriter writer = stamper.getWriter();
PdfAction action = PdfAction.gotoLocalPage(1, new PdfDestination(PdfDestination.FIT), writer);
writer.setAdditionalAction(PdfWriter.DOCUMENT_OPEN, action);

but DOCUMENT_OPEN is not defined. How can I do this? Should I be using instead stamper.addJavascript? but what JS code will setup the initial view?

I could use setPageAction(PAGE_OPEN, action, 1) and that works, but I think it might be annoying to the user if every time they look at page 1, the view changes.

BTW, initially I tried to use the PDF Open Parameters, but they are very unreliable. I displayed the pdf using

<embed src='myfile.pdf#view=Fit'>

and Adobe Reader often ignores the view for no apparent reason. That is why I am trying to set the initial view within the PDF itself.

هل كانت مفيدة؟

المحلول

Try this instead:

writer.setOpenAction(action);

Also see the documentation for setOpenAction.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top