-
-
Save Metaluim/2c9d340f0f93b21bf9c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
printf("\nloading page...\n"); | |
first_page = pdf_load_page(ctx, doc, 0); | |
if (first_page == NULL) | |
{ | |
fz_drop_document(ctx, doc); | |
fz_drop_context(ctx); | |
return QVR_NOK; | |
} | |
printf("\ncreating annotation...\n"); | |
page_annot = pdf_create_annot(ctx, doc, first_page, FZ_ANNOT_FILEATTACHMENT); | |
if (page_annot == NULL) | |
{ | |
fz_drop_page(ctx, first_page); | |
fz_drop_document(ctx, doc); | |
fz_drop_context(ctx); | |
return QVR_NOK; | |
} | |
printf("\nreading input file...\n"); | |
if (__buffrd(path, &input_file_buf, &input_file_buflen) == QVR_NOK || | |
input_file_buf == NULL) | |
{ | |
fz_drop_page(ctx, first_page); | |
fz_drop_document(ctx, doc); | |
fz_drop_context(ctx); | |
return QVR_NOK; | |
} | |
/*((char *) (input_file_buf))[input_file_buflen - 1] = '\0';*/ | |
/*pdf_set_annot_contents(ctx, doc, page_annot, (char *) input_file_buf);*/ | |
printf("\nattaching input file (%X)...\n", page_annot->obj); | |
pdf_dict_put(ctx, | |
page_annot->obj, | |
PDF_NAME_FileAttachment, | |
pdf_new_string(ctx, doc, (char*)input_file_buf, input_file_buflen)); | |
// ... | |
printf("\nwriting PDF...\n"); | |
memset(&wopts, 0, sizeof(wopts)); | |
wopts.errors = &err; | |
fz_write_document(ctx, doc, "tmp.pdf", &wopts); | |
printf("\nanum of annots in first page: %d\n", __count_annots(ctx, first_page)); | |
free(input_file_buf); | |
fz_drop_page(ctx, first_page); | |
fz_drop_document(ctx, doc); | |
fz_drop_context(ctx); | |
return ret; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment