diff --git a/CHANGES.md b/CHANGES.md index b76f808..f6af1d6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -9,6 +9,7 @@ v1.7.0 - YYYY-MM-DD - Added support for basic compound stream filters for ASCII85Decode support (Issue #11) - Added support for LZWDecode filters (Issue #11) +- Added support for GIF files (Issue #145) - Added `pdfioPageGetXxx` functions to get values from the page dictionaries (Issue #150) - Fixed a buffer overflow in the (still not enabled) AES-256 code. diff --git a/doc/pdfio.3 b/doc/pdfio.3 index 3c6f496..f5d5cfd 100644 --- a/doc/pdfio.3 +++ b/doc/pdfio.3 @@ -1,4 +1,4 @@ -.TH pdfio 3 "pdf read/write library" "2026-01-16" "pdf read/write library" +.TH pdfio 3 "pdf read/write library" "2026-01-18" "pdf read/write library" .SH NAME pdfio \- pdf read/write library .SH Introduction @@ -34,7 +34,7 @@ PDFio is .I not concerned with rendering or viewing a PDF file, although a PDF RIP or viewer could be written using it. .PP -PDFio is Copyright \[co] 2021\-2025 by Michael R Sweet and is licensed under the Apache License Version 2.0 with an (optional) exception to allow linking against GPL2/LGPL2 software. See the files "LICENSE" and "NOTICE" for more information. +PDFio is Copyright \[co] 2021\-2026 by Michael R Sweet and is licensed under the Apache License Version 2.0 with an (optional) exception to allow linking against GPL2/LGPL2 software. See the files "LICENSE" and "NOTICE" for more information. .SS Requirements .PP PDFio requires the following to build the software: @@ -361,41 +361,28 @@ Each PDF file contains one or more pages. The pdfioFileGetNumPages function retu } .fi .PP -Each page is represented by a "page tree" object (what pdfioFileGetPage returns) that specifies information about the page and one or more "content" objects that contain the images, fonts, text, and graphics that appear on the page. Use the pdfioPageGetNumStreams and pdfioPageOpenStream functions to access the content streams for each page, and pdfioObjGetDict to get the associated page object dictionary. For example, if you want to display the media and crop boxes for a given page: +Each page is represented by a "page tree" object (what pdfioFileGetPage returns) that specifies information about the page and one or more "content" objects that contain the images, fonts, text, and graphics that appear on the page. Use the pdfioPageGetNumStreams and pdfioPageOpenStream functions to access the content streams for each page, pdfioObjGetDict to get the associated page object dictionary, and pdfioPageGetArray, pdfioPageGetBinary, pdfioPageGetBoolean, pdfioPageGetDate, pdfioPageGetDict, pdfioPageGetName, pdfioPageGetObj, pdfioPageGetRect, and pdfioPageGetString to get a value from the page object dictionary or its parents. For example, if you want to display the media and crop boxes for a given page: .nf pdfio_file_t *pdf; // PDF file size_t i; // Looping var size_t count; // Number of pages pdfio_obj_t *page; // Current page - pdfio_dict_t *dict; // Current page dictionary - pdfio_array_t *media_box; // MediaBox array - double media_values[4]; // MediaBox values - pdfio_array_t *crop_box; // CropBox array - double crop_values[4]; // CropBox values + pdfio_rect_t media_box; // MediaBox values + pdfio_rect_t crop_box; // CropBox values // Iterate the pages in the PDF file for (i = 0, count = pdfioFileGetNumPages(pdf); i < count; i ++) { page = pdfioFileGetPage(pdf, i); - dict = pdfioObjGetDict(page); - media_box = pdfioDictGetArray(dict, "MediaBox"); - media_values[0] = pdfioArrayGetNumber(media_box, 0); - media_values[1] = pdfioArrayGetNumber(media_box, 1); - media_values[2] = pdfioArrayGetNumber(media_box, 2); - media_values[3] = pdfioArrayGetNumber(media_box, 3); - - crop_box = pdfioDictGetArray(dict, "CropBox"); - crop_values[0] = pdfioArrayGetNumber(crop_box, 0); - crop_values[1] = pdfioArrayGetNumber(crop_box, 1); - crop_values[2] = pdfioArrayGetNumber(crop_box, 2); - crop_values[3] = pdfioArrayGetNumber(crop_box, 3); + pdfioPageGetRect(page, "MediaBox", &media_box); + pdfioPageGetRect(page, "CropBox", &crop_box); printf("Page %u: MediaBox=[%g %g %g %g], CropBox=[%g %g %g %g]\\n", (unsigned)(i + 1), - media_values[0], media_values[1], media_values[2], media_values[3], - crop_values[0], crop_values[1], crop_values[2], crop_values[3]); + media_box.x1, media_box.y1, media_box.x2, media_box.y2, + crop_box.x1, crop_box.y1, crop_box.x2, crop_box.y2); } .fi .PP @@ -784,16 +771,13 @@ will create an object for a 1024x1024 RGBA image in memory, using the default co .PP The "interpolate" argument specifies whether the colors in the image should be smoothed/interpolated when scaling. This is most useful for photographs but should be false for screenshot and barcode images. .PP -If you have a JPEG or PNG file, use the pdfioFileCreateImageObjFromFile function to copy the image into a PDF image object, for example: +If you have a GIF, JPEG, or PNG file, use the pdfioFileCreateImageObjFromFile function to copy the image into a PDF image object, for example: .nf pdfio_file_t *pdf = pdfioFileCreate(...); pdfio_obj_t *img = pdfioFileCreateImageObjFromFile(pdf, "myphoto.jpg", /*interpolate*/true); .fi -.PP -Note: Currently pdfioFileCreateImageObjFromFile does not support 12 bit JPEG files or PNG files with an alpha channel. - .PP Page Dictionary Functions .PP @@ -1176,16 +1160,10 @@ The pdfioinfo.c example program opens a PDF file and prints the title, author, c for (cur = 0, prev = 0; cur < num_pages; cur ++) { // Find the MediaBox for this page in the page tree... - for (page = pdfioFileGetPage(pdf, cur); - page != NULL; - page = pdfioDictGetObj(page_dict, "Parent")) - { - cur_box.x1 = cur_box.x2 = cur_box.y1 = cur_box.y2 = 0.0; - page_dict = pdfioObjGetDict(page); + page = pdfioFileGetPage(pdf, cur); - if (pdfioDictGetRect(page_dict, "MediaBox", &cur_box)) - break; - } + cur_box.x1 = cur_box.x2 = cur_box.y1 = cur_box.y2 = 0.0; + pdfioPageGetRect(page, "MediaBox", &cur_box); // If this MediaBox is different from the previous one, show the range of // pages that have that size... @@ -1458,7 +1436,7 @@ Then we loop through the differences array, keeping track of the current index w .fi .SS Create a PDF File With Text and an Image .PP -The image2pdf.c example code creates a PDF file containing a JPEG or PNG image file and optional caption on a single page. The create_pdf_image_file function creates the PDF file, embeds a base font and the named JPEG or PNG image file, and then creates a page with the image centered on the page with any text centered below: +The image2pdf.c example code creates a PDF file containing a GIF, JPEG, or PNG image file and optional caption on a single page. The create_pdf_image_file function creates the PDF file, embeds a base font and the named JPEG or PNG image file, and then creates a page with the image centered on the page with any text centered below: .nf #include @@ -4209,15 +4187,17 @@ pdfio_obj_t * pdfioFileCreateImageObjFromFile ( ); .fi .PP -This function creates an image object in a PDF file from a JPEG or PNG file. -The "filename" parameter specifies the name of the JPEG or PNG file, while -the "interpolate" parameter specifies whether to interpolate when scaling the -image on the page. +This function creates an image object in a PDF file from a GIF, JPEG, or PNG +file. The "filename" parameter specifies the name of the GIF, JPEG, or PNG +file, while the "interpolate" parameter specifies whether to interpolate when +scaling the image on the page. .PP .IP 5 Note: PNG files containing transparency cannot be used when producing .IP 5 -PDF/A files. +PDF/A files. Files containing animation yield the final frame of the +.IP 5 +animation. .SS pdfioFileCreateNameObj Create a new object in a PDF file containing a name. .PP diff --git a/doc/pdfio.html b/doc/pdfio.html index 43d8845..8a2712d 100644 --- a/doc/pdfio.html +++ b/doc/pdfio.html @@ -560,7 +560,7 @@ span.string {

PDFio is not concerned with rendering or viewing a PDF file, although a PDF RIP or viewer could be written using it.

-

PDFio is Copyright © 2021-2025 by Michael R Sweet and is licensed under the Apache License Version 2.0 with an (optional) exception to allow linking against GPL2/LGPL2 software. See the files "LICENSE" and "NOTICE" for more information.

+

PDFio is Copyright © 2021-2026 by Michael R Sweet and is licensed under the Apache License Version 2.0 with an (optional) exception to allow linking against GPL2/LGPL2 software. See the files "LICENSE" and "NOTICE" for more information.

Requirements

PDFio requires the following to build the software: