Add text annotation layer#4
Conversation
|
@copilot why am i receiving these errors when i run locally? 'BlazorPdfLocalizedStrings' does not contain a definition for 'Text' and no accessible extension method 'Text' accepting a first argument of type 'BlazorPdfLocalizedStrings' could be found (are you missing a using directive or an assembly reference?) |
There was a problem hiding this comment.
Pull Request Overview
This PR adds text annotation functionality to the PDF viewer, allowing users to add text overlays to PDF documents. The implementation includes a new text layer system with configurable styling and supports both the standard viewer and MudBlazor integration.
- Adds text annotation layer with clickable text placement and styling controls
- Implements text layer management including undo/clear operations
- Integrates text tools UI components for both standard and MudBlazor viewers
Reviewed Changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| Gotho.BlazorPdf/wwwroot/blazorpdf_text.css | Adds CSS styling for text annotation canvas |
| Gotho.BlazorPdf/wwwroot/blazorpdf.css | Imports the new text annotation CSS file |
| Gotho.BlazorPdf/Ts/PdfViewer.ts | Updates PDF viewer to support text layer operations and printing |
| Gotho.BlazorPdf/Ts/PdfTextLayer.ts | Implements core text annotation functionality with canvas management |
| Gotho.BlazorPdf/Ts/PdfState.ts | Extends PDF state to include text layer properties |
| Gotho.BlazorPdf/Ts/Pdf.ts | Integrates text layer into main PDF class |
| Gotho.BlazorPdf/PdfViewer.razor.cs | Adds C# methods for text layer operations |
| Gotho.BlazorPdf/PdfViewer.razor | Updates UI to include text annotation tools and canvas |
| Gotho.BlazorPdf/PdfInterop.cs | Adds JavaScript interop methods for text operations |
| Gotho.BlazorPdf/Pdf/TextLayer.cs | Implements C# text layer state management |
| Gotho.BlazorPdf/Pdf/PdfState.cs | Extends internal PDF state with text properties |
| Gotho.BlazorPdf/Pdf/Pdf.cs | Integrates text layer into main PDF model |
| Gotho.BlazorPdf/Config/BlazorPdfLocalizedStrings.cs | Adds localization strings for text functionality |
| Gotho.BlazorPdf/BlazorPdfIcons/TextIcon.razor | Creates SVG icon component for text tool |
| Gotho.BlazorPdf.MudBlazor/MudPdfViewer.razor | Adds MudBlazor-specific text annotation UI |
| Gotho.BlazorPdf.MudBlazor/Config/MudPdfIconConfig.cs | Configures MudBlazor icons for text functionality |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| private onClick(e: MouseEvent) { | ||
| if (!this.canvas || !this.ctx) return; | ||
| const [x, y] = this.getNormalizedMousePos(this.canvas, e); | ||
| const text = prompt('Enter text'); |
There was a problem hiding this comment.
Using prompt() for text input provides a poor user experience and is not accessible. Consider implementing a custom modal or inline text input component that integrates with the existing UI framework.
| const x = rx * this.canvas.width; | ||
| const y = ry * this.canvas.height; | ||
| this.ctx.fillStyle = t.color; | ||
| this.ctx.font = `${t.size}px sans-serif`; |
There was a problem hiding this comment.
Hard-coding 'sans-serif' as the font family limits text customization options. Consider making the font family configurable through the text layer settings.
|
|
||
| for (const t of pageTexts) { | ||
| textCtx.fillStyle = t.color; | ||
| textCtx.font = `${t.size}px sans-serif`; |
There was a problem hiding this comment.
The font specification is duplicated from PdfTextLayer.ts line 124. Consider extracting this into a shared constant or method to maintain consistency.
| const x = (evt.clientX - rect.left) / canvas.width; | ||
| const y = (evt.clientY - rect.top) / canvas.height; |
There was a problem hiding this comment.
The normalization calculation is incorrect. It should divide by the canvas's display dimensions (rect.width/rect.height) rather than the canvas element's width/height properties to account for CSS scaling.
| const x = (evt.clientX - rect.left) / canvas.width; | |
| const y = (evt.clientY - rect.top) / canvas.height; | |
| const x = (evt.clientX - rect.left) / rect.width; | |
| const y = (evt.clientY - rect.top) / rect.height; |
Summary
Testing
npm run tsnpm run ts-minnpm run cssdotnet test(fails: The current .NET SDK does not support targeting .NET 9.0)https://chatgpt.com/codex/tasks/task_e_68b59f9e74948329bd2a64df6f9e6b06