MCPcopy Create free account
hub / github.com/creatale/node-dv / EndDocumentHandler

Method EndDocumentHandler

deps/tesseract/api/pdfrenderer.cpp:939–1030  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

937
938
939bool TessPDFRenderer::EndDocumentHandler() {
940 size_t n;
941 char buf[kBasicBufSize];
942
943 // We reserved the /Pages object number early, so that the /Page
944 // objects could refer to their parent. We finally have enough
945 // information to go fill it in. Using lower level calls to manipulate
946 // the offset record in two spots, because we are placing objects
947 // out of order in the file.
948
949 // PAGES
950 const long int kPagesObjectNumber = 2;
951 offsets_[kPagesObjectNumber] = offsets_.back(); // manipulation #1
952 n = snprintf(buf, sizeof(buf),
953 "%ld 0 obj\n"
954 "<<\n"
955 " /Type /Pages\n"
956 " /Kids [ ", kPagesObjectNumber);
957 if (n >= sizeof(buf)) return false;
958 AppendString(buf);
959 size_t pages_objsize = strlen(buf);
960 for (size_t i = 0; i < pages_.size(); i++) {
961 n = snprintf(buf, sizeof(buf),
962 "%ld 0 R ", pages_[i]);
963 if (n >= sizeof(buf)) return false;
964 AppendString(buf);
965 pages_objsize += strlen(buf);
966 }
967 n = snprintf(buf, sizeof(buf),
968 "]\n"
969 " /Count %d\n"
970 ">>\n"
971 "endobj\n", pages_.size());
972 if (n >= sizeof(buf)) return false;
973 AppendString(buf);
974 pages_objsize += strlen(buf);
975 offsets_.back() += pages_objsize; // manipulation #2
976
977 // INFO
978 STRING utf16_title = "FEFF"; // byte_order_marker
979 GenericVector<int> unicodes;
980 UNICHAR::UTF8ToUnicode(title(), &unicodes);
981 char utf16[kMaxBytesPerCodepoint];
982 for (int i = 0; i < unicodes.length(); i++) {
983 int code = unicodes[i];
984 if (CodepointToUtf16be(code, utf16)) {
985 utf16_title += utf16;
986 }
987 }
988
989 char* datestr = l_getFormattedDate();
990 n = snprintf(buf, sizeof(buf),
991 "%ld 0 obj\n"
992 "<<\n"
993 " /Producer (Tesseract %s)\n"
994 " /CreationDate (D:%s)\n"
995 " /Title <%s>\n"
996 ">>\n"

Callers

nothing calls this directly

Calls 7

titleFunction · 0.85
CodepointToUtf16beFunction · 0.85
l_getFormattedDateFunction · 0.85
lept_freeFunction · 0.85
sizeMethod · 0.45
lengthMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected