Change border color of Okular annotations

5

2

Inline Note annotations in Okular (the default PDF reader for the KDE desktop) only allow me to modify the highlight color by default, but I want to modify the border color of those annotations too.

How can I modify the border color of Okular annotations or simply remove the border?

user2547450

Posted 2015-11-20T21:03:37.863

Reputation: 183

Answers

4

The border color is hardcoded as Qt::black. Therefore, if you want to change the color, you'll need to get the source, modify it, and recompile Okular. Look in pagepainter.cpp starting on line 711 (comment mine):

if ( borderWidth != 0 )
{
    QPen pen( Qt::black, borderWidth ); // The first argument is the important part
    painter.setPen( pen );
    painter.drawRect( 0, 0, image.width() - 1, image.height() - 1 );
}

If you want to remove the border, you can just delete the above if statement and its contents. If you want a different color, you can replace Qt::black with another one of the twenty predefined colors. To get any color, replace that constant with a call to QColor::fromRgb. For example, QColor::fromRgb(239, 228, 176, 255) is a kind of dingy yellow.

Recompiling applications is a little out of scope here, and a full explanation would be a tome. Here are some reference documents from KDE TechBase, though they may be a little out of date:

I wish there was another way, and I would welcome a simpler answer.

Ben N

Posted 2015-11-20T21:03:37.863

Reputation: 32 973

1

Thanks, looks very useful! I tried to assemble the instructions to compile an Okular build that work to a similar question needing an Okular tweaking (feel free to update!): http://superuser.com/questions/673917/modify-okular-highlight-to-automatically-copy-highlighted-text-into-comment . Okular developers have pretty comperehensive guidelines here, that may provide a relatively quick route: https://okular.kde.org/download.php. Step-by-step, compiling may be ok difficulty also for newbies. Consider posting the code as a git branch of Okular for increased accessiblity.

– puslet88 – 2016-02-09T14:21:40.083

Sorry for late response... I download okular source code, comment the if stament and it content and then build okular following the the kde guide, but this not work. I still have border color when I add Inline Note... – user2547450 – 2016-02-16T05:57:59.380

@user2547450 Sorry for my delayed response, heh. Are you sure you're running the version you built rather than the stock one that came with your system? If you change the Qt::black to another of the predefined colors, does anything happen? – Ben N – 2016-02-22T02:00:22.230

Yes I'm sure. I have install okular 0.20.2 and I build 0.24.60. I used borderWidth = 0 but doesn't work and I also used Qt::white and still show black border. – user2547450 – 2016-03-04T02:30:13.883

@user2547450 Does the change affect the appearance of any other annotation? What happens if you insert continue; before line 694? Inline notes should then not be rendered at all. – Ben N – 2016-03-05T00:18:19.427

Now that you mention. The Straight Line has not color. Appear that this is the style that is modifying. – user2547450 – 2016-03-05T05:06:30.477

@user2547450 I have no Linux distro to test with here, but I can't imagine how that part of the code is modifying the geometric annotations. Could you check that there's a // draw TextAnnotation comment a few lines up? – Ben N – 2016-03-05T17:50:22.530

Yes, I found // draw TextAnnotation comment. I change const double borderWidth = text->style().width(); by const double borderWidth = 0;. But continue show border color. I forget ask if you know anyone of the okular kde dev team? – user2547450 – 2016-03-06T03:21:28.563

@user2547450 I'm afraid I don't know anyone on the dev team, but maybe I'll set myself up a test environment soon. Note that setting the borderWidth to zero results in Qt assuming you wanted 1, so you should just remove that drawing instruction entirely. – Ben N – 2016-03-06T05:31:20.060

1

There are two problems with inline note annotations in Okular :

  1. Annotations are not saved within the PDF, but written separately, which makes them awkward to communicate and unusable with any other reader.
  2. As noted by @BenN, border colors are hardwired in black.

One solution might be to use another PDF editor that is more customizable. Unfortunately, I cannot find such an editor in Linux, so one has to use a Windows editor, which is entirely possible on Linux by using Wine which adds a native Windows-on-Linux layer (with the logo of "Wine Is Not an Emulator").

The recommended editor is PDF-XChange Viewer. One can use the portable version, but the installer is also said to work under Wine. PDF-XChange Viewer is reported as fully functional under Wine.

PDF-XChange Viewer has several flavors of annotations, called by it comments & markup, which can be customized for border and background colors : Sticky Note, Typewriter, Text Box, Callout; and includes as well the ability to highlight text, cross out text and underline text. All are fully customizable, and the PDF file is updated to contain them as viewable by any other PDF viewer.

harrymc

Posted 2015-11-20T21:03:37.863

Reputation: 306 093