I'm quite annoyed with ads. As of many, I'm using an adblocker on my computer, but there is one kind of ads that annoys me the most: ads on printable ticket. Not only it poisons our eyes, but it consumes ink to print it.
I'm aware that we can just open the QR/barcode on your smartphone, but still, isn't it better if we can get rid of the ad directly?
A first obvious solution could be to import your pdf in any [image editing software](https://www.gimp.org/) and simply use any rectangle shape selection tool to remove the ad.
However, this produces a new pdf file (or image file) that does not contain any more information about the text, and which may grow in size.
A simple workaround is then to use a vector graphic editor to keep this information: for instance, opening the PDF with [inkscape](https://inkscape.org/), and remove the image corresponding to the ads.
Yet more elegant, this approach still has a serious drawback: it breaks the fonts. Also, some of them (such as Air France's “_Excellence in Motion_” font) are proprietary and cannot be found easily/legally for free.
**Explanations:** After opening your pdf file, start by selecting the ad (<spanstyle="color:#8b0074">purple</span>), you may have to ungroup elements (`ctrl+shift+g`), then set the dimensions in cm or your favourite length unit (<spanstyle="color:#0000ff">blue</span>) and finally note the dimensions of the ad (<spanstyle="color:#ff0000">red</span>).
Then we just use LaTeX to add a white (or any background color, I let you devise it by yourself, you can use RGB codes with [xcolor](https://www.ctan.org/pkg/xcolor)) rectangle in front of the ad.
I already used the [wallpaper](https://www.ctan.org/pkg/wallpaper) package in [another post]({filename}latex-letterhead.md), but it has some limitations: it doesn't allow us to import multiple pages (such as a round-trip ticket), and tikz doesn't interact well with the induced page geometry.
Thus, I used this [answer on stackexchange](https://tex.stackexchange.com/questions/12838/can-i-add-tikzpictures-to-pages-included-with-pdfpages).
To put it short, we use the package [pdfpages](https://ctan.org/pkg/pdfpages) with its options `pages={-}` to include every page, and the option `pagecommand` to include the rectangle overlay with the right dimensions `X`, `Y`, `L`, `H`.
**Remark:** You may have noticed the minus sign in front of `Y` and `H`. This is because tikz computes coordinates from bottom left of the page, while inkscape (and gimp) starts at top left (and the frame is oriented accordingly).
Some examples of dimensions to copy-paste (mostly for myself):
As I don't buy a plane ticket every day, I didn't feel the need to script it, and I don't have enough examples to make an interesting enough database of ad locations.
However, it is a great opportunity to get some more data about it, therefore there you can `git clone` the script from [here](https://git.epheme.re/fmouhart/hidepdfads).
As it is a self-hosted private repository, if you are eager to contribute, you may want to do a pull request on its [github repository](https://github.com/Chouhartem/hidepdfads) or send me an email on <imgstyle="height:2em"src="/images/mel.png"alt="courriel"/>. In any case, feel free to contact me for any further remarks, comments or questions.
* [pdf-adblock](https://github.com/anthony-morel/pdf-adblock) on github.
It's a script based on heuristics (for instance an ad will be an image) to remove single-page-ads automatically from a PDF (for instance a magazine PDF).