pdf_text.c

Thu, 13 Mar 2003 08:03:11 +0000

author
eric
date
Thu, 13 Mar 2003 08:03:11 +0000
changeset 124
ba64dfca82e9
parent 119
cbc382d73a86
child 125
e2ef1c2f9eca
permissions
-rw-r--r--

Acrobat 4.0 fails to optimize PDF files in which the Kids array in the Pages object is an indirect reference.

     1 /*
     2  * t2p: Create a PDF file from the contents of one or more TIFF
     3  *      bilevel image files.  The images in the resulting PDF file
     4  *      will be compressed using ITU-T T.6 (G4) fax encoding.
     5  *
     6  * PDF routines
     7  * $Id: pdf_text.c,v 1.1 2003/03/12 23:57:21 eric Exp $
     8  * Copyright 2003 Eric Smith <eric@brouhaha.com>
     9  *
    10  * This program is free software; you can redistribute it and/or modify
    11  * it under the terms of the GNU General Public License version 2 as
    12  * published by the Free Software Foundation.  Note that permission is
    13  * not granted to redistribute this program under the terms of any
    14  * other version of the General Public License.
    15  *
    16  * This program is distributed in the hope that it will be useful,
    17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    19  * GNU General Public License for more details.
    20  *
    21  * You should have received a copy of the GNU General Public License
    22  * along with this program; if not, write to the Free Software
    23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
    24  */
    27 #include <stdbool.h>
    28 #include <stdint.h>
    29 #include <stdio.h>
    30 #include <stdlib.h>
    31 #include <string.h>
    34 #include "bitblt.h"
    35 #include "pdf.h"
    36 #include "pdf_util.h"
    37 #include "pdf_prim.h"
    38 #include "pdf_private.h"
    42 static void pdf_write_text_content_callback (pdf_file_handle pdf_file,
    43 					     struct pdf_obj *stream,
    44 					     void *app_data)
    45 {
    46   pdf_stream_printf (pdf_file, stream,
    47 		     "BT /F1 24 Tf 100 100 Td (Hello World) Tj ET\r\n");
    48 }
    51 static struct pdf_obj *pdf_create_font (pdf_page_handle pdf_page)
    52 {
    53   struct pdf_obj *font = pdf_new_ind_ref (pdf_page->pdf_file,
    54 					  pdf_new_obj (PT_DICTIONARY));
    55   pdf_set_dict_entry (font, "Type", pdf_new_name ("Font"));
    56   pdf_set_dict_entry (font, "Subtype", pdf_new_name ("Type1"));
    57   pdf_set_dict_entry (font, "Name", pdf_new_name ("F1"));
    58   pdf_set_dict_entry (font, "BaseFont", pdf_new_name ("Helvetica"));
    59   pdf_set_dict_entry (font, "Encoding", pdf_new_name ("MacRomanEncoding"));
    61   return (font);
    62 }
    64 void pdf_write_text (pdf_page_handle pdf_page)
    65 {
    66   struct pdf_obj *font;
    67   struct pdf_obj *font_dict;
    68   struct pdf_obj *content_stream;
    70   font = pdf_create_font (pdf_page);
    72   font_dict = pdf_new_ind_ref (pdf_page->pdf_file,
    73 			       pdf_new_obj (PT_DICTIONARY));
    75   pdf_set_dict_entry (font_dict, "F1", font);
    77   pdf_set_dict_entry (pdf_page->resources, "Font", font_dict);
    79   pdf_add_array_elem_unique (pdf_page->procset, pdf_new_name ("Text"));
    81   content_stream = pdf_new_ind_ref (pdf_page->pdf_file,
    82 				    pdf_new_stream (pdf_page->pdf_file,
    83 						    pdf_new_obj (PT_DICTIONARY),
    84 						    & pdf_write_text_content_callback,
    85 						    NULL));
    87   pdf_set_dict_entry (pdf_page->page_dict, "Contents", content_stream);
    89   pdf_write_ind_obj (pdf_page->pdf_file, content_stream);
    90 }