From 1f62c53da6edc5a82a1e0eceb401b2274cd4a0d1 Mon Sep 17 00:00:00 2001 From: yzrh Date: Wed, 30 Dec 2020 17:06:55 +0000 Subject: Produce PDF directly from KDH. --- src/cnki_pdf.c | 66 ++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 16 deletions(-) (limited to 'src/cnki_pdf.c') diff --git a/src/cnki_pdf.c b/src/cnki_pdf.c index 6964cac..d8eabff 100644 --- a/src/cnki_pdf.c +++ b/src/cnki_pdf.c @@ -232,28 +232,62 @@ cnki_pdf(cnki_t **param) } if ((*param)->stat > 1) - printf("Generating '/Catalog' dictionary\n"); + printf("Searching for catalog object\n"); - snprintf(buf, 64, - "<<\n/Type /Catalog\n/Pages %d 0 R\n", - root); - strcat(dictionary, buf); + int catalog = pdf_get_catalog_id(&pdf); + + if (catalog != 0) { + if ((*param)->stat > 0) + printf("catalog object is %d.\n", catalog); + } else { + if ((*param)->stat > 0) + printf("catalog object is missing\n"); + + if ((*param)->stat > 1) + printf("Generating catalog object\n"); - if (ids != NULL) { snprintf(buf, 64, - "/Outlines %d 0 R\n/PageMode /UseOutlines\n", - ids[0]); + "<<\n/Type /Catalog\n/Pages %d 0 R\n", + root); strcat(dictionary, buf); + + if (ids != NULL) { + snprintf(buf, 64, + "/Outlines %d 0 R\n/PageMode /UseOutlines\n", + ids[0]); + strcat(dictionary, buf); + } + + strcat(dictionary, ">>\n"); + + pdf_obj_append(&pdf, 0, NULL, dictionary, NULL); + + if ((*param)->stat > 0) + printf("Generated catalog object\n"); } - strcat(dictionary, ">>\n"); + if ((*param)->stat > 1) + printf("Searching for xref object\n"); - pdf_obj_append(&pdf, 0, NULL, dictionary, NULL); + int xref = pdf_get_xref_id(&pdf); - free(dictionary); + if (xref != 0) { + if ((*param)->stat > 0) + printf("xref object is %d.\n", xref); - if ((*param)->stat > 0) - printf("Generated '/Catalog' dictionary\n"); + if ((*param)->stat > 1) + printf("Deleting xref object\n"); + + pdf_obj_del(&pdf, xref); + + if ((*param)->stat > 0) + printf("Deleted xref object\n"); + } else { + if ((*param)->stat > 0) + printf("xref object is missing\n"); + } + + free(dictionary); if ((*param)->stat > 1) printf("Sorting object(s)\n"); @@ -312,7 +346,7 @@ cnki_pdf(cnki_t **param) pdf_get_count(&pdf), ftell((*param)->fp_o)); - long xref = ftell((*param)->fp_o); + long cur_xref = ftell((*param)->fp_o); if ((*param)->stat > 1) printf("Writing cross-reference table\n"); @@ -323,7 +357,7 @@ cnki_pdf(cnki_t **param) } else { if ((*param)->stat > 0) printf("Cross-reference table %ld byte(s) written\n", - ftell((*param)->fp_o) - xref); + ftell((*param)->fp_o) - cur_xref); } if ((*param)->stat > 1) @@ -332,7 +366,7 @@ cnki_pdf(cnki_t **param) if ((*param)->stat > 0) cur = ftell((*param)->fp_o); - if (pdf_dump_trailer(&pdf, &(*param)->fp_o, xref) != 0) { + if (pdf_dump_trailer(&pdf, &(*param)->fp_o, cur_xref) != 0) { if ((*param)->stat > 0) printf("Trailer not written\n"); } else { -- cgit v1.2.3