Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Line measurement labels match the theme
- Remove hidden layers from PDF when exporting

## [1.3.0] - 2025-06-25

Expand Down
26 changes: 23 additions & 3 deletions app/_components/pdf-custom-renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,31 @@ export default function CustomRenderer() {
}
async function optionalContentConfigPromise(pdf: PDFDocumentProxy) {
const optionalContentConfig = await pdf.getOptionalContentConfig();
for (const layer of Object.values(layers)) {
for (const id of layer.ids) {
optionalContentConfig.setVisibility(id, layer.visible);
const groups = await (optionalContentConfig as any).getGroups();

if (groups) {
for (const [id, group] of Object.entries(groups)) {
const groupName = (group as any).name || "";
const cleanPDFName = groupName
.replace(/^\//, "") // Remove the leading slash used by pdf.js
.replace(/[()]/g, "")
.trim()
.toLowerCase();

const layerSetting = Object.values(layers).find(
(l) =>
l.name.replace(/[()]/g, "").trim().toLowerCase() === cleanPDFName,
);

if (layerSetting) {
optionalContentConfig.setVisibility(id, layerSetting.visible);
} else {
// Hide any orphaned layers that weren't explicitly matched
optionalContentConfig.setVisibility(id, false);
}
}
}

return optionalContentConfig;
}

Expand Down
Loading