| // Copyright 2026 Google LLC | |
| // | |
| // Licensed under the Apache License, Version 2.0 (the "License"); | |
| // you may not use this file except in compliance with the License. | |
| // You may obtain a copy of the License at | |
| // | |
| // https://www.apache.org/licenses/LICENSE-2.0 | |
| // | |
| // Unless required by applicable law or agreed to in writing, software | |
| // distributed under the License is distributed on an "AS IS" BASIS, | |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| // See the License for the specific language governing permissions and | |
| // limitations under the License. | |
| // | |
| #ifndef THIRD_PARTY_CREDENTIO_FORMATS_PDF_EMBEDDER_H_ | |
| #define THIRD_PARTY_CREDENTIO_FORMATS_PDF_EMBEDDER_H_ | |
| #include <cstdint> | |
| #include "absl/status/status.h" | |
| #include "absl/status/statusor.h" | |
| #include "absl/strings/cord.h" | |
| #include "absl/strings/string_view.h" | |
| #include "riegeli/bytes/reader.h" | |
| #include "riegeli/bytes/writer.h" | |
| namespace credentio { | |
| // A utility class for embedding a C2PA manifest store as an embedded file | |
| // stream in a non-C2PA PDF file. | |
| class PdfEmbedder { | |
| public: | |
| explicit PdfEmbedder() = default; | |
| // Rewrites a PDF file to be C2PA-embeddable, making necessary updates while | |
| // preserving the original structure. Returns the offset of the zero-filled | |
| // manifest store in the output. Fails if the input PDF already contains a | |
| // C2PA manifest store or if rewriting fails. | |
| absl::StatusOr<int64_t> RewriteForEmbedding( | |
| riegeli::Reader& input, int64_t estimated_manifest_store_size, | |
| riegeli::Writer& output) const; | |
| // Embeds the C2PA manifest store at the insertion point. | |
| absl::Status Embed(absl::string_view manifest_store, int64_t insert_at_offset, | |
| absl::Cord& embeddable_asset) const; | |
| }; | |
| } // namespace credentio | |
| #endif // THIRD_PARTY_CREDENTIO_FORMATS_PDF_EMBEDDER_H_ |