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

Feature: Support manual redaction #2433

Open
wants to merge 38 commits into
base: main
Choose a base branch
from

Conversation

omar-ahmed42
Copy link
Contributor

Description

Manual Redaction:

  • Text Selection-based redaction:

    • image
    • Users can now redact currently selected text by selecting the text then clicking ctrl + s shortcut or by pressing on apply/save/disk icon in the toolbar.
    • Users can delete/cancel the redacted area by clicking on the box containing the text, then clicking on delete/trash icon or by using the shortcut delete.
    • Users can customize the color of the redacted area/text (after the redaction was applied) by simply clicking on the box containing the text/area then clicking on the color palette icon and choosing the color they want.
    • Users can choose to select the color of redaction before redacting text or applying changes (this only affects newly created redaction areas, to change the color of an existing one; check the previous bullet point).
  • Draw/Area-based redaction:

    • image
    • Users can now redact an area in the page by selecting the then clicking ctrl + s shortcut or by pressing on apply/save/disk icon in the toolbar.
    • Users can delete/cancel the redacted area by clicking on the drawn box, then clicking on delete/trash icon or by using the shortcut delete (requires temporarily turning off drawing mode).
    • Users can customize the color of the redacted area (after the redaction was applied) by simply clicking on the box containing the area then clicking on the color palette icon and choosing the color they want.
    • Users can choose to select the color of redaction before drawing the box or applying changes (this only affects newly created redaction areas, to change the color of an existing one; check the previous bullet point).
  • Page-based redaction:

    • image
    • Users can now redact ENTIRE pages by specifying the page number(s), range(s) or functions.
    • Users can customize the color of page-based redaction (doesn't affect text-based nor draw-based redactions).

Redaction modes:

There are three modes of redaction/operation currently supported

  • Text Selection-based redaction (TEXT)
  • Draw/Area-based redaction (DRAWING)
  • None - by simply not choosing any of the above modes (NONE).

How to use:

  • Text Selection-based redaction: click on this icon in the toolbar image to enable text-selection redaction mode then select the text you want to redact then press ctrl + s or click on the disk/save icon image.

  • Draw/Area-based redaction: click on this icon in the toolbar image to enable draw/area-based redaction then left mouse click (LMB) on the starting point of the rectangle, then once you are satisfied with the rectangle's placement/dimensions then left mouse click (LMB) again to apply the redaction.

    • Example: Left mouse click (LMB) then move mouse to the right then bottom then Left mouse click (LMB).
    • Note: Red box/rectangle borders indicate that you have not yet saved (you need to left click on the page to save) image once saved the borders will become green image (they also become clickable/hover-able when drawing mode is off).
  • Page-based redactions:: Insert the page number(s), range(s) and/or functions (separated by ,) then select your preferred color and click on Redact to submit.
    image

  • Color Customizations:

    • You can change the redaction color for new redactions by clicking on this icon in the toolbar image.
    • You can change the redaction color for existing redactions by hovering over the redaction box then clicking on it (Left mouse click LMB) then clicking on color palette (highlighted in red in the picture) image then select your preferred color.
  • Deletions:

    • You can delete a redacted area by hovering over the redaction box then clicking on it (Left mouse click LMB) then clicking on the trash icon (highlighted in red in the picture) image.

Card in the home page:

image

Closes #465

Checklist

  • I have read the Contribution Guidelines
  • I have performed a self-review of my own code
  • I have attached images of the change if it is UI based
  • I have commented my code, particularly in hard-to-understand areas
  • If my code has heavily changed functionality I have updated relevant docs on Stirling-PDFs doc repo
  • My changes generate no new warnings
  • I have read the section Add New Translation Tags (for new translation tags only)

- Add redact.html which contains the nav-bar, file chooser, outer container and print container (used by PDF.JS viewer) and lastly the footer.
- Add redact.css which is used specifically to style redaction operation and the redaction page (except for PDF.js viewer).
- Add viewer-redact.css which is used to style PDF.js viewer that's used in the page (Changed the background to correspond with Stirling's themes).
- Add redact.js which contains the redaction related logic.
- Add submit button.
- Add hidden redactions input.
- Rename fileSelector from pdf-upload to fileInput.
- Scale x, y, width and height to match PDF page points accurately.
- Fix formula for redaction points and dimensions as x, y, height and width should be the original width rather than the width after adjusting it to the zoom level (zoom level is mainly used for correct display positioning, while scale factor is used for correct positioning in the actual PDF).
- Slightly refactor redact.js for more readability and to reduce code duplication.
…ion-based Redaction mode buttons

- Now, when one button is clicked, the other is automatically deselected, ensuring only one mode can be active at a time.
- Support page-based redactions by providing page numbers, page ranges and functions.
- Rename pageNumbers's input id to be more meaningful
@dosubot dosubot bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Dec 11, 2024
@github-actions github-actions bot added Java Pull requests that update Java code Front End Issues or pull requests related to front-end development Back End Issues related to back-end development Translation API API-related issues or pull requests labels Dec 11, 2024
@dosubot dosubot bot added the enhancement New feature or request label Dec 11, 2024
@Frooodle
Copy link
Member

/deploypr

Copy link
Contributor

🚀 PR Test Deployment

Your PR has been deployed for testing!

🔗 Test URL: http://185.252.234.121:2433

This deployment will be automatically cleaned up when the PR is closed.

@reecebrowne
Copy link
Contributor

Hi, this feature is absolutely fantastic, great work! I just have questions about presentation.
Is there a practical reason you used the pdfjs-legacy pdf viewer instead of using the implementation used on pages like sign? As it is this feature presents totally differently to our other editing tools and may be a bit difficult to use, especially with how small the icons are for the redaction tools.
If you could look in to making it look more like the Sign feature or explaining the potential issues if there are technical reasons for doing it the way you have that would be hugely appreciated. Thanks!

@omar-ahmed42
Copy link
Contributor Author

omar-ahmed42 commented Dec 12, 2024

Hi, before I explain anything let's take a look at what we need first to implement this feature (redaction):

  1. To be able to select text.
  2. To be able to draw shapes (mainly rectangles).
  3. Zooming is required as some text might be really small (because of font size) or because accuracy is required maybe to redact an area of the page (such as parts of an image).

Let's address each point, as for :

  1. To be able to select text.
    If we used the implementation provided in sign page for example, we will run into the problem of not being to select text as the provided view is simply a canvas without any text (if you right click on it, you can store it as an image) so basically it's treated as an image, which would be fail in our use case, we will need to add extra logic and complexity just to display text in the canvas which might prove error-prone, on the other hand, viewer.mjs (used by pdf-js for the viewing pdfs) actually provides the canvas as well as the text on it placed where text is supposed to be placed (in short, canvas with pdf's text). so by using viewer.mjs in this case, we've what we needed ready for us along with a toolbar that we can use to add more tools or hide existing tools.

as for:

  1. To be able to draw shapes (mainly rectangles).

This might not be a problem for either, the sign implementation nor the viewer.mjs

as for zooming:

  1. Zooming is required as some text might be really small (because of font size) or because accuracy is required maybe to redact an area of the page (such as parts of an image).

We will still have to modify the code and ensure the presentation doesn't lose any quality in the process of zooming in (you can try zooming in the sign - after extracting the canvas and its container out of the form card of course so that it would be bigger - you will find that it loses quality in the process, that's something we have to take into account as well), in other words, we will have to reinvent the wheel to some degree to get the same functionality that's made and ready to use in viewer.mjs

These are the main reasons why I went with viewer.mjs rather than sign's implementation, I believe the sign's implementation is superb and really fits the use case of sign and other pages as well, in the case of this feature I didn't feel like it would be a great fit for this use case.

Another thing I had in mind, is that we might add extra features to the manual redact page, such as displaying on the right the selected text for redaction for example, and on click the page would be displayed or that the user could simply remove it from that list/catalogue on the right side of the screen, also providing faster access to other pages through the ready made page preview on the left of the screen (I am not sure if that's what it's called), we can also modify the page preview to correspond to changes on the actual page (if the user decided to redact some text with a green rectangle, then a green rectangle would appear in the page preview in an approximate location), etc.

We could also modify the look and feel of the toolbar later on to correspond more to the Stirling's look and feel.

As for the icons' size, I can try and making them bigger if you think they would be easier to use, along with the toolbar, either way, I think we would need to come out with better icons for redactions because I don't find the icons that I used to be intuitive enough so that beginners could use it without heading to a guide/tutorial (I couldn't really find any icons to denote the usage of these buttons/features, so I had to come up with a custom solution that can relate even 1% to their intention).

Also, given this new UI for redactions we could later on incorporate auto redactions as well, so that we would've a complete redaction feature that would support all kinds of redactions, while at the same time, we still keep the auto redaction page because it's more lightweight and has specific usage so that users that need it can simply use it directly without the extra complexity of the current page.

Anyway, if you have any feedback, questions or any ideas, please, let me know.

Also, regarding:

this feature is absolutely fantastic, great work!

Thanks!

@reecebrowne
Copy link
Contributor

Hi there. Thanks for your reply, that all makes perfect sense! If you could make those icons bigger that would help straight away and if there's anything else you feel you could do to bring that page a little closer visually to the UI of other pages it would be much appreciated.

I don't know how much can be done about the top toolbar in the pdfjs viewer, would it be possible to pull that functionality out into a custom toolbar, one similar to the one we have in multitool perhaps? If that is possible it would make a world of difference on bringing the presentation more in line with our existing design.

I shall try to find you some icons that will be appropriate for these functions and send them across.

Thanks again for your contributions!

@omar-ahmed42
Copy link
Contributor Author

If you could make those icons bigger that would help straight away

Sure thing! I think this might provide a better user-experience, so you have a point!

if there's anything else you feel you could do to bring that page a little closer visually to the UI of other pages it would be much appreciated.

Sure, I can try this again, might look better than the current one given the bigger icons, etc

I don't know how much can be done about the top toolbar in the pdfjs viewer, would it be possible to pull that functionality out into a custom toolbar, one similar to the one we have in multitool perhaps? If that is possible it would make a world of difference on bringing the presentation more in line with our existing design.

All I know that we can customize the styling of it, but not pull our the functionality itself into a separate one, not to mention that if we managed to somehow pull it out and make it work:

  1. Which area would be most appropriate to the user (in terms of functionality, such as reach, if we place it too far, it would be unpleasant user experience (unless the user uses keyboard shortcuts most of the time), if we place it too close, it might get in the way of the user?
  2. Which area would be most pleasant to look at as well for the user (look-wise)?

But as for styling it, I was actually thinking of styling it to match the rest of the designs actually as you mentioned, but I thought I would push the feature first in case we needed to deliver it earlier than expected.

But yeah, I bringing the toolbar and icons as close as possible to existing design should be the next step (after making the icons bigger), so basically I should be starting with the size of the icons then proceed to the toolbar and the tools as well.

I shall try to find you some icons that will be appropriate for these functions and send them across.

Appreciate that a lot! this would be of great help! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API API-related issues or pull requests Back End Issues related to back-end development enhancement New feature or request Front End Issues or pull requests related to front-end development Java Pull requests that update Java code size:XXL This PR changes 1000+ lines, ignoring generated files. Translation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature request] anonymize PDFs via UI redaction (Drawing black rectangle etc)
3 participants