Skip to content

Commit 5a1ee15

Browse files
committed
CSP final fix
1 parent 6250e20 commit 5a1ee15

File tree

7 files changed

+93
-10
lines changed

7 files changed

+93
-10
lines changed

SECURITY.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,5 @@ We thank the security community for their contributions to making ng2-pdfjs-view
128128

129129
---
130130

131-
**Last Updated**: January 2025
132-
**Version**: 25.0.12
131+
**Last Updated**: October 2025
132+
**Version**: 25.x

docs-website/docs/installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ npm list ng2-pdfjs-viewer
2121
You should see output similar to:
2222
```
2323
[email protected] /path/to/your-app
24-
└── [email protected].12
24+
└── [email protected].13
2525
```
2626

2727
## Production Deployment

lib/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ng2-pdfjs-viewer",
3-
"version": "25.0.12",
3+
"version": "25.0.13",
44
"description": "The most comprehensive Angular PDF viewer powered by Mozilla PDF.js. 7M+ downloads, mobile-first, production-ready with complete rewrite in v25.x",
55
"author": {
66
"name": "Aneesh Goapalakrishnan",

lib/pdfjs/web/viewer.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5299,6 +5299,11 @@ body.wait::before{
52995299
mask-image:var(--toolbarButton-print-icon);
53005300
}
53015301

5302+
/* Print service dialog styling */
5303+
.print-service-dialog {
5304+
min-width: 200px;
5305+
}
5306+
53025307
#downloadButton::before{
53035308
-webkit-mask-image:var(--toolbarButton-download-icon);
53045309
mask-image:var(--toolbarButton-download-icon);

lib/pdfjs/web/viewer.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@
703703
</div>
704704
</dialog>
705705

706-
<dialog id="printServiceDialog" style="min-width: 200px;">
706+
<dialog id="printServiceDialog" class="print-service-dialog">
707707
<div class="row">
708708
<span data-l10n-id="pdfjs-print-progress-message"></span>
709709
</div>

lib/src/ng2-pdfjs-viewer.component.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,16 @@ import { ChangeOriginTracker } from "./utils/ChangeOriginTracker";
140140
transform: rotate(360deg);
141141
}
142142
}
143+
144+
/* Iframe border styling */
145+
.ng2-pdfjs-viewer-iframe {
146+
border: 0;
147+
}
148+
149+
/* Dynamic border classes */
150+
.ng2-pdfjs-viewer-iframe.has-border {
151+
border: 1px solid #ccc;
152+
}
143153
`,
144154
],
145155
template: `
@@ -148,7 +158,7 @@ import { ChangeOriginTracker } from "./utils/ChangeOriginTracker";
148158
[title]="iframeTitle || 'PDF document viewer'"
149159
[hidden]="externalWindow || (!externalWindow && !pdfSrc)"
150160
sandbox="allow-forms allow-scripts allow-same-origin allow-modals"
151-
[style.border]="iframeBorder"
161+
[class]="getIframeClasses()"
152162
#iframe
153163
width="100%"
154164
height="100%"
@@ -362,6 +372,19 @@ export class PdfJsViewerComponent
362372
};
363373
}
364374

375+
// Helper method to get iframe CSS classes
376+
public getIframeClasses(): string {
377+
const classes = ['ng2-pdfjs-viewer-iframe'];
378+
379+
// Add border class if iframeBorder is set and not "0"
380+
if (this.iframeBorder && this.iframeBorder !== "0" && this.iframeBorder !== 0) {
381+
classes.push('has-border');
382+
}
383+
384+
return classes.join(' ');
385+
}
386+
387+
365388
// Error template button actions
366389
public reloadViewer(): void {
367390
this.refresh();

lib/v5-upgrade.md

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,68 @@
163163

164164
## Future Upgrade Process
165165

166+
### Standard PDF.js Upgrade Steps
167+
166168
1. **Download new PDF.js version**
167-
2. **Replace all PDF.js files** (viewer.mjs, viewer.html, viewer.css, etc.)
169+
2. **Replace core PDF.js files**:
170+
- `viewer.mjs`
171+
- `viewer.html` ⚠️ **Manual edits required** (see below)
172+
- `viewer.css` ⚠️ **Manual edits required** (see below)
173+
- All other PDF.js files (worker, fonts, images, etc.)
168174
3. **Preserve `postmessage-wrapper.js`** (single integration file)
169-
4. **Test functionality** - verify all features work
170-
5. **Update wrapper if needed** (much easier than merging patches)
175+
4. **Re-apply manual edits** (see sections below)
176+
5. **Test functionality** - verify all features work
177+
6. **Update wrapper if needed** (much easier than merging patches)
178+
179+
### Manual Edits Required for Each Upgrade
180+
181+
#### 1. viewer.html - PostMessage Wrapper Integration
182+
**Location**: After the closing `</div>` tag (around line 740)
183+
**Purpose**: Include our custom postmessage wrapper for Angular integration
184+
185+
```html
186+
<!-- Add this script tag after the main viewer content -->
187+
<script src="postmessage-wrapper.js"></script>
188+
```
189+
190+
#### 2. viewer.html - CSP Compliance Fix
191+
**Location**: Line ~706 (printServiceDialog)
192+
**Purpose**: Remove inline styles for CSP compliance
193+
194+
**Change from:**
195+
```html
196+
<dialog id="printServiceDialog" style="min-width: 200px;">
197+
```
198+
199+
**Change to:**
200+
```html
201+
<dialog id="printServiceDialog" class="print-service-dialog">
202+
```
203+
204+
#### 3. viewer.css - Print Service Dialog Styling
205+
**Location**: After `#printButton::before` styles (around line 5300)
206+
**Purpose**: Add CSS class for print service dialog
207+
208+
```css
209+
/* Print service dialog styling */
210+
.print-service-dialog {
211+
min-width: 200px;
212+
}
213+
```
214+
215+
### Upgrade Checklist
216+
217+
- [ ] Download new PDF.js version
218+
- [ ] Replace `viewer.mjs` and other core files
219+
- [ ] Replace `viewer.html` and add postmessage wrapper script
220+
- [ ] Remove inline style from `printServiceDialog` in `viewer.html`
221+
- [ ] Replace `viewer.css` and add print service dialog class
222+
- [ ] Verify `postmessage-wrapper.js` is preserved
223+
- [ ] Test component functionality
224+
- [ ] Verify CSP compliance (no inline style violations)
225+
- [ ] Update this documentation if new manual edits are needed
171226

172-
**Proven Success**: v5.3.93 upgrade required **zero code changes** and worked immediately.
227+
**Proven Success**: v5.3.93 upgrade required **zero code changes** and worked immediately after applying the manual edits above.
173228

174229
---
175230

0 commit comments

Comments
 (0)