Leptonica 1.83.1
Image processing and image analysis suite
Loading...
Searching...
No Matches
pdfio1.c
Go to the documentation of this file.
1/*====================================================================*
2 - Copyright (C) 2001 Leptonica. All rights reserved.
3 -
4 - Redistribution and use in source and binary forms, with or without
5 - modification, are permitted provided that the following conditions
6 - are met:
7 - 1. Redistributions of source code must retain the above copyright
8 - notice, this list of conditions and the following disclaimer.
9 - 2. Redistributions in binary form must reproduce the above
10 - copyright notice, this list of conditions and the following
11 - disclaimer in the documentation and/or other materials
12 - provided with the distribution.
13 -
14 - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
18 - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23 - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *====================================================================*/
26
199
200#ifdef HAVE_CONFIG_H
201#include <config_auto.h>
202#endif /* HAVE_CONFIG_H */
203
204#include <string.h>
205#include <math.h>
206#include "allheaders.h"
207
208/* --------------------------------------------*/
209#if USE_PDFIO /* defined in environ.h */
210 /* --------------------------------------------*/
211
212 /* Typical scan resolution in ppi (pixels/inch) */
213static const l_int32 DefaultInputRes = 300;
214
215/*---------------------------------------------------------------------*
216 * Convert specified image files to pdf (one image file per page) *
217 *---------------------------------------------------------------------*/
251l_ok
252convertFilesToPdf(const char *dirname,
253 const char *substr,
254 l_int32 res,
255 l_float32 scalefactor,
256 l_int32 type,
257 l_int32 quality,
258 const char *title,
259 const char *fileout)
260{
261l_int32 ret;
262SARRAY *sa;
263
264 if (!dirname)
265 return ERROR_INT("dirname not defined", __func__, 1);
266 if (!fileout)
267 return ERROR_INT("fileout not defined", __func__, 1);
268
269 if ((sa = getSortedPathnamesInDirectory(dirname, substr, 0, 0)) == NULL)
270 return ERROR_INT("sa not made", __func__, 1);
271 ret = saConvertFilesToPdf(sa, res, scalefactor, type, quality,
272 title, fileout);
273 sarrayDestroy(&sa);
274 return ret;
275}
276
277
298l_ok
300 l_int32 res,
301 l_float32 scalefactor,
302 l_int32 type,
303 l_int32 quality,
304 const char *title,
305 const char *fileout)
306{
307l_uint8 *data;
308l_int32 ret;
309size_t nbytes;
310
311 if (!sa)
312 return ERROR_INT("sa not defined", __func__, 1);
313
314 ret = saConvertFilesToPdfData(sa, res, scalefactor, type, quality,
315 title, &data, &nbytes);
316 if (ret) {
317 if (data) LEPT_FREE(data);
318 return ERROR_INT("pdf data not made", __func__, 1);
319 }
320
321 ret = l_binaryWrite(fileout, "w", data, nbytes);
322 LEPT_FREE(data);
323 if (ret)
324 L_ERROR("pdf data not written to file\n", __func__);
325 return ret;
326}
327
328
350l_ok
352 l_int32 res,
353 l_float32 scalefactor,
354 l_int32 type,
355 l_int32 quality,
356 const char *title,
357 l_uint8 **pdata,
358 size_t *pnbytes)
359{
360char *fname;
361l_uint8 *imdata;
362l_int32 i, n, ret, pagetype, npages, scaledres;
363size_t imbytes;
364L_BYTEA *ba;
365PIX *pixs, *pix;
366L_PTRA *pa_data;
367
368 if (!pdata)
369 return ERROR_INT("&data not defined", __func__, 1);
370 *pdata = NULL;
371 if (!pnbytes)
372 return ERROR_INT("&nbytes not defined", __func__, 1);
373 *pnbytes = 0;
374 if (!sa)
375 return ERROR_INT("sa not defined", __func__, 1);
376 if (scalefactor <= 0.0) scalefactor = 1.0;
377 if (type != L_JPEG_ENCODE && type != L_G4_ENCODE &&
378 type != L_FLATE_ENCODE && type != L_JP2K_ENCODE) {
379 type = L_DEFAULT_ENCODE;
380 }
381
382 /* Generate all the encoded pdf strings */
383 n = sarrayGetCount(sa);
384 pa_data = ptraCreate(n);
385 for (i = 0; i < n; i++) {
386 if (i && (i % 10 == 0)) lept_stderr(".. %d ", i);
387 fname = sarrayGetString(sa, i, L_NOCOPY);
388 if ((pixs = pixRead(fname)) == NULL) {
389 L_ERROR("image not readable from file %s\n", __func__, fname);
390 continue;
391 }
392 if (scalefactor != 1.0)
393 pix = pixScale(pixs, scalefactor, scalefactor);
394 else
395 pix = pixClone(pixs);
396 pixDestroy(&pixs);
397 scaledres = (l_int32)(res * scalefactor);
398
399 /* Select the encoding type */
400 if (type != L_DEFAULT_ENCODE) {
401 pagetype = type;
402 } else if (selectDefaultPdfEncoding(pix, &pagetype) != 0) {
403 pixDestroy(&pix);
404 L_ERROR("encoding type selection failed for file %s\n",
405 __func__, fname);
406 continue;
407 }
408
409 ret = pixConvertToPdfData(pix, pagetype, quality, &imdata, &imbytes,
410 0, 0, scaledres, title, NULL, 0);
411 pixDestroy(&pix);
412 if (ret) {
413 LEPT_FREE(imdata);
414 L_ERROR("pdf encoding failed for %s\n", __func__, fname);
415 continue;
416 }
417 ba = l_byteaInitFromMem(imdata, imbytes);
418 LEPT_FREE(imdata);
419 ptraAdd(pa_data, ba);
420 }
421 ptraGetActualCount(pa_data, &npages);
422 if (npages == 0) {
423 L_ERROR("no pdf files made\n", __func__);
424 ptraDestroy(&pa_data, FALSE, FALSE);
425 return 1;
426 }
427
428 /* Concatenate them */
429 lept_stderr("\nconcatenating ... ");
430 ret = ptraConcatenatePdfToData(pa_data, NULL, pdata, pnbytes);
431 lept_stderr("done\n");
432
433 ptraGetActualCount(pa_data, &npages); /* recalculate in case it changes */
434 for (i = 0; i < npages; i++) {
435 ba = (L_BYTEA *)ptraRemove(pa_data, i, L_NO_COMPACTION);
436 l_byteaDestroy(&ba);
437 }
438 ptraDestroy(&pa_data, FALSE, FALSE);
439 return ret;
440}
441
442
463l_ok
465 l_int32 *ptype)
466{
467l_int32 w, h, d, factor, ncolors;
468PIXCMAP *cmap;
469
470 if (!ptype)
471 return ERROR_INT("&type not defined", __func__, 1);
472 *ptype = L_FLATE_ENCODE; /* default universal encoding */
473 if (!pix)
474 return ERROR_INT("pix not defined", __func__, 1);
475 pixGetDimensions(pix, &w, &h, &d);
476 cmap = pixGetColormap(pix);
477 if (d == 8 && !cmap) {
478 factor = L_MAX(1, (l_int32)sqrt((l_float64)(w * h) / 20000.));
479 pixNumColors(pix, factor, &ncolors);
480 if (ncolors < 20)
481 *ptype = L_FLATE_ENCODE;
482 else
483 *ptype = L_JPEG_ENCODE;
484 } else if (d == 1) {
485 *ptype = L_G4_ENCODE;
486 } else if (cmap || d == 2 || d == 4) {
487 *ptype = L_FLATE_ENCODE;
488 } else if (d == 8 || d == 32) {
489 *ptype = L_JPEG_ENCODE;
490 } else if (d == 16) {
491 *ptype = L_FLATE_ENCODE;
492 } else {
493 return ERROR_INT("type selection failure", __func__, 1);
494 }
495
496 return 0;
497}
498
499
500/*---------------------------------------------------------------------*
501 * Convert specified image files to pdf without scaling *
502 *---------------------------------------------------------------------*/
526l_ok
527convertUnscaledFilesToPdf(const char *dirname,
528 const char *substr,
529 const char *title,
530 const char *fileout)
531{
532l_int32 ret;
533SARRAY *sa;
534
535 if (!dirname)
536 return ERROR_INT("dirname not defined", __func__, 1);
537 if (!fileout)
538 return ERROR_INT("fileout not defined", __func__, 1);
539
540 if ((sa = getSortedPathnamesInDirectory(dirname, substr, 0, 0)) == NULL)
541 return ERROR_INT("sa not made", __func__, 1);
542 ret = saConvertUnscaledFilesToPdf(sa, title, fileout);
543 sarrayDestroy(&sa);
544 return ret;
545}
546
547
561l_ok
563 const char *title,
564 const char *fileout)
565{
566l_uint8 *data;
567l_int32 ret;
568size_t nbytes;
569
570 if (!sa)
571 return ERROR_INT("sa not defined", __func__, 1);
572
573 ret = saConvertUnscaledFilesToPdfData(sa, title, &data, &nbytes);
574 if (ret) {
575 if (data) LEPT_FREE(data);
576 return ERROR_INT("pdf data not made", __func__, 1);
577 }
578
579 ret = l_binaryWrite(fileout, "w", data, nbytes);
580 LEPT_FREE(data);
581 if (ret)
582 L_ERROR("pdf data not written to file\n", __func__);
583 return ret;
584}
585
586
603l_ok
605 const char *title,
606 l_uint8 **pdata,
607 size_t *pnbytes)
608{
609char *fname;
610l_uint8 *imdata;
611l_int32 i, n, ret, npages;
612size_t imbytes;
613L_BYTEA *ba;
614L_PTRA *pa_data;
615
616 if (!pdata)
617 return ERROR_INT("&data not defined", __func__, 1);
618 *pdata = NULL;
619 if (!pnbytes)
620 return ERROR_INT("&nbytes not defined", __func__, 1);
621 *pnbytes = 0;
622 if (!sa)
623 return ERROR_INT("sa not defined", __func__, 1);
624
625 /* Generate all the encoded pdf strings */
626 n = sarrayGetCount(sa);
627 pa_data = ptraCreate(n);
628 for (i = 0; i < n; i++) {
629 if (i && (i % 10 == 0)) lept_stderr(".. %d ", i);
630 fname = sarrayGetString(sa, i, L_NOCOPY);
631
632 /* Generate the pdf data */
633 if (convertUnscaledToPdfData(fname, title, &imdata, &imbytes))
634 continue;
635
636 /* ... and add it to the array of single page data */
637 ba = l_byteaInitFromMem(imdata, imbytes);
638 if (imdata) LEPT_FREE(imdata);
639 ptraAdd(pa_data, ba);
640 }
641 ptraGetActualCount(pa_data, &npages);
642 if (npages == 0) {
643 L_ERROR("no pdf files made\n", __func__);
644 ptraDestroy(&pa_data, FALSE, FALSE);
645 return 1;
646 }
647
648 /* Concatenate to generate a multipage pdf */
649 lept_stderr("\nconcatenating ... ");
650 ret = ptraConcatenatePdfToData(pa_data, NULL, pdata, pnbytes);
651 lept_stderr("done\n");
652
653 /* Clean up */
654 ptraGetActualCount(pa_data, &npages); /* maybe failed to read some files */
655 for (i = 0; i < npages; i++) {
656 ba = (L_BYTEA *)ptraRemove(pa_data, i, L_NO_COMPACTION);
657 l_byteaDestroy(&ba);
658 }
659 ptraDestroy(&pa_data, FALSE, FALSE);
660 return ret;
661}
662
663
680l_ok
681convertUnscaledToPdfData(const char *fname,
682 const char *title,
683 l_uint8 **pdata,
684 size_t *pnbytes)
685{
686l_int32 format;
687L_COMP_DATA *cid;
688
689 if (!pdata)
690 return ERROR_INT("&data not defined", __func__, 1);
691 *pdata = NULL;
692 if (!pnbytes)
693 return ERROR_INT("&nbytes not defined", __func__, 1);
694 *pnbytes = 0;
695 if (!fname)
696 return ERROR_INT("fname not defined", __func__, 1);
697
698 findFileFormat(fname, &format);
699 if (format == IFF_UNKNOWN) {
700 L_WARNING("file %s format is unknown; skip\n", __func__, fname);
701 return 1;
702 }
703 if (format == IFF_PS || format == IFF_LPDF) {
704 L_WARNING("file %s format is %d; skip\n", __func__, fname, format);
705 return 1;
706 }
707
708 /* Generate the image data required for pdf generation, always
709 * in binary (not ascii85) coding. Note that jpeg, jp2k and some
710 * png files are not transcoded. */
711 l_generateCIDataForPdf(fname, NULL, 0, &cid);
712 if (!cid) {
713 L_ERROR("file %s format is %d; unreadable\n", __func__, fname, format);
714 return 1;
715 }
716
717 /* Generate the pdf string for this page (image). This destroys
718 * the cid by attaching it to an lpd and destroying the lpd. */
719 cidConvertToPdfData(cid, title, pdata, pnbytes);
720 return 0;
721}
722
723
724/*---------------------------------------------------------------------*
725 * Convert multiple images to pdf (one image per page) *
726 *---------------------------------------------------------------------*/
755l_ok
757 l_int32 res,
758 l_float32 scalefactor,
759 l_int32 type,
760 l_int32 quality,
761 const char *title,
762 const char *fileout)
763{
764l_uint8 *data;
765l_int32 ret;
766size_t nbytes;
767
768 if (!pixa)
769 return ERROR_INT("pixa not defined", __func__, 1);
770
771 ret = pixaConvertToPdfData(pixa, res, scalefactor, type, quality,
772 title, &data, &nbytes);
773 if (ret) {
774 LEPT_FREE(data);
775 return ERROR_INT("conversion to pdf failed", __func__, 1);
776 }
777
778 ret = l_binaryWrite(fileout, "w", data, nbytes);
779 LEPT_FREE(data);
780 if (ret)
781 L_ERROR("pdf data not written to file\n", __func__);
782 return ret;
783}
784
785
807l_ok
809 l_int32 res,
810 l_float32 scalefactor,
811 l_int32 type,
812 l_int32 quality,
813 const char *title,
814 l_uint8 **pdata,
815 size_t *pnbytes)
816{
817l_uint8 *imdata;
818l_int32 i, n, ret, scaledres, pagetype;
819size_t imbytes;
820L_BYTEA *ba;
821PIX *pixs, *pix;
822L_PTRA *pa_data;
823
824 if (!pdata)
825 return ERROR_INT("&data not defined", __func__, 1);
826 *pdata = NULL;
827 if (!pnbytes)
828 return ERROR_INT("&nbytes not defined", __func__, 1);
829 *pnbytes = 0;
830 if (!pixa)
831 return ERROR_INT("pixa not defined", __func__, 1);
832 if (scalefactor <= 0.0) scalefactor = 1.0;
833 if (scalefactor >= 50.0)
834 return ERROR_INT("scalefactor too large", __func__, 1);
835 if (type != L_DEFAULT_ENCODE && type != L_JPEG_ENCODE &&
836 type != L_G4_ENCODE && type != L_FLATE_ENCODE &&
837 type != L_JP2K_ENCODE) {
838 L_WARNING("invalid compression type; using per-page default\n",
839 __func__);
840 type = L_DEFAULT_ENCODE;
841 }
842 if (quality < 0 || quality > 100)
843 return ERROR_INT("invalid quality", __func__, 1);
844
845 /* Generate all the encoded pdf strings */
846 n = pixaGetCount(pixa);
847 pa_data = ptraCreate(n);
848 for (i = 0; i < n; i++) {
849 if ((pixs = pixaGetPix(pixa, i, L_CLONE)) == NULL) {
850 L_ERROR("pixs[%d] not retrieved\n", __func__, i);
851 continue;
852 }
853 if (scalefactor != 1.0)
854 pix = pixScale(pixs, scalefactor, scalefactor);
855 else
856 pix = pixClone(pixs);
857 pixDestroy(&pixs);
858 if (!pix) {
859 L_ERROR("pix[%d] not made\n", __func__, i);
860 continue;
861 }
862 scaledres = (l_int32)(res * scalefactor);
863
864 /* Select the encoding type */
865 if (type != L_DEFAULT_ENCODE) {
866 pagetype = type;
867 } else if (selectDefaultPdfEncoding(pix, &pagetype) != 0) {
868 L_ERROR("encoding type selection failed for pix[%d]\n",
869 __func__, i);
870 pixDestroy(&pix);
871 continue;
872 }
873
874 ret = pixConvertToPdfData(pix, pagetype, quality, &imdata, &imbytes,
875 0, 0, scaledres, title, NULL, 0);
876 pixDestroy(&pix);
877 if (ret) {
878 LEPT_FREE(imdata);
879 L_ERROR("pdf encoding failed for pix[%d]\n", __func__, i);
880 continue;
881 }
882 ba = l_byteaInitFromMem(imdata, imbytes);
883 LEPT_FREE(imdata);
884 ptraAdd(pa_data, ba);
885 }
886 ptraGetActualCount(pa_data, &n);
887 if (n == 0) {
888 L_ERROR("no pdf files made\n", __func__);
889 ptraDestroy(&pa_data, FALSE, FALSE);
890 return 1;
891 }
892
893 /* Concatenate them */
894 ret = ptraConcatenatePdfToData(pa_data, NULL, pdata, pnbytes);
895
896 ptraGetActualCount(pa_data, &n); /* recalculate in case it changes */
897 for (i = 0; i < n; i++) {
898 ba = (L_BYTEA *)ptraRemove(pa_data, i, L_NO_COMPACTION);
899 l_byteaDestroy(&ba);
900 }
901 ptraDestroy(&pa_data, FALSE, FALSE);
902 return ret;
903}
904
905
906/*---------------------------------------------------------------------*
907 * Single page, multi-image converters *
908 *---------------------------------------------------------------------*/
968l_ok
969convertToPdf(const char *filein,
970 l_int32 type,
971 l_int32 quality,
972 const char *fileout,
973 l_int32 x,
974 l_int32 y,
975 l_int32 res,
976 const char *title,
977 L_PDF_DATA **plpd,
978 l_int32 position)
979{
980l_uint8 *data;
981l_int32 ret;
982size_t nbytes;
983
984 if (!filein)
985 return ERROR_INT("filein not defined", __func__, 1);
986 if (!plpd || (position == L_LAST_IMAGE)) {
987 if (!fileout)
988 return ERROR_INT("fileout not defined", __func__, 1);
989 }
990
991 if (convertToPdfData(filein, type, quality, &data, &nbytes, x, y,
992 res, title, plpd, position))
993 return ERROR_INT("pdf data not made", __func__, 1);
994
995 if (!plpd || (position == L_LAST_IMAGE)) {
996 ret = l_binaryWrite(fileout, "w", data, nbytes);
997 LEPT_FREE(data);
998 if (ret)
999 return ERROR_INT("pdf data not written to file", __func__, 1);
1000 }
1001
1002 return 0;
1003}
1004
1005
1038l_ok
1040 size_t size,
1041 l_int32 type,
1042 l_int32 quality,
1043 const char *fileout,
1044 l_int32 x,
1045 l_int32 y,
1046 l_int32 res,
1047 const char *title,
1048 L_PDF_DATA **plpd,
1049 l_int32 position)
1050{
1051l_int32 ret;
1052PIX *pix;
1053
1054 if (!imdata)
1055 return ERROR_INT("image data not defined", __func__, 1);
1056 if (!plpd || (position == L_LAST_IMAGE)) {
1057 if (!fileout)
1058 return ERROR_INT("fileout not defined", __func__, 1);
1059 }
1060
1061 if ((pix = pixReadMem(imdata, size)) == NULL)
1062 return ERROR_INT("pix not read", __func__, 1);
1063 if (type != L_JPEG_ENCODE && type != L_G4_ENCODE &&
1064 type != L_FLATE_ENCODE && type != L_JP2K_ENCODE) {
1065 selectDefaultPdfEncoding(pix, &type);
1066 }
1067 ret = pixConvertToPdf(pix, type, quality, fileout, x, y, res,
1068 title, plpd, position);
1069 pixDestroy(&pix);
1070 return ret;
1071}
1072
1073
1105l_ok
1106convertToPdfData(const char *filein,
1107 l_int32 type,
1108 l_int32 quality,
1109 l_uint8 **pdata,
1110 size_t *pnbytes,
1111 l_int32 x,
1112 l_int32 y,
1113 l_int32 res,
1114 const char *title,
1115 L_PDF_DATA **plpd,
1116 l_int32 position)
1117{
1118PIX *pix;
1119
1120 if (!pdata)
1121 return ERROR_INT("&data not defined", __func__, 1);
1122 *pdata = NULL;
1123 if (!pnbytes)
1124 return ERROR_INT("&nbytes not defined", __func__, 1);
1125 *pnbytes = 0;
1126 if (!filein)
1127 return ERROR_INT("filein not defined", __func__, 1);
1128
1129 if ((pix = pixRead(filein)) == NULL)
1130 return ERROR_INT("pix not made", __func__, 1);
1131
1132 pixConvertToPdfData(pix, type, quality, pdata, pnbytes,
1133 x, y, res, title, plpd, position);
1134 pixDestroy(&pix);
1135 return 0;
1136}
1137
1138
1171l_ok
1173 size_t size,
1174 l_int32 type,
1175 l_int32 quality,
1176 l_uint8 **pdata,
1177 size_t *pnbytes,
1178 l_int32 x,
1179 l_int32 y,
1180 l_int32 res,
1181 const char *title,
1182 L_PDF_DATA **plpd,
1183 l_int32 position)
1184{
1185l_int32 ret;
1186PIX *pix;
1187
1188 if (!pdata)
1189 return ERROR_INT("&data not defined", __func__, 1);
1190 *pdata = NULL;
1191 if (!pnbytes)
1192 return ERROR_INT("&nbytes not defined", __func__, 1);
1193 *pnbytes = 0;
1194 if (!imdata)
1195 return ERROR_INT("image data not defined", __func__, 1);
1196 if (plpd) { /* part of multi-page invocation */
1197 if (position == L_FIRST_IMAGE)
1198 *plpd = NULL;
1199 }
1200
1201 if ((pix = pixReadMem(imdata, size)) == NULL)
1202 return ERROR_INT("pix not read", __func__, 1);
1203 if (type != L_JPEG_ENCODE && type != L_G4_ENCODE &&
1204 type != L_FLATE_ENCODE && type != L_JP2K_ENCODE) {
1205 selectDefaultPdfEncoding(pix, &type);
1206 }
1207 ret = pixConvertToPdfData(pix, type, quality, pdata, pnbytes,
1208 x, y, res, title, plpd, position);
1209 pixDestroy(&pix);
1210 return ret;
1211}
1212
1213
1247l_ok
1249 l_int32 type,
1250 l_int32 quality,
1251 const char *fileout,
1252 l_int32 x,
1253 l_int32 y,
1254 l_int32 res,
1255 const char *title,
1256 L_PDF_DATA **plpd,
1257 l_int32 position)
1258{
1259l_uint8 *data;
1260l_int32 ret;
1261size_t nbytes;
1262
1263 if (!pix)
1264 return ERROR_INT("pix not defined", __func__, 1);
1265 if (!plpd || (position == L_LAST_IMAGE)) {
1266 if (!fileout)
1267 return ERROR_INT("fileout not defined", __func__, 1);
1268 }
1269
1270 if (pixConvertToPdfData(pix, type, quality, &data, &nbytes,
1271 x, y, res, title, plpd, position)) {
1272 LEPT_FREE(data);
1273 return ERROR_INT("pdf data not made", __func__, 1);
1274 }
1275
1276 if (!plpd || (position == L_LAST_IMAGE)) {
1277 ret = l_binaryWrite(fileout, "w", data, nbytes);
1278 LEPT_FREE(data);
1279 if (ret)
1280 return ERROR_INT("pdf data not written to file", __func__, 1);
1281 }
1282 return 0;
1283}
1284
1285
1304l_ok
1306 PIX *pix,
1307 l_int32 res,
1308 const char *title)
1309{
1310l_uint8 *data;
1311size_t nbytes, nbytes_written;
1312
1313 if (!fp)
1314 return ERROR_INT("stream not opened", __func__, 1);
1315 if (!pix)
1316 return ERROR_INT("pix not defined", __func__, 1);
1317
1318 if (pixWriteMemPdf(&data, &nbytes, pix, res, title) != 0) {
1319 LEPT_FREE(data);
1320 return ERROR_INT("pdf data not made", __func__, 1);
1321 }
1322
1323 nbytes_written = fwrite(data, 1, nbytes, fp);
1324 LEPT_FREE(data);
1325 if (nbytes != nbytes_written)
1326 return ERROR_INT("failure writing pdf data to stream", __func__, 1);
1327 return 0;
1328}
1329
1330
1350l_ok
1351pixWriteMemPdf(l_uint8 **pdata,
1352 size_t *pnbytes,
1353 PIX *pix,
1354 l_int32 res,
1355 const char *title)
1356{
1357l_int32 ret, type;
1358
1359 if (pdata) *pdata = NULL;
1360 if (pnbytes) *pnbytes = 0;
1361 if (!pdata || !pnbytes)
1362 return ERROR_INT("&data or &nbytes not defined", __func__, 1);
1363 if (!pix)
1364 return ERROR_INT("pix not defined", __func__, 1);
1365
1366 selectDefaultPdfEncoding(pix, &type);
1367 ret = pixConvertToPdfData(pix, type, 75, pdata, pnbytes,
1368 0, 0, res, title, NULL, 0);
1369 if (ret)
1370 return ERROR_INT("pdf data not made", __func__, 1);
1371 return 0;
1372}
1373
1374
1375/*---------------------------------------------------------------------*
1376 * Segmented multi-page, multi-image converter *
1377 *---------------------------------------------------------------------*/
1421l_ok
1422convertSegmentedFilesToPdf(const char *dirname,
1423 const char *substr,
1424 l_int32 res,
1425 l_int32 type,
1426 l_int32 thresh,
1427 BOXAA *baa,
1428 l_int32 quality,
1429 l_float32 scalefactor,
1430 const char *title,
1431 const char *fileout)
1432{
1433char *fname;
1434l_uint8 *imdata, *data;
1435l_int32 i, npages, nboxa, nboxes, ret;
1436size_t imbytes, databytes;
1437BOXA *boxa;
1438L_BYTEA *ba;
1439L_PTRA *pa_data;
1440SARRAY *sa;
1441
1442 if (!dirname)
1443 return ERROR_INT("dirname not defined", __func__, 1);
1444 if (!fileout)
1445 return ERROR_INT("fileout not defined", __func__, 1);
1446
1447 if ((sa = getNumberedPathnamesInDirectory(dirname, substr, 0, 0, 10000))
1448 == NULL)
1449 return ERROR_INT("sa not made", __func__, 1);
1450
1451 npages = sarrayGetCount(sa);
1452 /* If necessary, extend the boxaa, which is page-aligned with
1453 * the image files, to be as large as the set of images. */
1454 if (baa) {
1455 nboxa = boxaaGetCount(baa);
1456 if (nboxa < npages) {
1457 boxa = boxaCreate(1);
1458 boxaaExtendWithInit(baa, npages, boxa);
1459 boxaDestroy(&boxa);
1460 }
1461 }
1462
1463 /* Generate and save all the encoded pdf strings */
1464 pa_data = ptraCreate(npages);
1465 for (i = 0; i < npages; i++) {
1466 fname = sarrayGetString(sa, i, L_NOCOPY);
1467 if (!strcmp(fname, "")) continue;
1468 boxa = NULL;
1469 if (baa) {
1470 boxa = boxaaGetBoxa(baa, i, L_CLONE);
1471 nboxes = boxaGetCount(boxa);
1472 if (nboxes == 0)
1473 boxaDestroy(&boxa);
1474 }
1475 ret = convertToPdfDataSegmented(fname, res, type, thresh, boxa,
1476 quality, scalefactor, title,
1477 &imdata, &imbytes);
1478 boxaDestroy(&boxa); /* safe; in case nboxes > 0 */
1479 if (ret) {
1480 L_ERROR("pdf encoding failed for %s\n", __func__, fname);
1481 continue;
1482 }
1483 ba = l_byteaInitFromMem(imdata, imbytes);
1484 if (imdata) LEPT_FREE(imdata);
1485 ptraAdd(pa_data, ba);
1486 }
1487 sarrayDestroy(&sa);
1488
1489 ptraGetActualCount(pa_data, &npages);
1490 if (npages == 0) {
1491 L_ERROR("no pdf files made\n", __func__);
1492 ptraDestroy(&pa_data, FALSE, FALSE);
1493 return 1;
1494 }
1495
1496 /* Concatenate */
1497 ret = ptraConcatenatePdfToData(pa_data, NULL, &data, &databytes);
1498
1499 /* Clean up */
1500 ptraGetActualCount(pa_data, &npages); /* recalculate in case it changes */
1501 for (i = 0; i < npages; i++) {
1502 ba = (L_BYTEA *)ptraRemove(pa_data, i, L_NO_COMPACTION);
1503 l_byteaDestroy(&ba);
1504 }
1505 ptraDestroy(&pa_data, FALSE, FALSE);
1506
1507 if (ret) {
1508 if (data) LEPT_FREE(data);
1509 return ERROR_INT("pdf data not made", __func__, 1);
1510 }
1511
1512 ret = l_binaryWrite(fileout, "w", data, databytes);
1513 LEPT_FREE(data);
1514 if (ret)
1515 L_ERROR("pdf data not written to file\n", __func__);
1516 return ret;
1517}
1518
1519
1539BOXAA *
1541 const char *substr,
1542 l_int32 numpre,
1543 l_int32 numpost)
1544{
1545char *fname;
1546l_int32 i, n;
1547BOXA *boxa;
1548BOXAA *baa;
1549PIX *pix;
1550SARRAY *sa;
1551
1552 if (!dirname)
1553 return (BOXAA *)ERROR_PTR("dirname not defined", __func__, NULL);
1554
1555 if ((sa = getNumberedPathnamesInDirectory(dirname, substr, numpre,
1556 numpost, 10000)) == NULL)
1557 return (BOXAA *)ERROR_PTR("sa not made", __func__, NULL);
1558
1559 /* Generate and save all the encoded pdf strings */
1560 n = sarrayGetCount(sa);
1561 baa = boxaaCreate(n);
1562 boxa = boxaCreate(1);
1563 boxaaInitFull(baa, boxa);
1564 boxaDestroy(&boxa);
1565 for (i = 0; i < n; i++) {
1566 fname = sarrayGetString(sa, i, L_NOCOPY);
1567 if (!strcmp(fname, "")) continue;
1568 if ((pix = pixRead(fname)) == NULL) {
1569 L_WARNING("invalid image on page %d\n", __func__, i);
1570 continue;
1571 }
1572 boxa = pixConnComp(pix, NULL, 8);
1573 boxaaReplaceBoxa(baa, i, boxa);
1574 pixDestroy(&pix);
1575 }
1576
1577 sarrayDestroy(&sa);
1578 return baa;
1579}
1580
1581
1582/*---------------------------------------------------------------------*
1583 * Segmented single page, multi-image converters *
1584 *---------------------------------------------------------------------*/
1646l_ok
1647convertToPdfSegmented(const char *filein,
1648 l_int32 res,
1649 l_int32 type,
1650 l_int32 thresh,
1651 BOXA *boxa,
1652 l_int32 quality,
1653 l_float32 scalefactor,
1654 const char *title,
1655 const char *fileout)
1656{
1657l_int32 ret;
1658PIX *pixs;
1659
1660 if (!filein)
1661 return ERROR_INT("filein not defined", __func__, 1);
1662 if (!fileout)
1663 return ERROR_INT("fileout not defined", __func__, 1);
1664 if (type != L_G4_ENCODE && type != L_JPEG_ENCODE &&
1665 type != L_FLATE_ENCODE)
1666 return ERROR_INT("invalid conversion type", __func__, 1);
1667 if (boxa && scalefactor > 1.0) {
1668 L_WARNING("setting scalefactor to 1.0\n", __func__);
1669 scalefactor = 1.0;
1670 }
1671
1672 if ((pixs = pixRead(filein)) == NULL)
1673 return ERROR_INT("pixs not made", __func__, 1);
1674
1675 ret = pixConvertToPdfSegmented(pixs, res, type, thresh, boxa, quality,
1676 scalefactor, title, fileout);
1677 pixDestroy(&pixs);
1678 return ret;
1679}
1680
1681
1703l_ok
1705 l_int32 res,
1706 l_int32 type,
1707 l_int32 thresh,
1708 BOXA *boxa,
1709 l_int32 quality,
1710 l_float32 scalefactor,
1711 const char *title,
1712 const char *fileout)
1713{
1714l_uint8 *data;
1715l_int32 ret;
1716size_t nbytes;
1717
1718 if (!pixs)
1719 return ERROR_INT("pixs not defined", __func__, 1);
1720 if (!fileout)
1721 return ERROR_INT("fileout not defined", __func__, 1);
1722 if (type != L_G4_ENCODE && type != L_JPEG_ENCODE &&
1723 type != L_FLATE_ENCODE)
1724 return ERROR_INT("invalid conversion type", __func__, 1);
1725 if (boxa && scalefactor > 1.0) {
1726 L_WARNING("setting scalefactor to 1.0\n", __func__);
1727 scalefactor = 1.0;
1728 }
1729
1730 ret = pixConvertToPdfDataSegmented(pixs, res, type, thresh, boxa, quality,
1731 scalefactor, title, &data, &nbytes);
1732 if (ret)
1733 return ERROR_INT("pdf generation failure", __func__, 1);
1734
1735 ret = l_binaryWrite(fileout, "w", data, nbytes);
1736 if (data) LEPT_FREE(data);
1737 return ret;
1738}
1739
1740
1765l_ok
1766convertToPdfDataSegmented(const char *filein,
1767 l_int32 res,
1768 l_int32 type,
1769 l_int32 thresh,
1770 BOXA *boxa,
1771 l_int32 quality,
1772 l_float32 scalefactor,
1773 const char *title,
1774 l_uint8 **pdata,
1775 size_t *pnbytes)
1776{
1777l_int32 ret;
1778PIX *pixs;
1779
1780 if (!pdata)
1781 return ERROR_INT("&data not defined", __func__, 1);
1782 *pdata = NULL;
1783 if (!pnbytes)
1784 return ERROR_INT("&nbytes not defined", __func__, 1);
1785 *pnbytes = 0;
1786 if (!filein)
1787 return ERROR_INT("filein not defined", __func__, 1);
1788 if (type != L_G4_ENCODE && type != L_JPEG_ENCODE &&
1789 type != L_FLATE_ENCODE)
1790 return ERROR_INT("invalid conversion type", __func__, 1);
1791 if (boxa && scalefactor > 1.0) {
1792 L_WARNING("setting scalefactor to 1.0\n", __func__);
1793 scalefactor = 1.0;
1794 }
1795
1796 if ((pixs = pixRead(filein)) == NULL)
1797 return ERROR_INT("pixs not made", __func__, 1);
1798
1799 ret = pixConvertToPdfDataSegmented(pixs, res, type, thresh, boxa,
1800 quality, scalefactor, title,
1801 pdata, pnbytes);
1802 pixDestroy(&pixs);
1803 return ret;
1804}
1805
1806
1829l_ok
1831 l_int32 res,
1832 l_int32 type,
1833 l_int32 thresh,
1834 BOXA *boxa,
1835 l_int32 quality,
1836 l_float32 scalefactor,
1837 const char *title,
1838 l_uint8 **pdata,
1839 size_t *pnbytes)
1840{
1841l_int32 i, nbox, seq, bx, by, bw, bh, upscale;
1842l_float32 scale;
1843BOX *box, *boxc, *box2;
1844PIX *pix, *pixt1, *pixt2, *pixt3, *pixt4, *pixt5, *pixt6;
1845PIXCMAP *cmap;
1846L_PDF_DATA *lpd;
1847
1848 if (!pdata)
1849 return ERROR_INT("&data not defined", __func__, 1);
1850 *pdata = NULL;
1851 if (!pnbytes)
1852 return ERROR_INT("&nbytes not defined", __func__, 1);
1853 *pnbytes = 0;
1854 if (!pixs)
1855 return ERROR_INT("pixs not defined", __func__, 1);
1856 if (type != L_G4_ENCODE && type != L_JPEG_ENCODE &&
1857 type != L_FLATE_ENCODE)
1858 return ERROR_INT("invalid conversion type", __func__, 1);
1859 if (boxa && (scalefactor <= 0.0 || scalefactor > 1.0)) {
1860 L_WARNING("setting scalefactor to 1.0\n", __func__);
1861 scalefactor = 1.0;
1862 }
1863
1864 /* Adjust scalefactor so that the product with res gives an integer */
1865 if (res <= 0)
1866 res = DefaultInputRes;
1867 scale = (l_float32)((l_int32)(scalefactor * res + 0.5)) / (l_float32)res;
1868 cmap = pixGetColormap(pixs);
1869
1870 /* Simple case: single image to be encoded */
1871 if (!boxa || boxaGetCount(boxa) == 0) {
1872 if (pixGetDepth(pixs) > 1 && type == L_G4_ENCODE) {
1873 if (cmap)
1874 pixt1 = pixRemoveColormap(pixs, REMOVE_CMAP_TO_GRAYSCALE);
1875 else
1876 pixt1 = pixConvertTo8(pixs, FALSE);
1877 pixt2 = pixScaleGray2xLIThresh(pixt1, thresh);
1878 pixConvertToPdfData(pixt2, type, quality, pdata, pnbytes,
1879 0, 0, 2 * res, title, NULL, 0);
1880 pixDestroy(&pixt1);
1881 pixDestroy(&pixt2);
1882 } else {
1883 pixConvertToPdfData(pixs, type, quality, pdata, pnbytes,
1884 0, 0, res, title, NULL, 0);
1885 }
1886 return 0;
1887 }
1888
1889 /* Multiple images to be encoded. If %type == L_G4_ENCODE,
1890 * jpeg encode a version of pixs that is blanked in the non-image
1891 * regions, and paint the scaled non-image part onto it through a mask.
1892 * Otherwise, we must put the non-image part down first and
1893 * then render all the image regions separately on top of it,
1894 * at their own resolution. */
1895 pixt1 = pixSetBlackOrWhiteBoxa(pixs, boxa, L_SET_WHITE); /* non-image */
1896 nbox = boxaGetCount(boxa);
1897 if (type == L_G4_ENCODE) {
1898 pixt2 = pixCreateTemplate(pixs); /* only image regions */
1899 pixSetBlackOrWhite(pixt2, L_SET_WHITE);
1900 for (i = 0; i < nbox; i++) {
1901 box = boxaGetBox(boxa, i, L_CLONE);
1902 pix = pixClipRectangle(pixs, box, &boxc);
1903 boxGetGeometry(boxc, &bx, &by, &bw, &bh);
1904 pixRasterop(pixt2, bx, by, bw, bh, PIX_SRC, pix, 0, 0);
1905 pixDestroy(&pix);
1906 boxDestroy(&box);
1907 boxDestroy(&boxc);
1908 }
1909 pixt3 = pixRemoveColormap(pixt2, REMOVE_CMAP_BASED_ON_SRC);
1910 if (pixGetDepth(pixt3) == 1)
1911 pixt4 = pixScaleToGray(pixt3, scale);
1912 else
1913 pixt4 = pixScale(pixt3, scale, scale);
1914 pixConvertToPdfData(pixt4, L_JPEG_ENCODE, quality, pdata, pnbytes,
1915 0, 0, (l_int32)(scale * res), title,
1916 &lpd, L_FIRST_IMAGE);
1917
1918 if (pixGetDepth(pixt1) == 1) {
1919 pixt5 = pixClone(pixt1);
1920 upscale = 1;
1921 } else {
1922 pixt6 = pixConvertTo8(pixt1, 0);
1923 pixt5 = pixScaleGray2xLIThresh(pixt6, thresh);
1924 pixDestroy(&pixt6);
1925 upscale = 2;
1926 }
1927 pixConvertToPdfData(pixt5, L_G4_ENCODE, quality, pdata, pnbytes,
1928 0, 0, upscale * res, title, &lpd, L_LAST_IMAGE);
1929 pixDestroy(&pixt2);
1930 pixDestroy(&pixt3);
1931 pixDestroy(&pixt4);
1932 pixDestroy(&pixt5);
1933 } else {
1934 /* Put the non-image part down first. This is the full
1935 size of the page, so we can use it to find the page
1936 height in pixels, which is required for determining
1937 the LL corner of the image relative to the LL corner
1938 of the page. */
1939 pixConvertToPdfData(pixt1, type, quality, pdata, pnbytes, 0, 0,
1940 res, title, &lpd, L_FIRST_IMAGE);
1941 for (i = 0; i < nbox; i++) {
1942 box = boxaGetBox(boxa, i, L_CLONE);
1943 pixt2 = pixClipRectangle(pixs, box, &boxc);
1944 pixt3 = pixRemoveColormap(pixt2, REMOVE_CMAP_BASED_ON_SRC);
1945 if (pixGetDepth(pixt3) == 1)
1946 pixt4 = pixScaleToGray(pixt3, scale);
1947 else
1948 pixt4 = pixScale(pixt3, scale, scale);
1949 box2 = boxTransform(boxc, 0, 0, scale, scale);
1950 boxGetGeometry(box2, &bx, &by, NULL, &bh);
1951 seq = (i == nbox - 1) ? L_LAST_IMAGE : L_NEXT_IMAGE;
1952 pixConvertToPdfData(pixt4, L_JPEG_ENCODE, quality, pdata, pnbytes,
1953 bx, by, (l_int32)(scale * res), title,
1954 &lpd, seq);
1955 pixDestroy(&pixt2);
1956 pixDestroy(&pixt3);
1957 pixDestroy(&pixt4);
1958 boxDestroy(&box);
1959 boxDestroy(&boxc);
1960 boxDestroy(&box2);
1961 }
1962 }
1963
1964 pixDestroy(&pixt1);
1965 return 0;
1966}
1967
1968
1969/*---------------------------------------------------------------------*
1970 * Multi-page concatenation *
1971 *---------------------------------------------------------------------*/
1992l_ok
1993concatenatePdf(const char *dirname,
1994 const char *substr,
1995 const char *fileout)
1996{
1997l_int32 ret;
1998SARRAY *sa;
1999
2000 if (!dirname)
2001 return ERROR_INT("dirname not defined", __func__, 1);
2002 if (!fileout)
2003 return ERROR_INT("fileout not defined", __func__, 1);
2004
2005 if ((sa = getSortedPathnamesInDirectory(dirname, substr, 0, 0)) == NULL)
2006 return ERROR_INT("sa not made", __func__, 1);
2007 ret = saConcatenatePdf(sa, fileout);
2008 sarrayDestroy(&sa);
2009 return ret;
2010}
2011
2012
2025l_ok
2027 const char *fileout)
2028{
2029l_uint8 *data;
2030l_int32 ret;
2031size_t nbytes;
2032
2033 if (!sa)
2034 return ERROR_INT("sa not defined", __func__, 1);
2035 if (!fileout)
2036 return ERROR_INT("fileout not defined", __func__, 1);
2037
2038 ret = saConcatenatePdfToData(sa, &data, &nbytes);
2039 if (ret)
2040 return ERROR_INT("pdf data not made", __func__, 1);
2041 ret = l_binaryWrite(fileout, "w", data, nbytes);
2042 LEPT_FREE(data);
2043 return ret;
2044}
2045
2046
2059l_ok
2061 const char *fileout)
2062{
2063l_uint8 *data;
2064l_int32 ret;
2065size_t nbytes;
2066
2067 if (!pa)
2068 return ERROR_INT("pa not defined", __func__, 1);
2069 if (!fileout)
2070 return ERROR_INT("fileout not defined", __func__, 1);
2071
2072 ret = ptraConcatenatePdfToData(pa, NULL, &data, &nbytes);
2073 if (ret)
2074 return ERROR_INT("pdf data not made", __func__, 1);
2075 ret = l_binaryWrite(fileout, "w", data, nbytes);
2076 LEPT_FREE(data);
2077 return ret;
2078}
2079
2080
2102l_ok
2103concatenatePdfToData(const char *dirname,
2104 const char *substr,
2105 l_uint8 **pdata,
2106 size_t *pnbytes)
2107{
2108l_int32 ret;
2109SARRAY *sa;
2110
2111 if (!pdata)
2112 return ERROR_INT("&data not defined", __func__, 1);
2113 *pdata = NULL;
2114 if (!pnbytes)
2115 return ERROR_INT("&nbytes not defined", __func__, 1);
2116 *pnbytes = 0;
2117 if (!dirname)
2118 return ERROR_INT("dirname not defined", __func__, 1);
2119
2120 if ((sa = getSortedPathnamesInDirectory(dirname, substr, 0, 0)) == NULL)
2121 return ERROR_INT("sa not made", __func__, 1);
2122 ret = saConcatenatePdfToData(sa, pdata, pnbytes);
2123 sarrayDestroy(&sa);
2124 return ret;
2125}
2126
2127
2141l_ok
2143 l_uint8 **pdata,
2144 size_t *pnbytes)
2145{
2146char *fname;
2147l_int32 i, npages, ret;
2148L_BYTEA *bas;
2149L_PTRA *pa_data; /* input pdf data for each page */
2150
2151 if (!pdata)
2152 return ERROR_INT("&data not defined", __func__, 1);
2153 *pdata = NULL;
2154 if (!pnbytes)
2155 return ERROR_INT("&nbytes not defined", __func__, 1);
2156 *pnbytes = 0;
2157 if (!sa)
2158 return ERROR_INT("sa not defined", __func__, 1);
2159
2160 /* Read the pdf files into memory */
2161 if ((npages = sarrayGetCount(sa)) == 0)
2162 return ERROR_INT("no filenames found", __func__, 1);
2163 pa_data = ptraCreate(npages);
2164 for (i = 0; i < npages; i++) {
2165 fname = sarrayGetString(sa, i, L_NOCOPY);
2166 bas = l_byteaInitFromFile(fname);
2167 ptraAdd(pa_data, bas);
2168 }
2169
2170 ret = ptraConcatenatePdfToData(pa_data, sa, pdata, pnbytes);
2171
2172 /* Cleanup: some pages could have been removed */
2173 ptraGetActualCount(pa_data, &npages);
2174 for (i = 0; i < npages; i++) {
2175 bas = (L_BYTEA *)ptraRemove(pa_data, i, L_NO_COMPACTION);
2176 l_byteaDestroy(&bas);
2177 }
2178 ptraDestroy(&pa_data, FALSE, FALSE);
2179 return ret;
2180}
2181
2182/* --------------------------------------------*/
2183#endif /* USE_PDFIO */
2184/* --------------------------------------------*/
struct L_Bytea L_BYTEA
Definition array.h:84
struct Sarray SARRAY
Definition array.h:81
@ L_FIRST_IMAGE
Definition imageio.h:208
@ L_NEXT_IMAGE
Definition imageio.h:209
@ L_LAST_IMAGE
Definition imageio.h:210
@ L_DEFAULT_ENCODE
Definition imageio.h:158
@ L_FLATE_ENCODE
Definition imageio.h:161
@ L_G4_ENCODE
Definition imageio.h:160
@ L_JP2K_ENCODE
Definition imageio.h:162
@ L_JPEG_ENCODE
Definition imageio.h:159
l_ok concatenatePdf(const char *dirname, const char *substr, const char *fileout)
concatenatePdf()
Definition pdfio1.c:1993
l_ok concatenatePdfToData(const char *dirname, const char *substr, l_uint8 **pdata, size_t *pnbytes)
concatenatePdfToData()
Definition pdfio1.c:2103
l_ok saConvertFilesToPdf(SARRAY *sa, l_int32 res, l_float32 scalefactor, l_int32 type, l_int32 quality, const char *title, const char *fileout)
saConvertFilesToPdf()
Definition pdfio1.c:299
l_ok convertUnscaledFilesToPdf(const char *dirname, const char *substr, const char *title, const char *fileout)
convertUnscaledFilesToPdf()
Definition pdfio1.c:527
l_ok pixWriteMemPdf(l_uint8 **pdata, size_t *pnbytes, PIX *pix, l_int32 res, const char *title)
pixWriteMemPdf()
Definition pdfio1.c:1351
l_ok convertToPdf(const char *filein, l_int32 type, l_int32 quality, const char *fileout, l_int32 x, l_int32 y, l_int32 res, const char *title, L_PDF_DATA **plpd, l_int32 position)
convertToPdf()
Definition pdfio1.c:969
l_ok saConvertFilesToPdfData(SARRAY *sa, l_int32 res, l_float32 scalefactor, l_int32 type, l_int32 quality, const char *title, l_uint8 **pdata, size_t *pnbytes)
saConvertFilesToPdfData()
Definition pdfio1.c:351
l_ok convertToPdfData(const char *filein, l_int32 type, l_int32 quality, l_uint8 **pdata, size_t *pnbytes, l_int32 x, l_int32 y, l_int32 res, const char *title, L_PDF_DATA **plpd, l_int32 position)
convertToPdfData()
Definition pdfio1.c:1106
l_ok ptraConcatenatePdf(L_PTRA *pa, const char *fileout)
ptraConcatenatePdf()
Definition pdfio1.c:2060
l_ok convertSegmentedFilesToPdf(const char *dirname, const char *substr, l_int32 res, l_int32 type, l_int32 thresh, BOXAA *baa, l_int32 quality, l_float32 scalefactor, const char *title, const char *fileout)
convertSegmentedFilesToPdf()
Definition pdfio1.c:1422
l_ok pixaConvertToPdfData(PIXA *pixa, l_int32 res, l_float32 scalefactor, l_int32 type, l_int32 quality, const char *title, l_uint8 **pdata, size_t *pnbytes)
pixaConvertToPdfData()
Definition pdfio1.c:808
l_ok saConcatenatePdfToData(SARRAY *sa, l_uint8 **pdata, size_t *pnbytes)
saConcatenatePdfToData()
Definition pdfio1.c:2142
l_ok pixConvertToPdf(PIX *pix, l_int32 type, l_int32 quality, const char *fileout, l_int32 x, l_int32 y, l_int32 res, const char *title, L_PDF_DATA **plpd, l_int32 position)
pixConvertToPdf()
Definition pdfio1.c:1248
l_ok convertToPdfSegmented(const char *filein, l_int32 res, l_int32 type, l_int32 thresh, BOXA *boxa, l_int32 quality, l_float32 scalefactor, const char *title, const char *fileout)
convertToPdfSegmented()
Definition pdfio1.c:1647
l_ok pixaConvertToPdf(PIXA *pixa, l_int32 res, l_float32 scalefactor, l_int32 type, l_int32 quality, const char *title, const char *fileout)
pixaConvertToPdf()
Definition pdfio1.c:756
l_ok convertImageDataToPdf(l_uint8 *imdata, size_t size, l_int32 type, l_int32 quality, const char *fileout, l_int32 x, l_int32 y, l_int32 res, const char *title, L_PDF_DATA **plpd, l_int32 position)
convertImageDataToPdf()
Definition pdfio1.c:1039
l_ok pixWriteStreamPdf(FILE *fp, PIX *pix, l_int32 res, const char *title)
pixWriteStreamPdf()
Definition pdfio1.c:1305
l_ok convertImageDataToPdfData(l_uint8 *imdata, size_t size, l_int32 type, l_int32 quality, l_uint8 **pdata, size_t *pnbytes, l_int32 x, l_int32 y, l_int32 res, const char *title, L_PDF_DATA **plpd, l_int32 position)
convertImageDataToPdfData()
Definition pdfio1.c:1172
l_ok saConvertUnscaledFilesToPdf(SARRAY *sa, const char *title, const char *fileout)
saConvertUnscaledFilesToPdf()
Definition pdfio1.c:562
l_ok convertToPdfDataSegmented(const char *filein, l_int32 res, l_int32 type, l_int32 thresh, BOXA *boxa, l_int32 quality, l_float32 scalefactor, const char *title, l_uint8 **pdata, size_t *pnbytes)
convertToPdfDataSegmented()
Definition pdfio1.c:1766
l_ok convertUnscaledToPdfData(const char *fname, const char *title, l_uint8 **pdata, size_t *pnbytes)
convertUnscaledToPdfData()
Definition pdfio1.c:681
l_ok saConcatenatePdf(SARRAY *sa, const char *fileout)
saConcatenatePdf()
Definition pdfio1.c:2026
l_ok pixConvertToPdfSegmented(PIX *pixs, l_int32 res, l_int32 type, l_int32 thresh, BOXA *boxa, l_int32 quality, l_float32 scalefactor, const char *title, const char *fileout)
pixConvertToPdfSegmented()
Definition pdfio1.c:1704
l_ok selectDefaultPdfEncoding(PIX *pix, l_int32 *ptype)
selectDefaultPdfEncoding()
Definition pdfio1.c:464
l_ok convertFilesToPdf(const char *dirname, const char *substr, l_int32 res, l_float32 scalefactor, l_int32 type, l_int32 quality, const char *title, const char *fileout)
convertFilesToPdf()
Definition pdfio1.c:252
l_ok saConvertUnscaledFilesToPdfData(SARRAY *sa, const char *title, l_uint8 **pdata, size_t *pnbytes)
saConvertUnscaledFilesToPdfData()
Definition pdfio1.c:604
l_ok pixConvertToPdfDataSegmented(PIX *pixs, l_int32 res, l_int32 type, l_int32 thresh, BOXA *boxa, l_int32 quality, l_float32 scalefactor, const char *title, l_uint8 **pdata, size_t *pnbytes)
pixConvertToPdfDataSegmented()
Definition pdfio1.c:1830
BOXAA * convertNumberedMasksToBoxaa(const char *dirname, const char *substr, l_int32 numpre, l_int32 numpost)
convertNumberedMasksToBoxaa()
Definition pdfio1.c:1540
@ REMOVE_CMAP_TO_GRAYSCALE
Definition pix.h:381
@ REMOVE_CMAP_BASED_ON_SRC
Definition pix.h:384
@ L_CLONE
Definition pix.h:506
@ L_NOCOPY
Definition pix.h:503
@ L_SET_WHITE
Definition pix.h:699
struct Pix PIX
Definition pix.h:228
struct Box BOX
Definition pix.h:252
#define PIX_SRC
Definition pix.h:444
struct PixColormap PIXCMAP
Definition pix.h:231
struct Pixa PIXA
Definition pix.h:243
struct Boxa BOXA
Definition pix.h:255
struct Boxaa BOXAA
Definition pix.h:258
@ L_NO_COMPACTION
Definition ptra.h:79