Skip to content

Add per-library toggles for PDF internal and external links - #4777

Open
aliooo36 wants to merge 2 commits into
Kareadita:developfrom
aliooo36:feature/toggle-external-internal-links-pdf
Open

Add per-library toggles for PDF internal and external links#4777
aliooo36 wants to merge 2 commits into
Kareadita:developfrom
aliooo36:feature/toggle-external-internal-links-pdf

Conversation

@aliooo36

@aliooo36 aliooo36 commented Jul 5, 2026

Copy link
Copy Markdown

Allow libraries to disable external URL links and in-document internal links in the PDF reader, with EF migration, API/DTO wiring, UI settings, and migration/service test

Added

  • Per-library toggles in Library Settings to enable or disable external links in PDFs, which open websites in the browser
  • Per-library toggles in Library Settings to enable or disable internal links in PDFs, which jump to other pages or sections within the same document
  • When either link type is disabled, the PDF reader hides the yellow link overlay and click targets for that link type so they can't be activated accidentally

Changed

  • PDF link settings are included when copying settings from one library to another, matching other library-level reader options

🐈 Manual testing video + Feature showcase hyperlinked!

! Why I Implemented this feature (As mentioned in this discussion post)

I primarily read PDFs in Kavita and the core experience works great. However, navigating documents with a mix of internal references (footnotes, indexes) and external web URLs creates unnecessary friction.

An "Internal-Only" link toggle addresses two specific issues:

1. Preventing Reading Disruptions

  • Clicking an external link opens a new browser tab, breaking the reading state and forcing me out of the Kavita app interface.
  • An internal lock ensures that clicking or tapping around a document only navigates within the PDF itself, making misclicks a non-issue.

2. Local Privacy & Security

  • No External Phone-Homes: Malicious or tracked hyperlinks can leak data (like a public IP address or active reading times) to outside servers when triggered. Restricting links ensures the document remains completely sandboxed and offline.
  • Protection from Unverified Links: It blocks accidental redirects to phishing pages or automated file downloads embedded within unverified documents.

Behavior

Add a configuration toggle in the PDF reader settings (e.g., "Restrict to Internal Links Only"). When enabled, http:// and https:// protocols are ignored, while document anchor tags continue to handle internal navigation normally.


image

Allow libraries to disable external URL links and in-document internal
links in the PDF reader, with EF migration, API/DTO wiring, UI settings,
and migration/service tests.
Copilot AI review requested due to automatic review settings July 5, 2026 23:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds per-library controls to restrict PDF link behavior (external URLs and in-document navigation) and enforces those restrictions in the web PDF reader, with persistence via EF migration and coverage via service/migration tests.

Changes:

  • Introduces EnablePdfExternalLinks / EnablePdfInternalLinks library settings persisted in the database and exposed via DTOs/controllers.
  • Adds Library Settings UI switches for the two toggles and threads the values into the PDF reader runtime behavior.
  • Adds integration tests to validate update/copy behavior and a migration test to confirm default values.

Reviewed changes

Copilot reviewed 17 out of 18 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
UI/Web/src/assets/langs/en.json Adds i18n strings for the new library settings toggles.
UI/Web/src/app/sidenav/_modals/library-settings-modal/library-settings-modal.component.ts Adds form controls and populates them from the library model.
UI/Web/src/app/sidenav/_modals/library-settings-modal/library-settings-modal.component.html Adds two switches to configure PDF link behavior per library.
UI/Web/src/app/pdf-reader/_components/pdf-reader/pdf-reader.component.ts Fetches library toggles and configures PDF.js/annotation visibility accordingly.
UI/Web/src/app/pdf-reader/_components/pdf-reader/pdf-reader.component.scss Adds CSS rules to hide link annotations when disabled.
UI/Web/src/app/pdf-reader/_components/pdf-reader/pdf-reader.component.html Binds CSS classes and hooks annotationLayerRendered for per-page updates.
UI/Web/src/app/_models/library/library.ts Extends the Library TS interface with the two new booleans.
Kavita.Services.Tests/LibraryPdfLinkSettingsTests.cs Tests update + copy-settings propagation for the new toggles.
Kavita.Services.Tests/Helpers/LibrarySettingsTestHelper.cs Test helper to mirror library settings update/copy behavior.
Kavita.Server/Controllers/LibraryController.cs Wires new DTO fields into create/update/copy settings flows.
Kavita.Models/Entities/Library.cs Adds entity properties with default true.
Kavita.Models/DTOs/UpdateLibraryDto.cs Adds update DTO fields for the new toggles.
Kavita.Models/DTOs/LibraryDto.cs Adds fields to Lite/Library DTOs so clients can read the toggles.
Kavita.Database/Migrations/DataContextModelSnapshot.cs Updates snapshot with the new columns + defaults.
Kavita.Database/Migrations/20260705223354_PdfLinkSettings.Designer.cs EF designer output for the new migration.
Kavita.Database/Migrations/20260705223354_PdfLinkSettings.cs Migration adding the two new columns with default true.
Kavita.Database/DataContext.cs Configures default values for the new entity properties.
Kavita.Database.Tests/Migrations/PdfLinkSettingsMigrationTests.cs Verifies migration applies and defaults are true.

Comment thread Kavita.Models/DTOs/UpdateLibraryDto.cs Outdated
Comment on lines +51 to +53
/// <inheritdoc cref="Library.EnablePdfExternalLinks"/>
[Required]
public bool EnablePdfExternalLinks { get; init; }
Comment thread Kavita.Models/DTOs/UpdateLibraryDto.cs Outdated
Comment on lines +54 to +56
/// <inheritdoc cref="Library.EnablePdfInternalLinks"/>
[Required]
public bool EnablePdfInternalLinks { get; init; }
Comment thread Kavita.Services.Tests/Helpers/LibrarySettingsTestHelper.cs

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 18 changed files in this pull request and generated 2 comments.

Comment on lines +370 to +374
const isInternal = section.hasAttribute('data-internal-link');
const hide = (isInternal && !this.enablePdfInternalLinks)
|| (!isInternal && !this.enablePdfExternalLinks);
(section as HTMLElement).hidden = hide;
});
Comment on lines +111 to +115
.pdf-external-links-disabled ::ng-deep .annotationLayer section.linkAnnotation:not([data-internal-link]),
.pdf-internal-links-disabled ::ng-deep .annotationLayer section.linkAnnotation[data-internal-link] {
display: none !important;
pointer-events: none !important;
}
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

Successfully merging this pull request may close these issues.

2 participants