I try to set the initial view of a pdf to fit the entire page with this code:
from pypdf import PdfWriter
writer = PdfWriter(clone_from="test.pdf")
if writer.viewer_preferences is None:
writer.create_viewer_preferences()
writer.viewer_preferences.fit_window = True
with open("result.pdf", "wb") as fp:
writer.write(fp)
but the pdf still opens in Acrobat with zoom=pagewidth. I wanted the page to open with full page in Window. The test.pdf is just one page
There are 3 types of "Acrobat Viewer", so let's cover this PDF setting in each case.
For browsers with "Powered by Adobe Acrobat" the PDF internal controls are ignored and need to be set externally (after the file name), different ways. But here in Edge, it will be
filename.pdf#view=fitVto ensure a full single page. Without that fragment it will be random, based on page size so here neither fit width nor fit height. Nor adjust the browser window.I do not have the imbedded Adobe Reader in a browser to illustrate, but it may perform slightly differently. It may now, not respect those external controls, but did in legacy plug-ins.
Stand-alone "Adobe Acrobat Reader" does not internally use Fit Height or Fit Width for external sourced viewer controls. It uses any "fit" it deems necessary, as allowed by the user. Since the user can and must have, control of initial view. Such as here, so you need to switch those off.
If the mode is Automatic or refuse external control, then fit window will resize window depending on /CropBox. Here it fits window to width. Also same internal command, a different file, it fits window to suit.
So basically in this case you cannot reliably override the user settings. You need to tell the user to set
Single PageandFit Page(/CropBox /MediaBox contents).This will be the only way to externally influence some consistency.