Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify Parts of the Header/Footer Info #163

Open
ryanwwest opened this issue Oct 17, 2022 · 6 comments
Open

Modify Parts of the Header/Footer Info #163

ryanwwest opened this issue Oct 17, 2022 · 6 comments

Comments

@ryanwwest
Copy link

I would like to be able to modify some, but not all, of the header/footer info. Specifically, I want to hide the date and bottom-left 'localhost' text, and include the full filepath (not just the filename) at the top. Is this possible?

@PeterWone
Copy link
Collaborator

PeterWone commented Oct 17, 2022

This is one of those things that looks straightforward but isn't. Headers and footers are outside of the scope of HTML and CSS standards, so they are not consistent between browsers.

I was going to tell you that the Chromium family of browsers provides direct control of header and footer content with symbols for various pieces of metadata including the ones that interest you, but I just checked, and it appears to have been removed.

A general solution would require me to switch off browser generated headers and footers, set margins to zero and take over the entire page. As you can imagine this represents a huge leap in complexity because I have to take over pagination as well. This is actually not impossible and there is a library with which I have been experimenting. The biggest problem is finding a reliable cross browser programmatic way to turn off browser generated headers and footers -- so far this appears to be impossible.

@ryanwwest
Copy link
Author

I see, I was suspecting that they might be tied to the browser since printing from other applications was changing the header and footer formatting.

I was going to open another issue asking whether there could be a command to just save the current code selection or file directly to a PDF (foregoing the need to bring up a browser and select which printer (in this case, a virtual PDF printer) you would want to use). Then after clicking/invoking said command, it simply brings up a file dialog of what to name the saved PDF and where to place it. But it sounds like the plugin currently relies on the browser to generate the PDF (along with headers and footers in that PDF as you stated), so would probably be very complicated.

The best solution I know of so far is using Notepad++, in which you can easily customize the header and footer contents (see screenshot). I understand that this would probably be too much to ask for a plugin, but this would be my ideal as then I could eliminate using Notepad++ entirely.

image

@PeterWone
Copy link
Collaborator

But it sounds like the plugin currently relies on the browser to generate the PDF

Yes, exactly. PDF generation is a side effect of exploiting the ubiquity of print capable browsers.

Someone told me that Electron (the basis of VS Code) has printing capabilities, so I investigated. It's true, and they do it by controlling Chrome. If I were to abandon support for browsers other than Chromium and its ilk, CRDP (Chrome Remote Debugging Protocol) would allow me to stick my programmatic hand up Chrome's digital butt and do anything I need to, including create a new user profile so I can set things up the way I need without affecting user preferences.

All of my research suggests that this is what I'll have to do if I want to take Print any further. This runs counter to Print's philosophy of platform independence, but the payoff is large.

@PeterWone PeterWone reopened this Aug 9, 2023
@PeterWone
Copy link
Collaborator

@ryanwwest See #265 for details. I'm reopening this. It won't be quick but I know how to do it.

@ryanwwest
Copy link
Author

Cool thanks! Would love to hear what you figured out.

@PeterWone
Copy link
Collaborator

It turns out that the current crop of browsers honour this

@media print { @page { margin: 0; } }

That suppresses the browser generated margins, headers and footers.

I can then use paged.js to paginate and produce my own headers and footers.

It's a heavyweight solution but it solves so many otherwise intractable problems it's not funny. For example, it gives me a way to make multi-document print-jobs start each file on the right-hand page for people with duplexing printers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants