1#![allow(
6 clippy::too_many_lines,
7 clippy::match_same_arms,
8 clippy::doc_markdown,
9 reason = "generated: one match arm per code; summaries are codes.json text"
10)]
11
12use crate::ErrorKind;
13
14pub const DOCS_URL_BASE: &str = "https://docs.laminapdf.com/reference/codes/";
18
19pub const DOCS_URL_SUFFIX: &str = "/";
23
24const fn bytes_eq(a: &[u8], b: &[u8]) -> bool {
26 if a.len() != b.len() {
27 return false;
28 }
29 let (mut a, mut b) = (a, b);
30 while let ([x, a_rest @ ..], [y, b_rest @ ..]) = (a, b) {
31 if *x != *y {
32 return false;
33 }
34 a = a_rest;
35 b = b_rest;
36 }
37 true
38}
39
40#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
45#[non_exhaustive]
46pub enum ErrorCode {
47 NotPdf,
49 MissingRoot,
51 ReferenceCycle,
53 LimitExceeded,
55 Strict,
57 DataPending,
59 Source,
61 Type,
63 InvalidStructure,
65 UnsetObject,
67 RepairedBase,
69 EncryptedBase,
71 PasswordRequired,
73 WrongPassword,
75 UnsupportedSecurityHandler,
77 UnexpectedEof,
79 Syntax,
81 UnsupportedFilter,
83 Decompress,
85 NestedTransaction,
87 NoTransaction,
89 UnknownPage,
91 DirectPage,
93 UnsupportedVersion,
95 InvalidOpLog,
97 SavedNotRebased,
99 NoPendingSave,
101 MalformedXmp,
103 UnknownSource,
105 OpenActionNotDestination,
107 UnknownOutlineItem,
109 DirectOutlineItem,
111 OutlineNotASibling,
113 OutlineMoveIntoItself,
115 UnknownNamedDestination,
117 NamedDestinationExists,
119 EmptyDestinationName,
121 LinkUriRefused,
123 ViewNotFinite,
125 XmpClaimReadOnly,
127 InvalidXmpPacket,
129 InvalidXmpProperty,
131 NoPagesLeft,
133 InvalidOp,
135 UnknownAnnotation,
137 AnnotationLocked,
139 AnnotationNotEditable,
141 NotALink,
143 LinkNotTagged,
145 AppearanceUnavailable,
147 AppearanceNeedsText,
149 AnnotationGlyphMissing,
151 AnnotationFontInvalid,
153 InvalidLabelRanges,
155 ContentObjectStale,
157 ContentNotEditable,
159 UnknownBlob,
161 ImagesUnavailable,
163 FlattenWidget,
165 UnknownAttachment,
167 AttachmentTooLarge,
169 Sink,
171 NotRebased,
173 SinkNotEmpty,
175 WouldInvalidateSignatures,
177 RequiresRewrite,
179 InvalidFont,
181 CollectionIndex,
183 UnknownAxis,
185 FontNotEmbeddable,
187 MissingGlyph,
189 GlyphOutOfRange,
191 UnknownFont,
193 SubsetFailed,
195 InvalidAxisValue,
197 WrongDocument,
199 InvalidFeature,
201 InvalidTextRange,
203 InvalidSpans,
205 UnsupportedLayoutOption,
207 FontMismatch,
209 EncodingFull,
211 FontNotShapable,
213 InvalidImage,
215 UnsupportedImage,
217 ImageTooLarge,
219 ImageDataLength,
221 InvalidIccProfile,
223 ColorComponents,
225 InvalidColor,
227 InvalidGeometry,
229 TextOverflow,
231 PageIndexOutOfRange,
233 UnknownDestination,
235 InvalidPageLabels,
237 TagElementNotOpen,
239 TagElementUnclosed,
241 ProfileVersionConflict,
243 MissingTitle,
245 MissingLang,
247 MissingAltText,
249 UntaggedContent,
251 HeadingLevelSkipped,
253 UnnumberedHeadingMisused,
255 InvalidStructureNesting,
257 LinkWithoutStructure,
259 LinkWithoutContents,
261 FontNotEmbedded,
263 GlyphWithoutUnicode,
265 DeviceColorWithoutOutputIntent,
267 EmbeddedFileForbidden,
269 EmbeddedFileWithoutMimeType,
271 FlowContentTooLarge,
273 FlowLayoutUnstable,
275 InvalidDocument,
277 TemplateDataMissing,
279 TemplateDataType,
281 TemplateTooLarge,
283 RenderTooLarge,
285 RenderFailed,
287 RenderBackendUnavailable,
289 ExportFailed,
291 ModelFailed,
293 ModelResultUnexpected,
295 ModelNeedsHost,
297 Cancelled,
299 JobFinished,
301 DocumentChanged,
303 RevisionIndexOutOfRange,
305 NoBookmarks,
307 BuilderFinished,
309 Disposed,
311 InvalidArgument,
313 SourceBudgetExceeded,
315 UnknownOption,
317 InvalidCommandLine,
319 InvalidPageRange,
321 BinaryOutputToTerminal,
323 UnknownCode,
325 OverwriteRefused,
327 InputUnreadable,
329 OutputUnwritable,
331 PathOutsideRoots,
333}
334
335impl ErrorCode {
336 pub const ALL: &'static [Self] = &[
340 Self::NotPdf,
341 Self::MissingRoot,
342 Self::ReferenceCycle,
343 Self::LimitExceeded,
344 Self::Strict,
345 Self::DataPending,
346 Self::Source,
347 Self::Type,
348 Self::InvalidStructure,
349 Self::UnsetObject,
350 Self::RepairedBase,
351 Self::EncryptedBase,
352 Self::PasswordRequired,
353 Self::WrongPassword,
354 Self::UnsupportedSecurityHandler,
355 Self::UnexpectedEof,
356 Self::Syntax,
357 Self::UnsupportedFilter,
358 Self::Decompress,
359 Self::NestedTransaction,
360 Self::NoTransaction,
361 Self::UnknownPage,
362 Self::DirectPage,
363 Self::UnsupportedVersion,
364 Self::InvalidOpLog,
365 Self::SavedNotRebased,
366 Self::NoPendingSave,
367 Self::MalformedXmp,
368 Self::UnknownSource,
369 Self::OpenActionNotDestination,
370 Self::UnknownOutlineItem,
371 Self::DirectOutlineItem,
372 Self::OutlineNotASibling,
373 Self::OutlineMoveIntoItself,
374 Self::UnknownNamedDestination,
375 Self::NamedDestinationExists,
376 Self::EmptyDestinationName,
377 Self::LinkUriRefused,
378 Self::ViewNotFinite,
379 Self::XmpClaimReadOnly,
380 Self::InvalidXmpPacket,
381 Self::InvalidXmpProperty,
382 Self::NoPagesLeft,
383 Self::InvalidOp,
384 Self::UnknownAnnotation,
385 Self::AnnotationLocked,
386 Self::AnnotationNotEditable,
387 Self::NotALink,
388 Self::LinkNotTagged,
389 Self::AppearanceUnavailable,
390 Self::AppearanceNeedsText,
391 Self::AnnotationGlyphMissing,
392 Self::AnnotationFontInvalid,
393 Self::InvalidLabelRanges,
394 Self::ContentObjectStale,
395 Self::ContentNotEditable,
396 Self::UnknownBlob,
397 Self::ImagesUnavailable,
398 Self::FlattenWidget,
399 Self::UnknownAttachment,
400 Self::AttachmentTooLarge,
401 Self::Sink,
402 Self::NotRebased,
403 Self::SinkNotEmpty,
404 Self::WouldInvalidateSignatures,
405 Self::RequiresRewrite,
406 Self::InvalidFont,
407 Self::CollectionIndex,
408 Self::UnknownAxis,
409 Self::FontNotEmbeddable,
410 Self::MissingGlyph,
411 Self::GlyphOutOfRange,
412 Self::UnknownFont,
413 Self::SubsetFailed,
414 Self::InvalidAxisValue,
415 Self::WrongDocument,
416 Self::InvalidFeature,
417 Self::InvalidTextRange,
418 Self::InvalidSpans,
419 Self::UnsupportedLayoutOption,
420 Self::FontMismatch,
421 Self::EncodingFull,
422 Self::FontNotShapable,
423 Self::InvalidImage,
424 Self::UnsupportedImage,
425 Self::ImageTooLarge,
426 Self::ImageDataLength,
427 Self::InvalidIccProfile,
428 Self::ColorComponents,
429 Self::InvalidColor,
430 Self::InvalidGeometry,
431 Self::TextOverflow,
432 Self::PageIndexOutOfRange,
433 Self::UnknownDestination,
434 Self::InvalidPageLabels,
435 Self::TagElementNotOpen,
436 Self::TagElementUnclosed,
437 Self::ProfileVersionConflict,
438 Self::MissingTitle,
439 Self::MissingLang,
440 Self::MissingAltText,
441 Self::UntaggedContent,
442 Self::HeadingLevelSkipped,
443 Self::UnnumberedHeadingMisused,
444 Self::InvalidStructureNesting,
445 Self::LinkWithoutStructure,
446 Self::LinkWithoutContents,
447 Self::FontNotEmbedded,
448 Self::GlyphWithoutUnicode,
449 Self::DeviceColorWithoutOutputIntent,
450 Self::EmbeddedFileForbidden,
451 Self::EmbeddedFileWithoutMimeType,
452 Self::FlowContentTooLarge,
453 Self::FlowLayoutUnstable,
454 Self::InvalidDocument,
455 Self::TemplateDataMissing,
456 Self::TemplateDataType,
457 Self::TemplateTooLarge,
458 Self::RenderTooLarge,
459 Self::RenderFailed,
460 Self::RenderBackendUnavailable,
461 Self::ExportFailed,
462 Self::ModelFailed,
463 Self::ModelResultUnexpected,
464 Self::ModelNeedsHost,
465 Self::Cancelled,
466 Self::JobFinished,
467 Self::DocumentChanged,
468 Self::RevisionIndexOutOfRange,
469 Self::NoBookmarks,
470 Self::BuilderFinished,
471 Self::Disposed,
472 Self::InvalidArgument,
473 Self::SourceBudgetExceeded,
474 Self::UnknownOption,
475 Self::InvalidCommandLine,
476 Self::InvalidPageRange,
477 Self::BinaryOutputToTerminal,
478 Self::UnknownCode,
479 Self::OverwriteRefused,
480 Self::InputUnreadable,
481 Self::OutputUnwritable,
482 Self::PathOutsideRoots,
483 ];
484
485 #[must_use]
489 pub const fn from_code(code: &str) -> Option<Self> {
490 let mut rest = Self::ALL;
491 while let [first, tail @ ..] = rest {
492 if bytes_eq(first.as_str().as_bytes(), code.as_bytes()) {
493 return Some(*first);
494 }
495 rest = tail;
496 }
497 None
498 }
499
500 #[must_use]
504 pub const fn as_str(self) -> &'static str {
505 match self {
506 Self::NotPdf => "not-pdf",
507 Self::MissingRoot => "missing-root",
508 Self::ReferenceCycle => "reference-cycle",
509 Self::LimitExceeded => "limit-exceeded",
510 Self::Strict => "strict",
511 Self::DataPending => "data-pending",
512 Self::Source => "source",
513 Self::Type => "type",
514 Self::InvalidStructure => "invalid-structure",
515 Self::UnsetObject => "unset-object",
516 Self::RepairedBase => "repaired-base",
517 Self::EncryptedBase => "encrypted-base",
518 Self::PasswordRequired => "password-required",
519 Self::WrongPassword => "wrong-password",
520 Self::UnsupportedSecurityHandler => "unsupported-security-handler",
521 Self::UnexpectedEof => "unexpected-eof",
522 Self::Syntax => "syntax",
523 Self::UnsupportedFilter => "unsupported-filter",
524 Self::Decompress => "decompress",
525 Self::NestedTransaction => "nested-transaction",
526 Self::NoTransaction => "no-transaction",
527 Self::UnknownPage => "unknown-page",
528 Self::DirectPage => "direct-page",
529 Self::UnsupportedVersion => "unsupported-version",
530 Self::InvalidOpLog => "invalid-op-log",
531 Self::SavedNotRebased => "saved-not-rebased",
532 Self::NoPendingSave => "no-pending-save",
533 Self::MalformedXmp => "malformed-xmp",
534 Self::UnknownSource => "unknown-source",
535 Self::OpenActionNotDestination => "open-action-not-destination",
536 Self::UnknownOutlineItem => "unknown-outline-item",
537 Self::DirectOutlineItem => "direct-outline-item",
538 Self::OutlineNotASibling => "outline-not-a-sibling",
539 Self::OutlineMoveIntoItself => "outline-move-into-itself",
540 Self::UnknownNamedDestination => "unknown-named-destination",
541 Self::NamedDestinationExists => "named-destination-exists",
542 Self::EmptyDestinationName => "empty-destination-name",
543 Self::LinkUriRefused => "link-uri-refused",
544 Self::ViewNotFinite => "view-not-finite",
545 Self::XmpClaimReadOnly => "xmp-claim-read-only",
546 Self::InvalidXmpPacket => "invalid-xmp-packet",
547 Self::InvalidXmpProperty => "invalid-xmp-property",
548 Self::NoPagesLeft => "no-pages-left",
549 Self::InvalidOp => "invalid-op",
550 Self::UnknownAnnotation => "unknown-annotation",
551 Self::AnnotationLocked => "annotation-locked",
552 Self::AnnotationNotEditable => "annotation-not-editable",
553 Self::NotALink => "not-a-link",
554 Self::LinkNotTagged => "link-not-tagged",
555 Self::AppearanceUnavailable => "appearance-unavailable",
556 Self::AppearanceNeedsText => "appearance-needs-text",
557 Self::AnnotationGlyphMissing => "annotation-glyph-missing",
558 Self::AnnotationFontInvalid => "annotation-font-invalid",
559 Self::InvalidLabelRanges => "invalid-label-ranges",
560 Self::ContentObjectStale => "content-object-stale",
561 Self::ContentNotEditable => "content-not-editable",
562 Self::UnknownBlob => "unknown-blob",
563 Self::ImagesUnavailable => "images-unavailable",
564 Self::FlattenWidget => "flatten-widget",
565 Self::UnknownAttachment => "unknown-attachment",
566 Self::AttachmentTooLarge => "attachment-too-large",
567 Self::Sink => "sink",
568 Self::NotRebased => "not-rebased",
569 Self::SinkNotEmpty => "sink-not-empty",
570 Self::WouldInvalidateSignatures => "would-invalidate-signatures",
571 Self::RequiresRewrite => "requires-rewrite",
572 Self::InvalidFont => "invalid-font",
573 Self::CollectionIndex => "collection-index",
574 Self::UnknownAxis => "unknown-axis",
575 Self::FontNotEmbeddable => "font-not-embeddable",
576 Self::MissingGlyph => "missing-glyph",
577 Self::GlyphOutOfRange => "glyph-out-of-range",
578 Self::UnknownFont => "unknown-font",
579 Self::SubsetFailed => "subset-failed",
580 Self::InvalidAxisValue => "invalid-axis-value",
581 Self::WrongDocument => "wrong-document",
582 Self::InvalidFeature => "invalid-feature",
583 Self::InvalidTextRange => "invalid-text-range",
584 Self::InvalidSpans => "invalid-spans",
585 Self::UnsupportedLayoutOption => "unsupported-layout-option",
586 Self::FontMismatch => "font-mismatch",
587 Self::EncodingFull => "encoding-full",
588 Self::FontNotShapable => "font-not-shapable",
589 Self::InvalidImage => "invalid-image",
590 Self::UnsupportedImage => "unsupported-image",
591 Self::ImageTooLarge => "image-too-large",
592 Self::ImageDataLength => "image-data-length",
593 Self::InvalidIccProfile => "invalid-icc-profile",
594 Self::ColorComponents => "color-components",
595 Self::InvalidColor => "invalid-color",
596 Self::InvalidGeometry => "invalid-geometry",
597 Self::TextOverflow => "text-overflow",
598 Self::PageIndexOutOfRange => "page-index-out-of-range",
599 Self::UnknownDestination => "unknown-destination",
600 Self::InvalidPageLabels => "invalid-page-labels",
601 Self::TagElementNotOpen => "tag-element-not-open",
602 Self::TagElementUnclosed => "tag-element-unclosed",
603 Self::ProfileVersionConflict => "profile-version-conflict",
604 Self::MissingTitle => "missing-title",
605 Self::MissingLang => "missing-lang",
606 Self::MissingAltText => "missing-alt-text",
607 Self::UntaggedContent => "untagged-content",
608 Self::HeadingLevelSkipped => "heading-level-skipped",
609 Self::UnnumberedHeadingMisused => "unnumbered-heading-misused",
610 Self::InvalidStructureNesting => "invalid-structure-nesting",
611 Self::LinkWithoutStructure => "link-without-structure",
612 Self::LinkWithoutContents => "link-without-contents",
613 Self::FontNotEmbedded => "font-not-embedded",
614 Self::GlyphWithoutUnicode => "glyph-without-unicode",
615 Self::DeviceColorWithoutOutputIntent => "device-color-without-output-intent",
616 Self::EmbeddedFileForbidden => "embedded-file-forbidden",
617 Self::EmbeddedFileWithoutMimeType => "embedded-file-without-mime-type",
618 Self::FlowContentTooLarge => "flow-content-too-large",
619 Self::FlowLayoutUnstable => "flow-layout-unstable",
620 Self::InvalidDocument => "invalid-document",
621 Self::TemplateDataMissing => "template-data-missing",
622 Self::TemplateDataType => "template-data-type",
623 Self::TemplateTooLarge => "template-too-large",
624 Self::RenderTooLarge => "render-too-large",
625 Self::RenderFailed => "render-failed",
626 Self::RenderBackendUnavailable => "render-backend-unavailable",
627 Self::ExportFailed => "export-failed",
628 Self::ModelFailed => "model-failed",
629 Self::ModelResultUnexpected => "model-result-unexpected",
630 Self::ModelNeedsHost => "model-needs-host",
631 Self::Cancelled => "cancelled",
632 Self::JobFinished => "job-finished",
633 Self::DocumentChanged => "document-changed",
634 Self::RevisionIndexOutOfRange => "revision-index-out-of-range",
635 Self::NoBookmarks => "no-bookmarks",
636 Self::BuilderFinished => "builder-finished",
637 Self::Disposed => "disposed",
638 Self::InvalidArgument => "invalid-argument",
639 Self::SourceBudgetExceeded => "source-budget-exceeded",
640 Self::UnknownOption => "unknown-option",
641 Self::InvalidCommandLine => "invalid-command-line",
642 Self::InvalidPageRange => "invalid-page-range",
643 Self::BinaryOutputToTerminal => "binary-output-to-terminal",
644 Self::UnknownCode => "unknown-code",
645 Self::OverwriteRefused => "overwrite-refused",
646 Self::InputUnreadable => "input-unreadable",
647 Self::OutputUnwritable => "output-unwritable",
648 Self::PathOutsideRoots => "path-outside-roots",
649 }
650 }
651
652 #[must_use]
656 pub const fn kind(self) -> ErrorKind {
657 match self {
658 Self::NotPdf => ErrorKind::Input,
659 Self::MissingRoot => ErrorKind::Input,
660 Self::ReferenceCycle => ErrorKind::Input,
661 Self::LimitExceeded => ErrorKind::Limit,
662 Self::Strict => ErrorKind::Input,
663 Self::DataPending => ErrorKind::State,
664 Self::Source => ErrorKind::Io,
665 Self::Type => ErrorKind::Input,
666 Self::InvalidStructure => ErrorKind::Input,
667 Self::UnsetObject => ErrorKind::Internal,
668 Self::RepairedBase => ErrorKind::State,
669 Self::EncryptedBase => ErrorKind::Unsupported,
670 Self::PasswordRequired => ErrorKind::Security,
671 Self::WrongPassword => ErrorKind::Security,
672 Self::UnsupportedSecurityHandler => ErrorKind::Unsupported,
673 Self::UnexpectedEof => ErrorKind::Input,
674 Self::Syntax => ErrorKind::Input,
675 Self::UnsupportedFilter => ErrorKind::Unsupported,
676 Self::Decompress => ErrorKind::Input,
677 Self::NestedTransaction => ErrorKind::State,
678 Self::NoTransaction => ErrorKind::State,
679 Self::UnknownPage => ErrorKind::Usage,
680 Self::DirectPage => ErrorKind::Unsupported,
681 Self::UnsupportedVersion => ErrorKind::Unsupported,
682 Self::InvalidOpLog => ErrorKind::Input,
683 Self::SavedNotRebased => ErrorKind::State,
684 Self::NoPendingSave => ErrorKind::State,
685 Self::MalformedXmp => ErrorKind::Input,
686 Self::UnknownSource => ErrorKind::Usage,
687 Self::OpenActionNotDestination => ErrorKind::Usage,
688 Self::UnknownOutlineItem => ErrorKind::Usage,
689 Self::DirectOutlineItem => ErrorKind::Unsupported,
690 Self::OutlineNotASibling => ErrorKind::Usage,
691 Self::OutlineMoveIntoItself => ErrorKind::Usage,
692 Self::UnknownNamedDestination => ErrorKind::Usage,
693 Self::NamedDestinationExists => ErrorKind::Usage,
694 Self::EmptyDestinationName => ErrorKind::Usage,
695 Self::LinkUriRefused => ErrorKind::Usage,
696 Self::ViewNotFinite => ErrorKind::Usage,
697 Self::XmpClaimReadOnly => ErrorKind::Usage,
698 Self::InvalidXmpPacket => ErrorKind::Input,
699 Self::InvalidXmpProperty => ErrorKind::Usage,
700 Self::NoPagesLeft => ErrorKind::Usage,
701 Self::InvalidOp => ErrorKind::Usage,
702 Self::UnknownAnnotation => ErrorKind::Usage,
703 Self::AnnotationLocked => ErrorKind::State,
704 Self::AnnotationNotEditable => ErrorKind::Unsupported,
705 Self::NotALink => ErrorKind::Usage,
706 Self::LinkNotTagged => ErrorKind::Unsupported,
707 Self::AppearanceUnavailable => ErrorKind::Unsupported,
708 Self::AppearanceNeedsText => ErrorKind::Unsupported,
709 Self::AnnotationGlyphMissing => ErrorKind::Usage,
710 Self::AnnotationFontInvalid => ErrorKind::Usage,
711 Self::InvalidLabelRanges => ErrorKind::Usage,
712 Self::ContentObjectStale => ErrorKind::State,
713 Self::ContentNotEditable => ErrorKind::Unsupported,
714 Self::UnknownBlob => ErrorKind::Usage,
715 Self::ImagesUnavailable => ErrorKind::Unsupported,
716 Self::FlattenWidget => ErrorKind::Usage,
717 Self::UnknownAttachment => ErrorKind::Usage,
718 Self::AttachmentTooLarge => ErrorKind::Limit,
719 Self::Sink => ErrorKind::Io,
720 Self::NotRebased => ErrorKind::State,
721 Self::SinkNotEmpty => ErrorKind::Usage,
722 Self::WouldInvalidateSignatures => ErrorKind::Security,
723 Self::RequiresRewrite => ErrorKind::State,
724 Self::InvalidFont => ErrorKind::Input,
725 Self::CollectionIndex => ErrorKind::Usage,
726 Self::UnknownAxis => ErrorKind::Usage,
727 Self::FontNotEmbeddable => ErrorKind::Usage,
728 Self::MissingGlyph => ErrorKind::Input,
729 Self::GlyphOutOfRange => ErrorKind::Usage,
730 Self::UnknownFont => ErrorKind::Usage,
731 Self::SubsetFailed => ErrorKind::Unsupported,
732 Self::InvalidAxisValue => ErrorKind::Usage,
733 Self::WrongDocument => ErrorKind::Usage,
734 Self::InvalidFeature => ErrorKind::Usage,
735 Self::InvalidTextRange => ErrorKind::Usage,
736 Self::InvalidSpans => ErrorKind::Usage,
737 Self::UnsupportedLayoutOption => ErrorKind::Unsupported,
738 Self::FontMismatch => ErrorKind::Usage,
739 Self::EncodingFull => ErrorKind::Limit,
740 Self::FontNotShapable => ErrorKind::Unsupported,
741 Self::InvalidImage => ErrorKind::Input,
742 Self::UnsupportedImage => ErrorKind::Unsupported,
743 Self::ImageTooLarge => ErrorKind::Limit,
744 Self::ImageDataLength => ErrorKind::Usage,
745 Self::InvalidIccProfile => ErrorKind::Input,
746 Self::ColorComponents => ErrorKind::Usage,
747 Self::InvalidColor => ErrorKind::Usage,
748 Self::InvalidGeometry => ErrorKind::Usage,
749 Self::TextOverflow => ErrorKind::Usage,
750 Self::PageIndexOutOfRange => ErrorKind::Usage,
751 Self::UnknownDestination => ErrorKind::Usage,
752 Self::InvalidPageLabels => ErrorKind::Usage,
753 Self::TagElementNotOpen => ErrorKind::Usage,
754 Self::TagElementUnclosed => ErrorKind::Usage,
755 Self::ProfileVersionConflict => ErrorKind::Usage,
756 Self::MissingTitle => ErrorKind::Usage,
757 Self::MissingLang => ErrorKind::Usage,
758 Self::MissingAltText => ErrorKind::Usage,
759 Self::UntaggedContent => ErrorKind::Usage,
760 Self::HeadingLevelSkipped => ErrorKind::Usage,
761 Self::UnnumberedHeadingMisused => ErrorKind::Usage,
762 Self::InvalidStructureNesting => ErrorKind::Usage,
763 Self::LinkWithoutStructure => ErrorKind::Usage,
764 Self::LinkWithoutContents => ErrorKind::Usage,
765 Self::FontNotEmbedded => ErrorKind::Usage,
766 Self::GlyphWithoutUnicode => ErrorKind::Usage,
767 Self::DeviceColorWithoutOutputIntent => ErrorKind::Usage,
768 Self::EmbeddedFileForbidden => ErrorKind::Usage,
769 Self::EmbeddedFileWithoutMimeType => ErrorKind::Usage,
770 Self::FlowContentTooLarge => ErrorKind::Usage,
771 Self::FlowLayoutUnstable => ErrorKind::Internal,
772 Self::InvalidDocument => ErrorKind::Usage,
773 Self::TemplateDataMissing => ErrorKind::Usage,
774 Self::TemplateDataType => ErrorKind::Usage,
775 Self::TemplateTooLarge => ErrorKind::Usage,
776 Self::RenderTooLarge => ErrorKind::Limit,
777 Self::RenderFailed => ErrorKind::Input,
778 Self::RenderBackendUnavailable => ErrorKind::Io,
779 Self::ExportFailed => ErrorKind::Internal,
780 Self::ModelFailed => ErrorKind::Internal,
781 Self::ModelResultUnexpected => ErrorKind::Usage,
782 Self::ModelNeedsHost => ErrorKind::Usage,
783 Self::Cancelled => ErrorKind::Cancelled,
784 Self::JobFinished => ErrorKind::State,
785 Self::DocumentChanged => ErrorKind::State,
786 Self::RevisionIndexOutOfRange => ErrorKind::Usage,
787 Self::NoBookmarks => ErrorKind::Usage,
788 Self::BuilderFinished => ErrorKind::State,
789 Self::Disposed => ErrorKind::State,
790 Self::InvalidArgument => ErrorKind::Usage,
791 Self::SourceBudgetExceeded => ErrorKind::Limit,
792 Self::UnknownOption => ErrorKind::Usage,
793 Self::InvalidCommandLine => ErrorKind::Usage,
794 Self::InvalidPageRange => ErrorKind::Usage,
795 Self::BinaryOutputToTerminal => ErrorKind::Usage,
796 Self::UnknownCode => ErrorKind::Usage,
797 Self::OverwriteRefused => ErrorKind::State,
798 Self::InputUnreadable => ErrorKind::Io,
799 Self::OutputUnwritable => ErrorKind::Io,
800 Self::PathOutsideRoots => ErrorKind::Security,
801 }
802 }
803
804 #[must_use]
808 pub const fn summary(self) -> &'static str {
809 match self {
810 Self::NotPdf => "the input does not look like a PDF at all",
811 Self::MissingRoot => "no document catalog (/Root) was found, even after repair",
812 Self::ReferenceCycle => "a reference chain or the page tree loops back on itself",
813 Self::LimitExceeded => "a hard Limits value was exceeded",
814 Self::Strict => "strict mode refused something the tolerant reader would have repaired",
815 Self::DataPending => "the ByteSource has not fetched the byte ranges the call needs yet",
816 Self::Source => "the ByteSource failed to read",
817 Self::Type => "an object had a different type than the structure requires",
818 Self::InvalidStructure => "an object stream, xref section or filter parameter was malformed",
819 Self::UnsetObject => "a writer object number was reserved but never given a value",
820 Self::RepairedBase => "an incremental update was requested for a document whose xref needed repair",
821 Self::EncryptedBase => "a save of an encrypted document was requested",
822 Self::PasswordRequired => "the document is encrypted with a user password and none was given",
823 Self::WrongPassword => "the given password is neither the user nor the owner password",
824 Self::UnsupportedSecurityHandler => "the document uses a security handler Lamina PDF cannot decrypt",
825 Self::UnexpectedEof => "the input ended before a complete token or object was read",
826 Self::Syntax => "a token or structure did not match the PDF grammar",
827 Self::UnsupportedFilter => "a stream uses a filter Lamina PDF does not implement",
828 Self::Decompress => "compressed stream data was corrupt",
829 Self::NestedTransaction => "a transaction was started, or undo or redo called, while one is open",
830 Self::NoTransaction => "apply, commit or rollback was called without an open transaction",
831 Self::UnknownPage => "an op names a page the document does not have",
832 Self::DirectPage => "the page is a direct dictionary, which ops cannot edit yet",
833 Self::UnsupportedVersion => "an op log has a schema version this reader does not know",
834 Self::InvalidOpLog => "an op log does not parse: an unknown op or field, a bad value, or not JSON",
835 Self::SavedNotRebased => "the document was saved to a sink Lamina PDF cannot read back and waits for rebase",
836 Self::NoPendingSave => "rebase was called without a save waiting for it",
837 Self::MalformedXmp => "a metadata edit would replace the document's XMP packet, which can't be read, losing what it holds",
838 Self::UnknownSource => "an op or a call names a source document that was not added to the session",
839 Self::OpenActionNotDestination => "an op would replace or remove the document's open action, which is an action other than a destination",
840 Self::UnknownOutlineItem => "an outline op names a bookmark the outline does not have",
841 Self::DirectOutlineItem => "the bookmark is stored inside another item rather than as an object of its own, so outline ops can't name it yet",
842 Self::OutlineNotASibling => "the position names a bookmark that is not a child of the parent the op names",
843 Self::OutlineMoveIntoItself => "a move would put a bookmark inside itself or one of its descendants",
844 Self::UnknownNamedDestination => "the op names a destination the file does not define",
845 Self::NamedDestinationExists => "a rename to a name another destination already has",
846 Self::EmptyDestinationName => "a destination name is empty",
847 Self::LinkUriRefused => "a web address that isn't an absolute http, https or mailto address in plain ASCII",
848 Self::ViewNotFinite => "a destination's coordinates and zoom must be finite numbers",
849 Self::XmpClaimReadOnly => "an XMP edit would change the file's PDF/A or PDF/UA identification, which only conversion or a check may set",
850 Self::InvalidXmpPacket => "the XMP packet given to replace the document's doesn't parse",
851 Self::InvalidXmpProperty => "an XMP property edit names a property, or gives a value, that can't be written",
852 Self::NoPagesLeft => "a page deletion would leave the document with no pages",
853 Self::InvalidOp => "an op's values are out of range, such as a page count or a page size",
854 Self::UnknownAnnotation => "the op names an annotation that no page of the document lists",
855 Self::AnnotationLocked => "the annotation's flags forbid the change: Locked forbids deleting it or changing its properties, LockedContents changing its contents",
856 Self::AnnotationNotEditable => "the annotation can't be edited by the annotation ops: it is a form field's widget, or a direct dictionary with no object of its own",
857 Self::NotALink => "a link op names an annotation that isn't a link",
858 Self::LinkNotTagged => "the file claims PDF/UA-1 but has no structure tree for a new link to join",
859 Self::AppearanceUnavailable => "the document has no appearance generator, so it can't draw a new annotation",
860 Self::AppearanceNeedsText => "drawing this text box needs text layout that this build of Lamina PDF leaves out: a font given by its bytes, or a fallback font",
861 Self::AnnotationGlyphMissing => "a character of a text box is in none of its fonts, so it can't be drawn",
862 Self::AnnotationFontInvalid => "a text box's font bytes aren't a font Lamina PDF can read and embed",
863 Self::InvalidLabelRanges => "page label ranges whose first isn't on the first page, that are out of page order or share a page, or that number from 0",
864 Self::ContentObjectStale => "an edit names a content object whose bytes are no longer what the edit expects, so it would change another object",
865 Self::ContentNotEditable => "the content can't be edited: its font, its writing direction, the order of its glyphs, a clip it sets or the state it draws in is one Lamina PDF can't change safely, or it can't be read",
866 Self::UnknownBlob => "an op names bytes by an ID that were not added to the session",
867 Self::ImagesUnavailable => "the document has no image writer, so it can't put a replacement image in the file",
868 Self::FlattenWidget => "flattening names a form field's widget, which annotation flattening leaves alone",
869 Self::UnknownAttachment => "an attachment op names an attachment the document doesn't hold",
870 Self::AttachmentTooLarge => "a file to attach is larger than the document can read back out, so it wasn't attached",
871 Self::Sink => "the sink failed to take the bytes or could not give them back",
872 Self::NotRebased => "the output was written, but rebasing the document onto it failed",
873 Self::SinkNotEmpty => "the sink already held bytes before the save started",
874 Self::WouldInvalidateSignatures => "the save would break one or more signatures",
875 Self::RequiresRewrite => "an incremental save was requested but only a full rewrite is safe",
876 Self::InvalidFont => "font bytes could not be read as a font",
877 Self::CollectionIndex => "a font collection member past the end of the collection was asked for",
878 Self::UnknownAxis => "an instance was asked for on a variation axis the font does not have",
879 Self::FontNotEmbeddable => "the font's OS/2 fsType forbids embedding",
880 Self::MissingGlyph => "the font has no glyph for a character of the text",
881 Self::GlyphOutOfRange => "a glyph ID at or past the font's glyph count was used",
882 Self::UnknownFont => "a FontKey was used with a registry that did not hand it out",
883 Self::SubsetFailed => "subsetting a font failed",
884 Self::InvalidAxisValue => "a variation axis value was NaN or infinite",
885 Self::WrongDocument => "finish_fonts was given a document the registry did not reserve its fonts in",
886 Self::InvalidFeature => "an OpenType feature setting did not parse",
887 Self::InvalidTextRange => "a byte range was out of bounds or not on character boundaries of the text",
888 Self::InvalidSpans => "the styled spans given for a paragraph do not cover its text once, in order",
889 Self::UnsupportedLayoutOption => "a layout option that is not implemented yet was asked for",
890 Self::FontMismatch => "a shaped run was given with a font key for a different font than it was shaped with",
891 Self::EncodingFull => "a standard 14 font has no free one-byte code left for another glyph",
892 Self::FontNotShapable => "a standard 14 font was given to shaping or layout, which need a font program",
893 Self::InvalidImage => "image bytes are not a readable image of the format they were given as",
894 Self::UnsupportedImage => "the image uses a feature that PDF or Lamina PDF does not support",
895 Self::ImageTooLarge => "the image needs more memory than the builder allows (a decoded PNG over 256 MiB, or raw dimensions whose size overflows)",
896 Self::ImageDataLength => "raw image samples are not width x height x channels bytes long",
897 Self::InvalidIccProfile => "the bytes are not a usable ICC profile",
898 Self::ColorComponents => "a colour has the wrong number of components for its colour space",
899 Self::InvalidColor => "a colour string is not of the form #rgb or #rrggbb",
900 Self::InvalidGeometry => "a page size, box, /UserUnit, drawing value (coordinate, matrix, line width, dash, miter limit) or image size is not usable",
901 Self::TextOverflow => "a text box's lines don't all fit its height and its options asked for an error",
902 Self::PageIndexOutOfRange => "a link, outline item or destination names a page index the document doesn't have",
903 Self::UnknownDestination => "a link or outline item names a destination that was never defined",
904 Self::InvalidPageLabels => "page label ranges that don't start at page 0, don't increase, start past the last page or number from 0",
905 Self::TagElementNotOpen => "a structure element resumed or closed isn't open",
906 Self::TagElementUnclosed => "structure elements opened across pages were never closed",
907 Self::ProfileVersionConflict => "the PDF version asked for is one the profile doesn't allow (PDF/UA-1, PDF/A-2 and PDF/A-3 are based on PDF 1.7)",
908 Self::MissingTitle => "PDF/UA-1 needs a document title, and the metadata gives none",
909 Self::MissingLang => "PDF/UA-1 needs the document's natural language, and none was set",
910 Self::MissingAltText => "a Figure or Formula has no alternate text (/Alt or /ActualText), which PDF/UA-1 requires",
911 Self::UntaggedContent => "content was drawn outside every structure element and artifact, which PDF/UA-1 forbids",
912 Self::HeadingLevelSkipped => "a heading skips a level (the first is not H1, or an H3 follows an H1), which PDF/UA-1 forbids",
913 Self::UnnumberedHeadingMisused => "an unnumbered H heading shares its parent with another H, or the document also uses H1-H6, which PDF/UA-1 forbids",
914 Self::InvalidStructureNesting => "a table or list element sits in a parent its type doesn't allow (a TD outside a TR, a P directly in a Table)",
915 Self::LinkWithoutStructure => "a link annotation has no Link structure element (it was drawn inside an artifact), which PDF/UA-1 forbids",
916 Self::LinkWithoutContents => "a link annotation has no description (/Contents), which PDF/UA-1 requires",
917 Self::FontNotEmbedded => "a standard 14 font, which is never embedded, was used under a profile that needs every font embedded",
918 Self::GlyphWithoutUnicode => "a glyph was drawn without a Unicode value, which PDF/A-2u and PDF/UA-1 forbid",
919 Self::DeviceColorWithoutOutputIntent => "a DeviceCMYK colour or image was used, but the PDF/A output intent is sRGB",
920 Self::EmbeddedFileForbidden => "PDF/A-2 doesn't allow attached files that aren't PDF/A themselves",
921 Self::EmbeddedFileWithoutMimeType => "an attached file has no MIME type, which every PDF/A profile requires",
922 Self::FlowContentTooLarge => "a line or a figure of a flow is taller than the page's body, so no page can hold it",
923 Self::FlowLayoutUnstable => "a flow's contents page kept changing its page numbers after four layouts",
924 Self::InvalidDocument => "a laminapdf.document/1 document has an unknown key, a missing one or a value of the wrong kind",
925 Self::TemplateDataMissing => "a template's $data, $each or $item points to a value the data doesn't have",
926 Self::TemplateDataType => "a template's placeholder found data of the wrong kind: $each over something that isn't a list, or text from an object",
927 Self::TemplateTooLarge => "a template would fill in more values, or nest deeper, than a document may hold",
928 Self::RenderTooLarge => "the requested tile is larger than the render limits allow; nothing was allocated",
929 Self::RenderFailed => "the render engine could not open the document or draw the page",
930 Self::RenderBackendUnavailable => "the render engine is not available: its library or module could not be loaded",
931 Self::ExportFailed => "an export's PNG, JPEG or TIFF encoder failed on a page that was drawn",
932 Self::ModelFailed => "a layout model, OCR engine or page renderer plugged into an extraction failed; the extraction stops with no partial result",
933 Self::ModelResultUnexpected => "a model result was handed to an extraction job that hadn't asked for it, or was the other model's result",
934 Self::ModelNeedsHost => "an extraction in one call was given a model whose results only the host can give: a host model, or a plug-in model without a page renderer",
935 Self::Cancelled => "a CancelToken stopped the work; the job is finished and returned no partial result",
936 Self::JobFinished => "a job was stepped after it had finished, failed or been cancelled",
937 Self::DocumentChanged => "the document a job or a contents listing was made from changed (an edit, undo, redo, save or rebase), or a different document was passed to step",
938 Self::RevisionIndexOutOfRange => "an earlier revision was asked for by an index past the file's last revision",
939 Self::NoBookmarks => "a contents page was asked for, but no bookmark goes to a page of the document, so it would list nothing",
940 Self::BuilderFinished => "a builder or one of its pages was used after it finished",
941 Self::Disposed => "a document, builder or other handle was used after free(), or after the using block that held it ended",
942 Self::InvalidArgument => "a value passed to a binding does not have the shape its type declares",
943 Self::SourceBudgetExceeded => "a sparse source was given more bytes than its byte budget allows",
944 Self::UnknownOption => "an options record passed to a binding has a key Lamina PDF does not know",
945 Self::InvalidCommandLine => "the command line doesn't parse: an unknown command or flag, a missing argument, a bad value, or stdin named twice",
946 Self::InvalidPageRange => "a page range doesn't fit the grammar, or names a page the document lacks",
947 Self::BinaryOutputToTerminal => "the command would write a PDF to standard output, and standard output is a terminal",
948 Self::UnknownCode => "explain was given a code that isn't a Lamina PDF error or warning code",
949 Self::OverwriteRefused => "the output file exists, or the command would modify its input in place, and --force wasn't given",
950 Self::InputUnreadable => "an input file, standard input or the password file couldn't be read",
951 Self::OutputUnwritable => "the output couldn't be written: its folder is missing or read-only, the disk is full, or standard output closed",
952 Self::PathOutsideRoots => "laminapdf mcp was given a path outside its --root folders, or a link that leads out of them",
953 }
954 }
955
956 #[must_use]
960 pub const fn hint(self) -> &'static str {
961 match self {
962 Self::NotPdf => "check that the bytes passed to open are a PDF file",
963 Self::MissingRoot => "use another copy of the file: this one has no usable catalog",
964 Self::ReferenceCycle => "use another copy of the file, or repair it with another tool",
965 Self::LimitExceeded => "the input exceeds a safety limit; raise {limit} in Limits only if you trust the input",
966 Self::Strict => "open without strict mode to read the file with repairs, or fix the file",
967 Self::DataPending => "fetch the listed ranges into the source and retry the call",
968 Self::Source => "retry the call, or check the source; the document stays usable",
969 Self::Type => "use another copy of the file, or repair it with another tool",
970 Self::InvalidStructure => "use another copy of the file, or repair it with another tool",
971 Self::UnsetObject => "this is a bug in Lamina PDF: report it with the steps that led to it",
972 Self::RepairedBase => "save with a full rewrite instead of an incremental update",
973 Self::EncryptedBase => "saving encrypted documents is not supported yet; use another tool to decrypt or re-encrypt",
974 Self::PasswordRequired => "pass the document's password in OpenOptions",
975 Self::WrongPassword => "ask for the password again and retry with the correct one",
976 Self::UnsupportedSecurityHandler => "use a tool that supports this encryption to decrypt the file first",
977 Self::UnexpectedEof => "use a complete copy of the file: this one looks truncated",
978 Self::Syntax => "use another copy of the file, or repair it with another tool",
979 Self::UnsupportedFilter => "use a tool that supports the filter to read this stream",
980 Self::Decompress => "use another copy of the file: this stream's data is damaged",
981 Self::NestedTransaction => "commit or roll back the open transaction first, or use a savepoint inside it",
982 Self::NoTransaction => "call begin first, or use transact",
983 Self::UnknownPage => "use a PageId from this document's pages()",
984 Self::DirectPage => "rewrite the file so that every page is an indirect object, or wait for page-structure ops",
985 Self::UnsupportedVersion => "upgrade Lamina PDF to a version that reads this op log version",
986 Self::InvalidOpLog => "validate the op log against the op schema; the samples in fixtures/ops show the format",
987 Self::SavedNotRebased => "call rebase with the saved bytes before applying ops or saving again",
988 Self::NoPendingSave => "call rebase only after a save that returned SavedNotRebased",
989 Self::MalformedXmp => "set replaceMalformed on the edit to replace the packet with a new one, or leave the metadata as it is",
990 Self::UnknownSource => "add the source document's bytes with addSource before applying ops that name it",
991 Self::OpenActionNotDestination => "leave the open page out of the edit, which keeps the open action as it is",
992 Self::UnknownOutlineItem => "read the outline again and use one of its item IDs; an item a previous op deleted is gone",
993 Self::DirectOutlineItem => "apply any other outline op first: it rewrites the outline and gives every bookmark an object and an ID of its own",
994 Self::OutlineNotASibling => "name a position among the parent's own children, or use first or last",
995 Self::OutlineMoveIntoItself => "choose a parent outside the bookmark's own branch",
996 Self::UnknownNamedDestination => "list the file's named destinations and use one of their names",
997 Self::NamedDestinationExists => "choose a name no destination has, or delete the other one first",
998 Self::EmptyDestinationName => "give the destination a name of at least one character",
999 Self::LinkUriRefused => "use a full address such as https://example.com/page; encode other characters with %",
1000 Self::ViewNotFinite => "pass finite numbers, or null to keep the viewer's current value",
1001 Self::XmpClaimReadOnly => "leave the pdfaid: and pdfuaid: properties as they are; edit the other properties, or keep them unchanged in a replaced packet",
1002 Self::InvalidXmpPacket => "fix the XML at the offset in the error's data (reason says what is wrong), then replace the packet again",
1003 Self::InvalidXmpProperty => "check the part the error's reason names: the namespace, prefix, name, value, or the shape a mirrored property needs",
1004 Self::NoPagesLeft => "keep at least one page: delete all but one, or insert a blank page first",
1005 Self::InvalidOp => "insert between 1 and 10,000 pages at a time, each with a width and height above 0 and up to 14,400 points",
1006 Self::UnknownAnnotation => "read the page's annotations again and use an ID from that list",
1007 Self::AnnotationLocked => "clear the lock with an update of its flags first, if you may",
1008 Self::AnnotationNotEditable => "edit a widget through its form field; an annotation stored inside the page's list can't be edited yet",
1009 Self::NotALink => "name a link from the page's links; change other annotations with updateAnnot and deleteAnnot",
1010 Self::LinkNotTagged => "tag the document first, or add the link to a copy that doesn't claim PDF/UA",
1011 Self::AppearanceUnavailable => "edit through the laminapdf crate, which draws appearances, or give laminapdf-ops a generator with Document::with_appearances",
1012 Self::AppearanceNeedsText => "in the extract module, use Helvetica, Times or Courier; otherwise open the document in the WebAssembly text module (pass text: true to init before opening it)",
1013 Self::AnnotationGlyphMissing => "add a fallback font that has the character, or give the box a font that has it",
1014 Self::AnnotationFontInvalid => "give the bytes of a TrueType or OpenType font whose licence allows embedding",
1015 Self::InvalidLabelRanges => "give ranges in page order, the first on the document's first page, each numbered from 1 or more",
1016 Self::ContentObjectStale => "read the page's content objects again and name the object from that list",
1017 Self::ContentNotEditable => "the content stays selectable and readable; the reason says why it can't be changed",
1018 Self::UnknownBlob => "add the bytes with addBlob before applying ops that name them",
1019 Self::ImagesUnavailable => "edit through the laminapdf crate, which writes images, or give laminapdf-ops a writer with Document::with_images",
1020 Self::FlattenWidget => "leave widgets out of the annotations to flatten; flattening form fields needs an edit that knows about their values, which Lamina PDF doesn't have yet, and a signature field is never flattened",
1021 Self::UnknownAttachment => "read the attachments again and use an ID from that list: the attachment was deleted, or the ID comes from another document",
1022 Self::AttachmentTooLarge => "attach a smaller file, or open the document with a higher maxStreamDecoded limit",
1023 Self::Sink => "check the destination and retry the save; the document is unchanged",
1024 Self::NotRebased => "retry rebase with the saved output carried by the error",
1025 Self::SinkNotEmpty => "pass an empty sink: output offsets count from the sink's first byte",
1026 Self::WouldInvalidateSignatures => "save with SaveMode::Auto, or ask the user and retry with SaveOptions::with_invalidate_signatures",
1027 Self::RequiresRewrite => "save with SaveMode::Auto or SaveMode::FullRewrite",
1028 Self::InvalidFont => "pass the complete bytes of a .ttf, .otf, .ttc or .otc file",
1029 Self::CollectionIndex => "use an index below Font::collection_len",
1030 Self::UnknownAxis => "check the font's axes before choosing coordinates, or use a variable font",
1031 Self::FontNotEmbeddable => "use another font, or register it with EmbedPolicy::Override if your licence allows embedding",
1032 Self::MissingGlyph => "use a font that covers the character, or split the text across fonts",
1033 Self::GlyphOutOfRange => "pass glyph IDs from the font you registered",
1034 Self::UnknownFont => "use the key returned by this registry's add",
1035 Self::SubsetFailed => "try another version or format of the font, and report the font if it is a common one",
1036 Self::InvalidAxisValue => "pass finite axis values; values outside the axis range are clamped",
1037 Self::WrongDocument => "use one FontRegistry per document and finish it with that document",
1038 Self::InvalidFeature => "write it as liga=0, -liga, smcp or aalt=2 (HarfBuzz syntax without ranges)",
1039 Self::InvalidTextRange => "take ranges from Lamina PDF's results (line_breaks, itemize, break_lines) and pass the same text",
1040 Self::InvalidSpans => "give spans in text order, each starting where the one before ends, from byte 0 to the end of the text, between grapheme clusters, each with at least one font from the list",
1041 Self::UnsupportedLayoutOption => "leave the option at its default; justification comes with a later release",
1042 Self::FontMismatch => "pass the key of the font the run was shaped with (the font index of each line run maps to your keys)",
1043 Self::EncodingFull => "embed a font with Font::from_bytes, or split the text across two registrations of the standard font",
1044 Self::FontNotShapable => "draw standard 14 fonts with FontRegistry::encode, or shape with an embedded font",
1045 Self::InvalidImage => "pass the complete bytes of a JPEG or PNG file to Image::jpeg or Image::png",
1046 Self::UnsupportedImage => "convert it to a baseline or progressive 8-bit JPEG, or to PNG",
1047 Self::ImageTooLarge => "scale the image down before adding it",
1048 Self::ImageDataLength => "pass exactly 4 bytes (RGBA) per pixel, row by row",
1049 Self::InvalidIccProfile => "pass a complete ICC profile with a Gray, RGB or CMYK data colour space",
1050 Self::ColorComponents => "give one component per channel of the colour space (/N of the ICC profile)",
1051 Self::InvalidColor => "write the colour as # followed by 3 or 6 hexadecimal digits",
1052 Self::InvalidGeometry => "use finite coordinates, positive page sizes and /UserUnit, non-negative line widths and dashes, a miter limit of at least 1, and images of at least one pixel",
1053 Self::TextOverflow => "make the box taller or the text shorter, or use Overflow::Clip and read TextLayout::overflow",
1054 Self::PageIndexOutOfRange => "use a 0-based index below the document's page count",
1055 Self::UnknownDestination => "define it with Builder::destination before the build finishes, or link to a page",
1056 Self::InvalidPageLabels => "give ranges sorted by first page, the first at page 0, numbered from 1",
1057 Self::TagElementNotOpen => "resume and close only elements this builder's pages opened with open_element, and close each once",
1058 Self::TagElementUnclosed => "close each element from open_element with Builder::close_element once its last page is finished",
1059 Self::ProfileVersionConflict => "leave the version at 1.7 (the default) or lower; PDF 2.0 needs PDF/A-4 or PDF/UA-2, which Lamina PDF doesn't write yet",
1060 Self::MissingTitle => "set a title with Builder::metadata (Metadata::with_title)",
1061 Self::MissingLang => "set the language with Builder::lang, such as \"en-GB\"",
1062 Self::MissingAltText => "give the figure or formula a description with Tag::with_alt or Surface::figure's alt, or draw decoration as an artifact",
1063 Self::UntaggedContent => "draw it inside Surface::tag (real content) or Surface::artifact (decoration)",
1064 Self::HeadingLevelSkipped => "start with H1 and go down one level at a time",
1065 Self::UnnumberedHeadingMisused => "use numbered headings (H1, H2, ...) throughout, or one H per section",
1066 Self::InvalidStructureNesting => "nest tables as Table > TR > TH/TD and lists as L > LI > Lbl/LBody",
1067 Self::LinkWithoutStructure => "draw links outside artifacts, so the builder gives each one a Link element",
1068 Self::LinkWithoutContents => "pass a description as the link's contents",
1069 Self::FontNotEmbedded => "load a font file with Builder::font instead of Builder::standard_font",
1070 Self::GlyphWithoutUnicode => "remove NUL characters (U+0000) from the text, or choose PDF/A-2b, which doesn't need Unicode",
1071 Self::DeviceColorWithoutOutputIntent => "use RGB or gray colours, or a CMYK colour with an ICC profile (Color::icc)",
1072 Self::EmbeddedFileForbidden => "choose PDF/A-3b, which allows attached files of any kind",
1073 Self::EmbeddedFileWithoutMimeType => "pass the file's MIME type, such as text/xml or application/octet-stream",
1074 Self::FlowContentTooLarge => "make the figure smaller, the text size smaller or the page's margins narrower",
1075 Self::FlowLayoutUnstable => "report the flow that fails; a page break after the contents block may avoid it until it is fixed",
1076 Self::InvalidDocument => "data.pointer names the value; correct it against the document schema, and didYouMean lists the closest known keys",
1077 Self::TemplateDataMissing => "data.pointer names the value the template asked for; add it to the data or correct the pointer",
1078 Self::TemplateDataType => "data.pointer names the value and data.expected the kind the template needs there",
1079 Self::TemplateTooLarge => "data.limit is the limit it passed; repeat fewer items, or split the document",
1080 Self::RenderTooLarge => "request smaller tiles (256 to 512 pixels at high zoom) or raise RenderLimits if the larger bitmap is intended",
1081 Self::RenderFailed => "the file may be damaged or use a feature this engine can't draw; try the other backend, or report the file",
1082 Self::RenderBackendUnavailable => "run cargo xtask fetch-pdfium or set LAMINA_PDF_PDFIUM_DIR to the folder holding the PDFium library",
1083 Self::ExportFailed => "report it with the format and the page: the encoder writes into memory, so this is a bug in Lamina PDF",
1084 Self::ModelFailed => "check the plug-in's own logs; extract without the model to get the rules-only result",
1085 Self::ModelResultUnexpected => "call provide only while request() returns a request, with the result its kind asks for",
1086 Self::ModelNeedsHost => "step an extraction job and hand it each result with provide, or give the plug-in a page renderer",
1087 Self::Cancelled => "nothing to do: this is the outcome the caller asked for; start a new job to try again",
1088 Self::JobFinished => "stop stepping a job once a step returned its result or an error; create a new job",
1089 Self::DocumentChanged => "pass the document the job was created from, and don't change it while the job runs; create a new job, or read the contents listing again",
1090 Self::RevisionIndexOutOfRange => "ask for an index below the document's revision count",
1091 Self::NoBookmarks => "add bookmarks that go to the document's pages first, then create the contents page",
1092 Self::BuilderFinished => "create a new builder or page: a finished one takes no more drawing, pages, fonts or settings",
1093 Self::Disposed => "free a handle only after its last use; to keep working, open the document again or create a new builder",
1094 Self::InvalidArgument => "pass the value the type declarations describe; the data field says what was wrong",
1095 Self::SourceBudgetExceeded => "raise the source's budget, or open the file with fewer bytes fetched (smaller blocks, no readahead)",
1096 Self::UnknownOption => "remove the key or correct its spelling; didYouMean lists the closest known names",
1097 Self::InvalidCommandLine => "run the command with --help to see its arguments",
1098 Self::InvalidPageRange => "write pages as 1-5, z for the last page, r2 for the second from the end, or x3 to leave page 3 out; data.position is the character where the range went wrong",
1099 Self::BinaryOutputToTerminal => "redirect standard output to a file or a pipe, or write to a file with -o",
1100 Self::UnknownCode => "check the spelling against didYouMean, or list every code at the docs URL",
1101 Self::OverwriteRefused => "pass --force, or write to a new file with -o",
1102 Self::InputUnreadable => "check that the file exists and that you can read it; data.input names it",
1103 Self::OutputUnwritable => "check that the output's folder exists, that you can write to it and that the disk has room",
1104 Self::PathOutsideRoots => "use a path inside one of the server's --root folders, or start the server with another --root",
1105 }
1106 }
1107
1108 #[must_use]
1112 pub fn docs_url(self) -> String {
1113 format!("{DOCS_URL_BASE}{}{DOCS_URL_SUFFIX}", self.as_str())
1114 }
1115}
1116
1117#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1121#[non_exhaustive]
1122pub enum WarningCode {
1123 MissingHeader,
1125 XrefRepaired,
1127 XrefstmIgnored,
1129 StreamLengthRecovered,
1131 DictionaryKeySkipped,
1133 StaleGeneration,
1135 PageTreeNodeSkipped,
1137 PageCountMismatch,
1139 FlateTruncated,
1141 FilterCharactersSkipped,
1143 ObjstmIndexMismatch,
1145 ObjectNumberOutOfRange,
1147 AesPaddingInvalid,
1149 PermsMismatch,
1151 WarningsTruncated,
1153 InvalidBox,
1155 InvalidRotate,
1157 NameTreeNodeSkipped,
1159 OutlineCycle,
1161 OutlineItemSkipped,
1163 InvalidDate,
1165 XmpInvalid,
1167 AnnotNameDuplicate,
1169 XmpRepaired,
1171 InvalidPageLabel,
1173 InvalidEntry,
1175 ContentUnknownOperator,
1177 ContentBadOperands,
1179 ContentUnbalancedQ,
1181 ContentUnbalancedBt,
1183 ContentUnbalancedMarked,
1185 ContentSyntax,
1187 ContentResourceMissing,
1189 InlineImageUnterminated,
1191 XobjectCycle,
1193 ContentPathUnpainted,
1195 FontInvalid,
1197 CmapInvalid,
1199 UnmappedGlyph,
1201 ExtractLimitBlocks,
1203 ExtractReadingOrderAmbiguous,
1205 ExtractTableAmbiguous,
1207 ExtractTableLimit,
1209 ExtractStructTreeIgnored,
1211 ExtractUntaggedContent,
1213 ExtractNeedsOcr,
1215 ExtractColumnOrderUncertain,
1217 PdfaOneAuthor,
1219 PdfuaTitleMissing,
1221 PdfaInfoMismatch,
1223 DuplicateTagsIncomplete,
1225 ImportedTagsDropped,
1227 ImportedPdfaUnchecked,
1229 ImportedPdfuaUnchecked,
1231 AnnotWithoutContents,
1233 AnnotNotTagged,
1235 PdfaAnnotFlags,
1237 PdfaTransparency,
1239 PdfaFontNotEmbedded,
1241 FlattenUntagged,
1243 FigureWithoutAlt,
1245 ContentTagsBroken,
1247 PdfaAttachmentForbidden,
1249 PdfaAttachmentIncomplete,
1251 TounicodeConflict,
1253 WholeFontRebuilt,
1255 FlowKeepBroken,
1257 MarkdownHtmlIgnored,
1259 MarkdownImageMissing,
1261 CoveredText,
1263 RedactionNotApplied,
1265 TextInEarlierRevision,
1267 RichTextSimplified,
1269 FlattenNoAppearance,
1271 AttachmentStillHeld,
1273 SummaryPageNotDrawn,
1275}
1276
1277impl WarningCode {
1278 pub const ALL: &'static [Self] = &[
1282 Self::MissingHeader,
1283 Self::XrefRepaired,
1284 Self::XrefstmIgnored,
1285 Self::StreamLengthRecovered,
1286 Self::DictionaryKeySkipped,
1287 Self::StaleGeneration,
1288 Self::PageTreeNodeSkipped,
1289 Self::PageCountMismatch,
1290 Self::FlateTruncated,
1291 Self::FilterCharactersSkipped,
1292 Self::ObjstmIndexMismatch,
1293 Self::ObjectNumberOutOfRange,
1294 Self::AesPaddingInvalid,
1295 Self::PermsMismatch,
1296 Self::WarningsTruncated,
1297 Self::InvalidBox,
1298 Self::InvalidRotate,
1299 Self::NameTreeNodeSkipped,
1300 Self::OutlineCycle,
1301 Self::OutlineItemSkipped,
1302 Self::InvalidDate,
1303 Self::XmpInvalid,
1304 Self::AnnotNameDuplicate,
1305 Self::XmpRepaired,
1306 Self::InvalidPageLabel,
1307 Self::InvalidEntry,
1308 Self::ContentUnknownOperator,
1309 Self::ContentBadOperands,
1310 Self::ContentUnbalancedQ,
1311 Self::ContentUnbalancedBt,
1312 Self::ContentUnbalancedMarked,
1313 Self::ContentSyntax,
1314 Self::ContentResourceMissing,
1315 Self::InlineImageUnterminated,
1316 Self::XobjectCycle,
1317 Self::ContentPathUnpainted,
1318 Self::FontInvalid,
1319 Self::CmapInvalid,
1320 Self::UnmappedGlyph,
1321 Self::ExtractLimitBlocks,
1322 Self::ExtractReadingOrderAmbiguous,
1323 Self::ExtractTableAmbiguous,
1324 Self::ExtractTableLimit,
1325 Self::ExtractStructTreeIgnored,
1326 Self::ExtractUntaggedContent,
1327 Self::ExtractNeedsOcr,
1328 Self::ExtractColumnOrderUncertain,
1329 Self::PdfaOneAuthor,
1330 Self::PdfuaTitleMissing,
1331 Self::PdfaInfoMismatch,
1332 Self::DuplicateTagsIncomplete,
1333 Self::ImportedTagsDropped,
1334 Self::ImportedPdfaUnchecked,
1335 Self::ImportedPdfuaUnchecked,
1336 Self::AnnotWithoutContents,
1337 Self::AnnotNotTagged,
1338 Self::PdfaAnnotFlags,
1339 Self::PdfaTransparency,
1340 Self::PdfaFontNotEmbedded,
1341 Self::FlattenUntagged,
1342 Self::FigureWithoutAlt,
1343 Self::ContentTagsBroken,
1344 Self::PdfaAttachmentForbidden,
1345 Self::PdfaAttachmentIncomplete,
1346 Self::TounicodeConflict,
1347 Self::WholeFontRebuilt,
1348 Self::FlowKeepBroken,
1349 Self::MarkdownHtmlIgnored,
1350 Self::MarkdownImageMissing,
1351 Self::CoveredText,
1352 Self::RedactionNotApplied,
1353 Self::TextInEarlierRevision,
1354 Self::RichTextSimplified,
1355 Self::FlattenNoAppearance,
1356 Self::AttachmentStillHeld,
1357 Self::SummaryPageNotDrawn,
1358 ];
1359
1360 #[must_use]
1364 pub const fn from_code(code: &str) -> Option<Self> {
1365 let mut rest = Self::ALL;
1366 while let [first, tail @ ..] = rest {
1367 if bytes_eq(first.as_str().as_bytes(), code.as_bytes()) {
1368 return Some(*first);
1369 }
1370 rest = tail;
1371 }
1372 None
1373 }
1374
1375 #[must_use]
1379 pub const fn as_str(self) -> &'static str {
1380 match self {
1381 Self::MissingHeader => "missing-header",
1382 Self::XrefRepaired => "xref-repaired",
1383 Self::XrefstmIgnored => "xrefstm-ignored",
1384 Self::StreamLengthRecovered => "stream-length-recovered",
1385 Self::DictionaryKeySkipped => "dictionary-key-skipped",
1386 Self::StaleGeneration => "stale-generation",
1387 Self::PageTreeNodeSkipped => "page-tree-node-skipped",
1388 Self::PageCountMismatch => "page-count-mismatch",
1389 Self::FlateTruncated => "flate-truncated",
1390 Self::FilterCharactersSkipped => "filter-characters-skipped",
1391 Self::ObjstmIndexMismatch => "objstm-index-mismatch",
1392 Self::ObjectNumberOutOfRange => "object-number-out-of-range",
1393 Self::AesPaddingInvalid => "aes-padding-invalid",
1394 Self::PermsMismatch => "perms-mismatch",
1395 Self::WarningsTruncated => "warnings-truncated",
1396 Self::InvalidBox => "invalid-box",
1397 Self::InvalidRotate => "invalid-rotate",
1398 Self::NameTreeNodeSkipped => "name-tree-node-skipped",
1399 Self::OutlineCycle => "outline-cycle",
1400 Self::OutlineItemSkipped => "outline-item-skipped",
1401 Self::InvalidDate => "invalid-date",
1402 Self::XmpInvalid => "xmp-invalid",
1403 Self::AnnotNameDuplicate => "annot-name-duplicate",
1404 Self::XmpRepaired => "xmp-repaired",
1405 Self::InvalidPageLabel => "invalid-page-label",
1406 Self::InvalidEntry => "invalid-entry",
1407 Self::ContentUnknownOperator => "content-unknown-operator",
1408 Self::ContentBadOperands => "content-bad-operands",
1409 Self::ContentUnbalancedQ => "content-unbalanced-q",
1410 Self::ContentUnbalancedBt => "content-unbalanced-bt",
1411 Self::ContentUnbalancedMarked => "content-unbalanced-marked",
1412 Self::ContentSyntax => "content-syntax",
1413 Self::ContentResourceMissing => "content-resource-missing",
1414 Self::InlineImageUnterminated => "inline-image-unterminated",
1415 Self::XobjectCycle => "xobject-cycle",
1416 Self::ContentPathUnpainted => "content-path-unpainted",
1417 Self::FontInvalid => "font-invalid",
1418 Self::CmapInvalid => "cmap-invalid",
1419 Self::UnmappedGlyph => "unmapped-glyph",
1420 Self::ExtractLimitBlocks => "extract-limit-blocks",
1421 Self::ExtractReadingOrderAmbiguous => "extract-reading-order-ambiguous",
1422 Self::ExtractTableAmbiguous => "extract-table-ambiguous",
1423 Self::ExtractTableLimit => "extract-table-limit",
1424 Self::ExtractStructTreeIgnored => "extract-struct-tree-ignored",
1425 Self::ExtractUntaggedContent => "extract-untagged-content",
1426 Self::ExtractNeedsOcr => "extract-needs-ocr",
1427 Self::ExtractColumnOrderUncertain => "extract-column-order-uncertain",
1428 Self::PdfaOneAuthor => "pdfa-one-author",
1429 Self::PdfuaTitleMissing => "pdfua-title-missing",
1430 Self::PdfaInfoMismatch => "pdfa-info-mismatch",
1431 Self::DuplicateTagsIncomplete => "duplicate-tags-incomplete",
1432 Self::ImportedTagsDropped => "imported-tags-dropped",
1433 Self::ImportedPdfaUnchecked => "imported-pdfa-unchecked",
1434 Self::ImportedPdfuaUnchecked => "imported-pdfua-unchecked",
1435 Self::AnnotWithoutContents => "annot-without-contents",
1436 Self::AnnotNotTagged => "annot-not-tagged",
1437 Self::PdfaAnnotFlags => "pdfa-annot-flags",
1438 Self::PdfaTransparency => "pdfa-transparency",
1439 Self::PdfaFontNotEmbedded => "pdfa-font-not-embedded",
1440 Self::FlattenUntagged => "flatten-untagged",
1441 Self::FigureWithoutAlt => "figure-without-alt",
1442 Self::ContentTagsBroken => "content-tags-broken",
1443 Self::PdfaAttachmentForbidden => "pdfa-attachment-forbidden",
1444 Self::PdfaAttachmentIncomplete => "pdfa-attachment-incomplete",
1445 Self::TounicodeConflict => "tounicode-conflict",
1446 Self::WholeFontRebuilt => "whole-font-rebuilt",
1447 Self::FlowKeepBroken => "flow-keep-broken",
1448 Self::MarkdownHtmlIgnored => "markdown-html-ignored",
1449 Self::MarkdownImageMissing => "markdown-image-missing",
1450 Self::CoveredText => "covered-text",
1451 Self::RedactionNotApplied => "redaction-not-applied",
1452 Self::TextInEarlierRevision => "text-in-earlier-revision",
1453 Self::RichTextSimplified => "rich-text-simplified",
1454 Self::FlattenNoAppearance => "flatten-no-appearance",
1455 Self::AttachmentStillHeld => "attachment-still-held",
1456 Self::SummaryPageNotDrawn => "summary-page-not-drawn",
1457 }
1458 }
1459
1460 #[must_use]
1464 pub const fn kind(self) -> ErrorKind {
1465 match self {
1466 Self::MissingHeader => ErrorKind::Input,
1467 Self::XrefRepaired => ErrorKind::Input,
1468 Self::XrefstmIgnored => ErrorKind::Input,
1469 Self::StreamLengthRecovered => ErrorKind::Input,
1470 Self::DictionaryKeySkipped => ErrorKind::Input,
1471 Self::StaleGeneration => ErrorKind::Input,
1472 Self::PageTreeNodeSkipped => ErrorKind::Input,
1473 Self::PageCountMismatch => ErrorKind::Input,
1474 Self::FlateTruncated => ErrorKind::Input,
1475 Self::FilterCharactersSkipped => ErrorKind::Input,
1476 Self::ObjstmIndexMismatch => ErrorKind::Input,
1477 Self::ObjectNumberOutOfRange => ErrorKind::Limit,
1478 Self::AesPaddingInvalid => ErrorKind::Security,
1479 Self::PermsMismatch => ErrorKind::Security,
1480 Self::WarningsTruncated => ErrorKind::Limit,
1481 Self::InvalidBox => ErrorKind::Input,
1482 Self::InvalidRotate => ErrorKind::Input,
1483 Self::NameTreeNodeSkipped => ErrorKind::Input,
1484 Self::OutlineCycle => ErrorKind::Input,
1485 Self::OutlineItemSkipped => ErrorKind::Input,
1486 Self::InvalidDate => ErrorKind::Input,
1487 Self::XmpInvalid => ErrorKind::Input,
1488 Self::AnnotNameDuplicate => ErrorKind::Input,
1489 Self::XmpRepaired => ErrorKind::Input,
1490 Self::InvalidPageLabel => ErrorKind::Input,
1491 Self::InvalidEntry => ErrorKind::Input,
1492 Self::ContentUnknownOperator => ErrorKind::Input,
1493 Self::ContentBadOperands => ErrorKind::Input,
1494 Self::ContentUnbalancedQ => ErrorKind::Input,
1495 Self::ContentUnbalancedBt => ErrorKind::Input,
1496 Self::ContentUnbalancedMarked => ErrorKind::Input,
1497 Self::ContentSyntax => ErrorKind::Input,
1498 Self::ContentResourceMissing => ErrorKind::Input,
1499 Self::InlineImageUnterminated => ErrorKind::Input,
1500 Self::XobjectCycle => ErrorKind::Input,
1501 Self::ContentPathUnpainted => ErrorKind::Input,
1502 Self::FontInvalid => ErrorKind::Input,
1503 Self::CmapInvalid => ErrorKind::Input,
1504 Self::UnmappedGlyph => ErrorKind::Input,
1505 Self::ExtractLimitBlocks => ErrorKind::Limit,
1506 Self::ExtractReadingOrderAmbiguous => ErrorKind::Unsupported,
1507 Self::ExtractTableAmbiguous => ErrorKind::Unsupported,
1508 Self::ExtractTableLimit => ErrorKind::Limit,
1509 Self::ExtractStructTreeIgnored => ErrorKind::Input,
1510 Self::ExtractUntaggedContent => ErrorKind::Input,
1511 Self::ExtractNeedsOcr => ErrorKind::Unsupported,
1512 Self::ExtractColumnOrderUncertain => ErrorKind::Unsupported,
1513 Self::PdfaOneAuthor => ErrorKind::Usage,
1514 Self::PdfuaTitleMissing => ErrorKind::Usage,
1515 Self::PdfaInfoMismatch => ErrorKind::Input,
1516 Self::DuplicateTagsIncomplete => ErrorKind::Usage,
1517 Self::ImportedTagsDropped => ErrorKind::Usage,
1518 Self::ImportedPdfaUnchecked => ErrorKind::Usage,
1519 Self::ImportedPdfuaUnchecked => ErrorKind::Usage,
1520 Self::AnnotWithoutContents => ErrorKind::Usage,
1521 Self::AnnotNotTagged => ErrorKind::Usage,
1522 Self::PdfaAnnotFlags => ErrorKind::Usage,
1523 Self::PdfaTransparency => ErrorKind::Usage,
1524 Self::PdfaFontNotEmbedded => ErrorKind::Usage,
1525 Self::FlattenUntagged => ErrorKind::Usage,
1526 Self::FigureWithoutAlt => ErrorKind::Usage,
1527 Self::ContentTagsBroken => ErrorKind::Input,
1528 Self::PdfaAttachmentForbidden => ErrorKind::Usage,
1529 Self::PdfaAttachmentIncomplete => ErrorKind::Usage,
1530 Self::TounicodeConflict => ErrorKind::Usage,
1531 Self::WholeFontRebuilt => ErrorKind::Usage,
1532 Self::FlowKeepBroken => ErrorKind::Usage,
1533 Self::MarkdownHtmlIgnored => ErrorKind::Unsupported,
1534 Self::MarkdownImageMissing => ErrorKind::Usage,
1535 Self::CoveredText => ErrorKind::Security,
1536 Self::RedactionNotApplied => ErrorKind::Security,
1537 Self::TextInEarlierRevision => ErrorKind::Security,
1538 Self::RichTextSimplified => ErrorKind::Usage,
1539 Self::FlattenNoAppearance => ErrorKind::Unsupported,
1540 Self::AttachmentStillHeld => ErrorKind::Usage,
1541 Self::SummaryPageNotDrawn => ErrorKind::Unsupported,
1542 }
1543 }
1544
1545 #[must_use]
1549 pub const fn summary(self) -> &'static str {
1550 match self {
1551 Self::MissingHeader => "no %PDF-x.y header in the first 1,024 bytes; parsing went ahead",
1552 Self::XrefRepaired => "the stored cross-reference data was unusable and was rebuilt by scanning",
1553 Self::XrefstmIgnored => "a hybrid file's /XRefStm could not be read and was ignored",
1554 Self::StreamLengthRecovered => "a stream's /Length was wrong, so its end was found by scanning for endstream",
1555 Self::DictionaryKeySkipped => "a dictionary had something other than a name where a key belongs, and it was skipped",
1556 Self::StaleGeneration => "a reference's generation did not match its xref entry, so it resolved to null",
1557 Self::PageTreeNodeSkipped => "a page-tree node was missing, malformed or too deep, and was skipped",
1558 Self::PageCountMismatch => "the page tree's /Count differs from the number of pages walked",
1559 Self::FlateTruncated => "Flate data was truncated or had a bad checksum; the partial output was kept",
1560 Self::FilterCharactersSkipped => "ASCIIHex or ASCII85 data held characters outside the filter's alphabet; they were skipped",
1561 Self::ObjstmIndexMismatch => "an object stream's index was stale and the object was found by searching",
1562 Self::ObjectNumberOutOfRange => "an xref entry above max_object_number was dropped",
1563 Self::AesPaddingInvalid => "AES-encrypted data had a bad length or padding and was kept as stored",
1564 Self::PermsMismatch => "an R5/R6 document's /Perms does not match its /P and /EncryptMetadata",
1565 Self::WarningsTruncated => "more than max_warnings warnings were raised and the rest were dropped",
1566 Self::InvalidBox => "a page boundary box is not four numbers and reads as absent",
1567 Self::InvalidRotate => "a page's /Rotate is not a multiple of 90 and reads as 0",
1568 Self::NameTreeNodeSkipped => "a name- or number-tree node was malformed, repeated or too deep, and was skipped",
1569 Self::OutlineCycle => "an outline item was reached twice; that branch of the walk stopped",
1570 Self::OutlineItemSkipped => "an outline item was missing, not a dictionary or too deep, and was skipped with its subtree",
1571 Self::InvalidDate => "an Info date is not a valid PDF date; the raw string is kept",
1572 Self::XmpInvalid => "the XMP metadata packet is not readable XMP and reads as absent",
1573 Self::AnnotNameDuplicate => "two annotations on one page have the same name (/NM), which should be unique on its page",
1574 Self::XmpRepaired => "the XMP metadata packet had damage other readers read past, and was read the same way",
1575 Self::InvalidPageLabel => "a /PageLabels entry is malformed; the malformed part is dropped",
1576 Self::InvalidEntry => "an entry a view reads is unreadable or of the wrong type and reads as absent",
1577 Self::ContentUnknownOperator => "an operator the spec does not define was skipped outside a BX/EX section",
1578 Self::ContentBadOperands => "an operator had too few operands or operands of the wrong type, or extra ones",
1579 Self::ContentUnbalancedQ => "a Q without a matching q was ignored, or saved graphics states were left open",
1580 Self::ContentUnbalancedBt => "a text object was opened twice, closed outside one, or left open",
1581 Self::ContentUnbalancedMarked => "an EMC without a matching BMC or BDC was ignored, or marked content was left open",
1582 Self::ContentSyntax => "content-stream bytes that are not a token were skipped",
1583 Self::ContentResourceMissing => "an operator named a resource that is missing, of the wrong type or unreadable",
1584 Self::InlineImageUnterminated => "no EI ends an inline image; the rest of the content was skipped",
1585 Self::XobjectCycle => "a Form XObject draws itself, directly or through other forms",
1586 Self::ContentPathUnpainted => "a content stream ended with a path no painting operator ended",
1587 Self::FontInvalid => "a font dictionary has a missing or malformed entry, so its text was decoded with defaults",
1588 Self::CmapInvalid => "a font's CMap or ToUnicode CMap is malformed or names a predefined CMap Lamina PDF has no table for",
1589 Self::UnmappedGlyph => "a font shows glyphs that nothing maps to text",
1590 Self::ExtractLimitBlocks => "a page had more runs of text than the extraction block limit; the runs past it were left out",
1591 Self::ExtractReadingOrderAmbiguous => "a page mixes horizontal and vertical writing, so the order of its blocks is a guess",
1592 Self::ExtractTableAmbiguous => "a table's rules marked out merged cells that aren't rectangles, so its cells were kept unmerged",
1593 Self::ExtractTableLimit => "a page's ruling lines would make a table bigger than the extraction's cell limit; those lines gave no table",
1594 Self::ExtractStructTreeIgnored => "a tagged page's structure tree covered too little of its text, or its order jumped back across columns too often, so the layout gave the reading order",
1595 Self::ExtractUntaggedContent => "a page read in structure-tree order has visible text that is neither in the tree nor an artifact; it follows the tree's blocks, in layout order",
1596 Self::ExtractNeedsOcr => "a page has no usable text layer: it is an image (with or without an invisible OCR layer), outlined glyphs, or glyphs without Unicode, so its extracted text is empty or unreliable",
1597 Self::ExtractColumnOrderUncertain => "the layout rules had to guess how a page's columns are read, so its blocks may be in the wrong order; the blocks concerned have a lower confidence",
1598 Self::PdfaOneAuthor => "the file claims PDF/A-1, which allows one author, and its metadata lists more",
1599 Self::PdfuaTitleMissing => "the file claims PDF/UA-1, which requires a title in its metadata, and it has none",
1600 Self::PdfaInfoMismatch => "the file claims PDF/A, which requires the Info dictionary and the XMP packet to agree, and they differ",
1601 Self::DuplicateTagsIncomplete => "a duplicated page's content is partly untagged, which breaks the PDF/UA claim of the document's metadata",
1602 Self::ImportedTagsDropped => "pages copied in from another document came without their tags, which breaks the PDF/UA claim of the document's metadata",
1603 Self::ImportedPdfaUnchecked => "pages copied in from a document that doesn't claim the same PDF/A level may break the PDF/A claim of the document's metadata",
1604 Self::ImportedPdfuaUnchecked => "pages copied in from a document that doesn't claim PDF/UA-1 may break the PDF/UA claim of the document's metadata",
1605 Self::AnnotWithoutContents => "a new or changed annotation has no description, which breaks the document's PDF/UA claim",
1606 Self::AnnotNotTagged => "a new annotation isn't in the structure tree, which breaks the document's PDF/UA claim",
1607 Self::PdfaAnnotFlags => "an annotation doesn't print or is hidden, which breaks the document's PDF/A claim",
1608 Self::PdfaTransparency => "an annotation is translucent or blends, which PDF/A-1 forbids",
1609 Self::PdfaFontNotEmbedded => "the file claims PDF/A, and an edited annotation or page uses a font that isn't embedded, such as a text box in a standard 14 font",
1610 Self::FlattenUntagged => "the file claims PDF/UA-1, and flattening took comments out of the structure tree: their text is no longer read out",
1611 Self::FigureWithoutAlt => "the file claims PDF/UA, and an edit replaced a figure's image: the figure's alternative text described the old image and was removed",
1612 Self::ContentTagsBroken => "the file claims PDF/UA, and edited pages draw content their tags don't cover, often because the file's tags were already incomplete",
1613 Self::PdfaAttachmentForbidden => "the file claims PDF/A-1 or PDF/A-2, which allow no attached files but PDF/A ones, and the edits attached a file",
1614 Self::PdfaAttachmentIncomplete => "the file claims PDF/A-3, and an attached file lacks an association with the document, a page or an annotation, a modification date or a MIME type",
1615 Self::TounicodeConflict => "one glyph was used for two different texts; ToUnicode keeps the first",
1616 Self::WholeFontRebuilt => "a font that forbids subsetting was rebuilt with every glyph kept",
1617 Self::FlowKeepBroken => "blocks kept together are taller than a page, so the flow split them",
1618 Self::MarkdownHtmlIgnored => "the Markdown holds raw HTML, which the PDF leaves out",
1619 Self::MarkdownImageMissing => "the Markdown names an image that wasn't supplied, so the PDF leaves it out",
1620 Self::CoveredText => "a page draws text and then paints a shape, an image or an annotation over it, so the text is hidden but still in the file",
1621 Self::RedactionNotApplied => "a page has redaction marks that were never applied, so the text under them is still in the file",
1622 Self::TextInEarlierRevision => "an earlier revision of the file holds text that the latest revision no longer has",
1623 Self::RichTextSimplified => "an edit changed a text box whose rich text had styles Lamina PDF doesn't keep, such as a size or colour per word, so the box now has one size and colour",
1624 Self::FlattenNoAppearance => "flattening left some annotations in place: they have no appearance, and Lamina PDF can't draw one for their kind",
1625 Self::AttachmentStillHeld => "a deleted attachment stays in the document because a file attachment annotation still holds it",
1626 Self::SummaryPageNotDrawn => "a comment summary lists a page's comments without drawing the page, because the page uses a font the file doesn't embed, which PDF/UA-1 forbids, or has content Lamina PDF can't read to its end",
1627 }
1628 }
1629
1630 #[must_use]
1634 pub const fn hint(self) -> &'static str {
1635 match self {
1636 Self::MissingHeader => "nothing to do if the document reads correctly; open in strict mode to refuse such files",
1637 Self::XrefRepaired => "check the result; save with a full rewrite, since an incremental update refuses a repaired base",
1638 Self::XrefstmIgnored => "nothing to do; the classic xref table is used instead",
1639 Self::StreamLengthRecovered => "nothing to do; a full rewrite writes the correct length",
1640 Self::DictionaryKeySkipped => "nothing to do if the document reads correctly; open in strict mode to refuse such files",
1641 Self::StaleGeneration => "nothing to do; the reference is treated as missing",
1642 Self::PageTreeNodeSkipped => "check the page count: pages under the skipped node are missing",
1643 Self::PageCountMismatch => "nothing to do; Lamina PDF uses the walked page count",
1644 Self::FlateTruncated => "check the affected content: the end of the stream may be missing",
1645 Self::FilterCharactersSkipped => "check the affected content: the stream is damaged, and what decoded may differ from what was written",
1646 Self::ObjstmIndexMismatch => "nothing to do; a full rewrite writes a correct index",
1647 Self::ObjectNumberOutOfRange => "raise max_object_number in Limits only if you trust the input",
1648 Self::AesPaddingInvalid => "treat the affected strings and streams as suspect: they may have been tampered with",
1649 Self::PermsMismatch => "treat the document's permissions as untrusted",
1650 Self::WarningsTruncated => "raise max_warnings in Limits if you need the full list",
1651 Self::InvalidBox => "nothing to do; the page uses the next box in the fallback chain",
1652 Self::InvalidRotate => "set the page rotation explicitly if 0 is wrong",
1653 Self::NameTreeNodeSkipped => "check the tree's entries: those under the skipped node are missing",
1654 Self::OutlineCycle => "nothing to do; the outline is read without the loop",
1655 Self::OutlineItemSkipped => "check the outline: the skipped item and its children are missing",
1656 Self::InvalidDate => "read the raw value from the Info view if you need it",
1657 Self::XmpInvalid => "nothing to do; a metadata edit asks before replacing it",
1658 Self::AnnotNameDuplicate => "nothing to do; both are kept, and annotations are told apart by their own IDs",
1659 Self::XmpRepaired => "nothing to do; a metadata edit writes the declarations the packet left out",
1660 Self::InvalidPageLabel => "nothing to do; affected pages fall back to decimal labels",
1661 Self::InvalidEntry => "nothing to do; the view uses the entry's default",
1662 Self::ContentUnknownOperator => "nothing to do; check the page's rendering if the operator mattered",
1663 Self::ContentBadOperands => "nothing to do; the operator was skipped or used its last operands",
1664 Self::ContentUnbalancedQ => "nothing to do; the graphics state was restored as the spec intends",
1665 Self::ContentUnbalancedBt => "nothing to do; text operators outside a text object were handled tolerantly",
1666 Self::ContentUnbalancedMarked => "check tagged-content results: marked-content sequences were closed for you",
1667 Self::ContentSyntax => "check the page's content: the bytes around the reported offset were skipped",
1668 Self::ContentResourceMissing => "check the page's resources: the operator ran without the resource or was skipped",
1669 Self::InlineImageUnterminated => "check the page's content: everything after the inline image is missing",
1670 Self::XobjectCycle => "nothing to do; the inner Do was skipped",
1671 Self::ContentPathUnpainted => "nothing to do; the unpainted path was dropped as the spec intends",
1672 Self::FontInvalid => "nothing to do; extracted text or positions for that font may be off",
1673 Self::CmapInvalid => "nothing to do; the bad entries were skipped and the rest of the CMap is used",
1674 Self::UnmappedGlyph => "nothing to do; those glyphs extract as U+FFFD (the file needs a ToUnicode CMap)",
1675 Self::ExtractLimitBlocks => "raise ExtractLimits::max_blocks_per_page if the page really has that many blocks",
1676 Self::ExtractReadingOrderAmbiguous => "nothing to do; check the order of that page's blocks, or ask for content order",
1677 Self::ExtractTableAmbiguous => "nothing to do; check that table's cells, whose text may be split across neighbours",
1678 Self::ExtractTableLimit => "raise ExtractLimits::max_table_cells if the page really has a table that big",
1679 Self::ExtractStructTreeIgnored => "nothing to do; ReadingOrder::Tagged uses the tree anyway",
1680 Self::ExtractUntaggedContent => "nothing to do; tag that text in the file to give it a place in the reading order",
1681 Self::ExtractNeedsOcr => "run OCR or a vision model on this page; the page's textLayer in the JSON says which case it is",
1682 Self::ExtractColumnOrderUncertain => "check the page, or send it to a layout model; the warning's reason says which guess was made",
1683 Self::PdfaOneAuthor => "keep one author (join the names into one), or save knowing the file no longer meets PDF/A-1",
1684 Self::PdfuaTitleMissing => "give the document a title before saving, or save knowing the file no longer meets PDF/UA-1",
1685 Self::PdfaInfoMismatch => "edit the metadata with setMetadata, which writes both, or remove the Info entries that differ",
1686 Self::DuplicateTagsIncomplete => "retag the copy, or duplicate pages whose tagged elements lie on the page alone",
1687 Self::ImportedTagsDropped => "tag the copied pages in a tagging tool, or copy pages from a document without tags",
1688 Self::ImportedPdfaUnchecked => "check the saved file with a PDF/A validator such as veraPDF, or copy pages from a document that claims the same level",
1689 Self::ImportedPdfuaUnchecked => "check the saved file's tags, alternate text and reading order with a PDF/UA checker such as veraPDF, or copy pages from a document that claims PDF/UA-1",
1690 Self::AnnotWithoutContents => "give the annotation a description: the text it marks, or what the mark means",
1691 Self::AnnotNotTagged => "tag the document first, or add the annotation to a copy that doesn't claim PDF/UA",
1692 Self::PdfaAnnotFlags => "keep the annotation's Print flag and clear Hidden, Invisible, NoView and ToggleNoView",
1693 Self::PdfaTransparency => "make the mark opaque, or use an underline instead of a highlight",
1694 Self::PdfaFontNotEmbedded => "give a text box a font by its bytes (add them with addBlob), which Lamina PDF embeds as a subset; before flattening, embed the font in the annotation's appearance with the app that made it, or flatten a copy",
1695 Self::FlattenUntagged => "save knowing the file no longer meets PDF/UA-1, or keep the comments as annotations and flatten a copy",
1696 Self::FigureWithoutAlt => "undo the image replacement, or add alternative text with an accessibility tool and open the file again; or save without the PDF/UA claim (removeConformanceClaims)",
1697 Self::ContentTagsBroken => "undo the edit, or save without the PDF/UA claim (removeConformanceClaims) and tag the page again with an accessibility tool",
1698 Self::PdfaAttachmentForbidden => "attach the file to a copy saved without the PDF/A claim, or save knowing the file may no longer meet its PDF/A level",
1699 Self::PdfaAttachmentIncomplete => "attach the file to the document, a page or an annotation, with its modification date and MIME type",
1700 Self::TounicodeConflict => "mark the second occurrence with /ActualText so extraction gets its text",
1701 Self::WholeFontRebuilt => "check that the font's licence allows this, or use a static TrueType or CFF version",
1702 Self::FlowKeepBroken => "split the keep group or drop keep-with-next on a heading chain, or use a taller page",
1703 Self::MarkdownHtmlIgnored => "write the content in Markdown instead of HTML, or remove the HTML",
1704 Self::MarkdownImageMissing => "pass the image's bytes with MarkdownBuildOptions::with_image under the path the Markdown uses",
1705 Self::CoveredText => "remove the text itself with a tool that deletes what a redaction covers, then save a full rewrite",
1706 Self::RedactionNotApplied => "apply the redactions in a tool that removes what they cover, then save a full rewrite",
1707 Self::TextInEarlierRevision => "save the file as a full rewrite, which keeps only the latest revision",
1708 Self::RichTextSimplified => "check how the box looks; bold and italic are kept, and the box's own font, size, colour and alignment apply to all of its text",
1709 Self::FlattenNoAppearance => "nothing to do if they should stay; otherwise give them an appearance in the app that made them, or delete them",
1710 Self::AttachmentStillHeld => "delete the annotation too to take the file out of the document",
1711 Self::SummaryPageNotDrawn => "nothing to do if the list is enough; to see the page beside its comments, embed its fonts first, for example by printing the document to PDF again, then make the summary again",
1712 }
1713 }
1714
1715 #[must_use]
1719 pub fn docs_url(self) -> String {
1720 format!("{DOCS_URL_BASE}{}{DOCS_URL_SUFFIX}", self.as_str())
1721 }
1722}