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