WIP: Add "Preserve Text (Searchable)" option with full color inversion #13

Closed
Copilot wants to merge 5 commits from copilot/fix-ctrl-f-search-issue into main
Copilot commented 2025-11-29 10:21:17 -05:00 (Migrated from github.com)

Current conversion rasterizes pages to images, breaking Ctrl+F text search. This adds an optional mode that inverts colors while preserving the original PDF text/vector content, keeping text searchable.

Changes

  • New checkbox option: "Preserve Text (Searchable)" in the controls area (disabled by default)
  • New checkbox option: "Invert Images" (only visible when Preserve Text is enabled, checked by default)
  • renderPDFPreserveText(): Uses PDF blend modes to invert colors while preserving text searchability
  • Refactored existing logic into renderPDFRasterized() for the default inversion mode

The preserve text mode uses PDF "Difference" blend mode to properly invert colors:

  • White background → Theme color (dark background)
  • Black text → White/light text (readable on dark background)
  • All content remains searchable with Ctrl+F
// Create ExtGState for Difference blend mode (for inversion)
const differenceGsDict = pdfDoc.context.obj({
    Type: PDFLib.PDFName.of('ExtGState'),
    BM: PDFLib.PDFName.of('Difference'),
});

// Invert everything by drawing white with Difference blend
contentOps += `q /GSDiff gs 1 1 1 rg 0 0 ${width} ${height} re f Q `;
// Add theme color tint
contentOps += `q /GSDiff gs ${tintR} ${tintG} ${tintB} rg 0 0 ${width} ${height} re f Q `;
Original prompt

This section details on the original issue you should resolve

<issue_title>ctrl-f no words found?</issue_title>
<issue_description>Want to thank you because I really like the dark pdf, and the datasheets are so much easier on the eyes late at night, but a little hard to find things since the the browser search seems to be broken after conversion? Looks like text is converted to raster </issue_description>

<agent_instructions>now the conversion is image
try to change the backgroud without change the image
do it only as an option (not a default) </agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Current conversion rasterizes pages to images, breaking Ctrl+F text search. This adds an optional mode that inverts colors while preserving the original PDF text/vector content, keeping text searchable. ## Changes - **New checkbox option**: "Preserve Text (Searchable)" in the controls area (disabled by default) - **New checkbox option**: "Invert Images" (only visible when Preserve Text is enabled, checked by default) - **`renderPDFPreserveText()`**: Uses PDF blend modes to invert colors while preserving text searchability - **Refactored existing logic** into `renderPDFRasterized()` for the default inversion mode The preserve text mode uses PDF "Difference" blend mode to properly invert colors: - White background → Theme color (dark background) - Black text → White/light text (readable on dark background) - All content remains searchable with Ctrl+F ```javascript // Create ExtGState for Difference blend mode (for inversion) const differenceGsDict = pdfDoc.context.obj({ Type: PDFLib.PDFName.of('ExtGState'), BM: PDFLib.PDFName.of('Difference'), }); // Invert everything by drawing white with Difference blend contentOps += `q /GSDiff gs 1 1 1 rg 0 0 ${width} ${height} re f Q `; // Add theme color tint contentOps += `q /GSDiff gs ${tintR} ${tintG} ${tintB} rg 0 0 ${width} ${height} re f Q `; ``` <img src="https://github.com/user-attachments/assets/32ab7117-ef64-4c56-82be-89d52529480b"> - Fixes chizkiyahu/pdf-dark-mode-converter#12 <!-- START COPILOT CODING AGENT SUFFIX --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>ctrl-f no words found?</issue_title> > <issue_description>Want to thank you because I really like the dark pdf, and the datasheets are so much easier on the eyes late at night, but a little hard to find things since the the browser search seems to be broken after conversion? Looks like text is converted to raster </issue_description> > > <agent_instructions>now the conversion is image > try to change the backgroud without change the image > do it only as an option (not a default) </agent_instructions> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> - Fixes chizkiyahu/pdf-dark-mode-converter#12 <!-- START COPILOT CODING AGENT TIPS --> --- 💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).
chizkiyahu (Migrated from github.com) reviewed 2025-11-29 10:21:17 -05:00
chizkiyahu commented 2025-11-29 11:37:14 -05:00 (Migrated from github.com)

@copilot the part of the files bacgorud is still w
and the text is still b in all the backgourd w and b
make sure to replace the bacgroud and the the text
about images have a checkbox to let the user decide if to change or not

@copilot the part of the files bacgorud is still w and the text is still b in all the backgourd w and b make sure to replace the bacgroud and the the text about images have a checkbox to let the user decide if to change or not
Copilot commented 2025-11-29 11:45:44 -05:00 (Migrated from github.com)

@copilot the part of the files bacgorud is still w
and the text is still b in all the backgourd w and b
make sure to replace the bacgroud and the the text ...

Fixed in fb24894. The "Preserve Text" mode now properly inverts colors using PDF blend modes:

  • White background → Theme color
  • Black text → White/light text
  • Added "Invert Images" checkbox (checked by default) to let users choose whether to invert images

UI Screenshot

> @copilot the part of the files bacgorud is still w > and the text is still b in all the backgourd w and b > make sure to replace the bacgroud and the the text ... Fixed in fb24894. The "Preserve Text" mode now properly inverts colors using PDF blend modes: - White background → Theme color - Black text → White/light text - Added "Invert Images" checkbox (checked by default) to let users choose whether to invert images ![UI Screenshot](https://github.com/user-attachments/assets/32ab7117-ef64-4c56-82be-89d52529480b)

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
chizkiyahu/pdf-dark-mode-converter!13
No description provided.