Leptonica 1.85.0
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
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
466l_ok
468 l_int32 *ptype)
469{
470l_int32 w, h, d, factor, ncolors;
471PIXCMAP *cmap;
472
473 if (!ptype)
474 return ERROR_INT("&type not defined", __func__, 1);
475 *ptype = L_FLATE_ENCODE; /* default universal encoding */
476 if (!pix)
477 return ERROR_INT("pix not defined", __func__, 1);
478 pixGetDimensions(pix, &w, &h, &d);
479 cmap = pixGetColormap(pix);
480 if (d == 8 && !cmap) {
481 factor = L_MAX(1, (l_int32)sqrt((l_float64)(w * h) / 20000.));
482 pixNumColors(pix, factor, &ncolors);
483 if (ncolors < 20)
484 *ptype = L_FLATE_ENCODE;
485 else
486 *ptype = L_JPEG_ENCODE;
487 } else if (d == 1) {
488 *ptype = L_G4_ENCODE;
489 } else if (cmap || d == 2 || d == 4) {
490 *ptype = L_FLATE_ENCODE;
491 } else if (d == 8 || d == 32) {
492 *ptype = L_JPEG_ENCODE;
493 } else if (d == 16) {
494 *ptype = L_FLATE_ENCODE;
495 } else {
496 return ERROR_INT("type selection failure", __func__, 1);
497 }
498
499 return 0;
500}
501
502
503/*---------------------------------------------------------------------*
504 * Convert specified image files to pdf without scaling *
505 *---------------------------------------------------------------------*/
529l_ok
530convertUnscaledFilesToPdf(const char *dirname,
531 const char *substr,
532 const char *title,
533 const char *fileout)
534{
535l_int32 ret;
536SARRAY *sa;
537
538 if (!dirname)
539 return ERROR_INT("dirname not defined", __func__, 1);
540 if (!fileout)
541 return ERROR_INT("fileout not defined", __func__, 1);
542
543 if ((sa = getSortedPathnamesInDirectory(dirname, substr, 0, 0)) == NULL)
544 return ERROR_INT("sa not made", __func__, 1);
545 ret = saConvertUnscaledFilesToPdf(sa, title, fileout);
546 sarrayDestroy(&sa);
547 return ret;
548}
549
550
564l_ok
566 const char *title,
567 const char *fileout)
568{
569l_uint8 *data;
570l_int32 ret;
571size_t nbytes;
572
573 if (!sa)
574 return ERROR_INT("sa not defined", __func__, 1);
575
576 ret = saConvertUnscaledFilesToPdfData(sa, title, &data, &nbytes);
577 if (ret) {
578 if (data) LEPT_FREE(data);
579 return ERROR_INT("pdf data not made", __func__, 1);
580 }
581
582 ret = l_binaryWrite(fileout, "w", data, nbytes);
583 LEPT_FREE(data);
584 if (ret)
585 L_ERROR("pdf data not written to file\n", __func__);
586 return ret;
587}
588
589
606l_ok
608 const char *title,
609 l_uint8 **pdata,
610 size_t *pnbytes)
611{
612char *fname;
613l_uint8 *imdata;
614l_int32 i, n, ret, npages;
615size_t imbytes;
616L_BYTEA *ba;
617L_PTRA *pa_data;
618
619 if (!pdata)
620 return ERROR_INT("&data not defined", __func__, 1);
621 *pdata = NULL;
622 if (!pnbytes)
623 return ERROR_INT("&nbytes not defined", __func__, 1);
624 *pnbytes = 0;
625 if (!sa)
626 return ERROR_INT("sa not defined", __func__, 1);
627
628 /* Generate all the encoded pdf strings */
629 n = sarrayGetCount(sa);
630 pa_data = ptraCreate(n);
631 for (i = 0; i < n; i++) {
632 if (i && (i % 10 == 0)) lept_stderr(".. %d ", i);
633 fname = sarrayGetString(sa, i, L_NOCOPY);
634
635 /* Generate the pdf data */
636 if (convertUnscaledToPdfData(fname, title, &imdata, &imbytes))
637 continue;
638
639 /* ... and add it to the array of single page data */
640 ba = l_byteaInitFromMem(imdata, imbytes);
641 if (imdata) LEPT_FREE(imdata);
642 ptraAdd(pa_data, ba);
643 }
644 ptraGetActualCount(pa_data, &npages);
645 if (npages == 0) {
646 L_ERROR("no pdf files made\n", __func__);
647 ptraDestroy(&pa_data, FALSE, FALSE);
648 return 1;
649 }
650
651 /* Concatenate to generate a multipage pdf */
652 lept_stderr("\nconcatenating ... ");
653 ret = ptraConcatenatePdfToData(pa_data, NULL, pdata, pnbytes);
654 lept_stderr("done\n");
655
656 /* Clean up */
657 ptraGetActualCount(pa_data, &npages); /* maybe failed to read some files */
658 for (i = 0; i < npages; i++) {
659 ba = (L_BYTEA *)ptraRemove(pa_data, i, L_NO_COMPACTION);
660 l_byteaDestroy(&ba);
661 }
662 ptraDestroy(&pa_data, FALSE, FALSE);
663 return ret;
664}
665
666
683l_ok
684convertUnscaledToPdfData(const char *fname,
685 const char *title,
686 l_uint8 **pdata,
687 size_t *pnbytes)
688{
689l_int32 format;
690L_COMP_DATA *cid;
691
692 if (!pdata)
693 return ERROR_INT("&data not defined", __func__, 1);
694 *pdata = NULL;
695 if (!pnbytes)
696 return ERROR_INT("&nbytes not defined", __func__, 1);
697 *pnbytes = 0;
698 if (!fname)
699 return ERROR_INT("fname not defined", __func__, 1);
700
701 findFileFormat(fname, &format);
702 if (format == IFF_UNKNOWN) {
703 L_WARNING("file %s format is unknown; skip\n", __func__, fname);
704 return 1;
705 }
706 if (format == IFF_PS || format == IFF_LPDF) {
707 L_WARNING("file %s format is %d; skip\n", __func__, fname, format);
708 return 1;
709 }
710
711 /* Generate the image data required for pdf generation, always
712 * in binary (not ascii85) coding. Note that jpeg, jp2k and some
713 * png files are not transcoded. */
714 l_generateCIDataForPdf(fname, NULL, 0, &cid);
715 if (!cid) {
716 L_ERROR("file %s format is %d; unreadable\n", __func__, fname, format);
717 return 1;
718 }
719
720 /* Generate the pdf string for this page (image). This destroys
721 * the cid by attaching it to an lpd and destroying the lpd. */
722 cidConvertToPdfData(cid, title, pdata, pnbytes);
723 return 0;
724}
725
726
727/*---------------------------------------------------------------------*
728 * Convert multiple images to pdf (one image per page) *
729 *---------------------------------------------------------------------*/
758l_ok
760 l_int32 res,
761 l_float32 scalefactor,
762 l_int32 type,
763 l_int32 quality,
764 const char *title,
765 const char *fileout)
766{
767l_uint8 *data;
768l_int32 ret;
769size_t nbytes;
770
771 if (!pixa)
772 return ERROR_INT("pixa not defined", __func__, 1);
773
774 ret = pixaConvertToPdfData(pixa, res, scalefactor, type, quality,
775 title, &data, &nbytes);
776 if (ret) {
777 LEPT_FREE(data);
778 return ERROR_INT("conversion to pdf failed", __func__, 1);
779 }
780
781 ret = l_binaryWrite(fileout, "w", data, nbytes);
782 LEPT_FREE(data);
783 if (ret)
784 L_ERROR("pdf data not written to file\n", __func__);
785 return ret;
786}
787
788
810l_ok
812 l_int32 res,
813 l_float32 scalefactor,
814 l_int32 type,
815 l_int32 quality,
816 const char *title,
817 l_uint8 **pdata,
818 size_t *pnbytes)
819{
820l_uint8 *imdata;
821l_int32 i, n, ret, scaledres, pagetype;
822size_t imbytes;
823L_BYTEA *ba;
824PIX *pixs, *pix;
825L_PTRA *pa_data;
826
827 if (!pdata)
828 return ERROR_INT("&data not defined", __func__, 1);
829 *pdata = NULL;
830 if (!pnbytes)
831 return ERROR_INT("&nbytes not defined", __func__, 1);
832 *pnbytes = 0;
833 if (!pixa)
834 return ERROR_INT("pixa not defined", __func__, 1);
835 if (scalefactor <= 0.0) scalefactor = 1.0;
836 if (scalefactor >= 50.0)
837 return ERROR_INT("scalefactor too large", __func__, 1);
838 if (type != L_DEFAULT_ENCODE && type != L_JPEG_ENCODE &&
839 type != L_G4_ENCODE && type != L_FLATE_ENCODE &&
840 type != L_JP2K_ENCODE) {
841 L_WARNING("invalid compression type; using per-page default\n",
842 __func__);
843 type = L_DEFAULT_ENCODE;
844 }
845 if (quality < 0 || quality > 100)
846 return ERROR_INT("invalid quality", __func__, 1);
847
848 /* Generate all the encoded pdf strings */
849 n = pixaGetCount(pixa);
850 pa_data = ptraCreate(n);
851 for (i = 0; i < n; i++) {
852 if ((pixs = pixaGetPix(pixa, i, L_CLONE)) == NULL) {
853 L_ERROR("pixs[%d] not retrieved\n", __func__, i);
854 continue;
855 }
856 if (scalefactor != 1.0)
857 pix = pixScale(pixs, scalefactor, scalefactor);
858 else
859 pix = pixClone(pixs);
860 pixDestroy(&pixs);
861 if (!pix) {
862 L_ERROR("pix[%d] not made\n", __func__, i);
863 continue;
864 }
865 scaledres = (l_int32)(res * scalefactor);
866
867 /* Select the encoding type */
868 if (type != L_DEFAULT_ENCODE) {
869 pagetype = type;
870 } else if (selectDefaultPdfEncoding(pix, &pagetype) != 0) {
871 L_ERROR("encoding type selection failed for pix[%d]\n",
872 __func__, i);
873 pixDestroy(&pix);
874 continue;
875 }
876
877 ret = pixConvertToPdfData(pix, pagetype, quality, &imdata, &imbytes,
878 0, 0, scaledres, title, NULL, 0);
879 pixDestroy(&pix);
880 if (ret) {
881 LEPT_FREE(imdata);
882 L_ERROR("pdf encoding failed for pix[%d]\n", __func__, i);
883 continue;
884 }
885 ba = l_byteaInitFromMem(imdata, imbytes);
886 LEPT_FREE(imdata);
887 ptraAdd(pa_data, ba);
888 }
889 ptraGetActualCount(pa_data, &n);
890 if (n == 0) {
891 L_ERROR("no pdf files made\n", __func__);
892 ptraDestroy(&pa_data, FALSE, FALSE);
893 return 1;
894 }
895
896 /* Concatenate them */
897 ret = ptraConcatenatePdfToData(pa_data, NULL, pdata, pnbytes);
898
899 ptraGetActualCount(pa_data, &n); /* recalculate in case it changes */
900 for (i = 0; i < n; i++) {
901 ba = (L_BYTEA *)ptraRemove(pa_data, i, L_NO_COMPACTION);
902 l_byteaDestroy(&ba);
903 }
904 ptraDestroy(&pa_data, FALSE, FALSE);
905 return ret;
906}
907
908
909/*---------------------------------------------------------------------*
910 * Single page, multi-image converters *
911 *---------------------------------------------------------------------*/
971l_ok
972convertToPdf(const char *filein,
973 l_int32 type,
974 l_int32 quality,
975 const char *fileout,
976 l_int32 x,
977 l_int32 y,
978 l_int32 res,
979 const char *title,
980 L_PDF_DATA **plpd,
981 l_int32 position)
982{
983l_uint8 *data;
984l_int32 ret;
985size_t nbytes;
986
987 if (!filein)
988 return ERROR_INT("filein not defined", __func__, 1);
989 if (!plpd || (position == L_LAST_IMAGE)) {
990 if (!fileout)
991 return ERROR_INT("fileout not defined", __func__, 1);
992 }
993
994 if (convertToPdfData(filein, type, quality, &data, &nbytes, x, y,
995 res, title, plpd, position))
996 return ERROR_INT("pdf data not made", __func__, 1);
997
998 if (!plpd || (position == L_LAST_IMAGE)) {
999 ret = l_binaryWrite(fileout, "w", data, nbytes);
1000 LEPT_FREE(data);
1001 if (ret)
1002 return ERROR_INT("pdf data not written to file", __func__, 1);
1003 }
1004
1005 return 0;
1006}
1007
1008
1041l_ok
1043 size_t size,
1044 l_int32 type,
1045 l_int32 quality,
1046 const char *fileout,
1047 l_int32 x,
1048 l_int32 y,
1049 l_int32 res,
1050 const char *title,
1051 L_PDF_DATA **plpd,
1052 l_int32 position)
1053{
1054l_int32 ret;
1055PIX *pix;
1056
1057 if (!imdata)
1058 return ERROR_INT("image data not defined", __func__, 1);
1059 if (!plpd || (position == L_LAST_IMAGE)) {
1060 if (!fileout)
1061 return ERROR_INT("fileout not defined", __func__, 1);
1062 }
1063
1064 if ((pix = pixReadMem(imdata, size)) == NULL)
1065 return ERROR_INT("pix not read", __func__, 1);
1066 if (type != L_JPEG_ENCODE && type != L_G4_ENCODE &&
1067 type != L_FLATE_ENCODE && type != L_JP2K_ENCODE) {
1068 selectDefaultPdfEncoding(pix, &type);
1069 }
1070 ret = pixConvertToPdf(pix, type, quality, fileout, x, y, res,
1071 title, plpd, position);
1072 pixDestroy(&pix);
1073 return ret;
1074}
1075
1076
1108l_ok
1109convertToPdfData(const char *filein,
1110 l_int32 type,
1111 l_int32 quality,
1112 l_uint8 **pdata,
1113 size_t *pnbytes,
1114 l_int32 x,
1115 l_int32 y,
1116 l_int32 res,
1117 const char *title,
1118 L_PDF_DATA **plpd,
1119 l_int32 position)
1120{
1121PIX *pix;
1122
1123 if (!pdata)
1124 return ERROR_INT("&data not defined", __func__, 1);
1125 *pdata = NULL;
1126 if (!pnbytes)
1127 return ERROR_INT("&nbytes not defined", __func__, 1);
1128 *pnbytes = 0;
1129 if (!filein)
1130 return ERROR_INT("filein not defined", __func__, 1);
1131
1132 if ((pix = pixRead(filein)) == NULL)
1133 return ERROR_INT("pix not made", __func__, 1);
1134
1135 pixConvertToPdfData(pix, type, quality, pdata, pnbytes,
1136 x, y, res, title, plpd, position);
1137 pixDestroy(&pix);
1138 return 0;
1139}
1140
1141
1174l_ok
1176 size_t size,
1177 l_int32 type,
1178 l_int32 quality,
1179 l_uint8 **pdata,
1180 size_t *pnbytes,
1181 l_int32 x,
1182 l_int32 y,
1183 l_int32 res,
1184 const char *title,
1185 L_PDF_DATA **plpd,
1186 l_int32 position)
1187{
1188l_int32 ret;
1189PIX *pix;
1190
1191 if (!pdata)
1192 return ERROR_INT("&data not defined", __func__, 1);
1193 *pdata = NULL;
1194 if (!pnbytes)
1195 return ERROR_INT("&nbytes not defined", __func__, 1);
1196 *pnbytes = 0;
1197 if (!imdata)
1198 return ERROR_INT("image data not defined", __func__, 1);
1199 if (plpd) { /* part of multi-page invocation */
1200 if (position == L_FIRST_IMAGE)
1201 *plpd = NULL;
1202 }
1203
1204 if ((pix = pixReadMem(imdata, size)) == NULL)
1205 return ERROR_INT("pix not read", __func__, 1);
1206 if (type != L_JPEG_ENCODE && type != L_G4_ENCODE &&
1207 type != L_FLATE_ENCODE && type != L_JP2K_ENCODE) {
1208 selectDefaultPdfEncoding(pix, &type);
1209 }
1210 ret = pixConvertToPdfData(pix, type, quality, pdata, pnbytes,
1211 x, y, res, title, plpd, position);
1212 pixDestroy(&pix);
1213 return ret;
1214}
1215
1216
1250l_ok
1252 l_int32 type,
1253 l_int32 quality,
1254 const char *fileout,
1255 l_int32 x,
1256 l_int32 y,
1257 l_int32 res,
1258 const char *title,
1259 L_PDF_DATA **plpd,
1260 l_int32 position)
1261{
1262l_uint8 *data;
1263l_int32 ret;
1264size_t nbytes;
1265
1266 if (!pix)
1267 return ERROR_INT("pix not defined", __func__, 1);
1268 if (!plpd || (position == L_LAST_IMAGE)) {
1269 if (!fileout)
1270 return ERROR_INT("fileout not defined", __func__, 1);
1271 }
1272
1273 if (pixConvertToPdfData(pix, type, quality, &data, &nbytes,
1274 x, y, res, title, plpd, position)) {
1275 LEPT_FREE(data);
1276 return ERROR_INT("pdf data not made", __func__, 1);
1277 }
1278
1279 if (!plpd || (position == L_LAST_IMAGE)) {
1280 ret = l_binaryWrite(fileout, "w", data, nbytes);
1281 LEPT_FREE(data);
1282 if (ret)
1283 return ERROR_INT("pdf data not written to file", __func__, 1);
1284 }
1285 return 0;
1286}
1287
1288
1307l_ok
1309 PIX *pix,
1310 l_int32 res,
1311 const char *title)
1312{
1313l_uint8 *data;
1314size_t nbytes, nbytes_written;
1315
1316 if (!fp)
1317 return ERROR_INT("stream not opened", __func__, 1);
1318 if (!pix)
1319 return ERROR_INT("pix not defined", __func__, 1);
1320
1321 if (pixWriteMemPdf(&data, &nbytes, pix, res, title) != 0) {
1322 LEPT_FREE(data);
1323 return ERROR_INT("pdf data not made", __func__, 1);
1324 }
1325
1326 nbytes_written = fwrite(data, 1, nbytes, fp);
1327 LEPT_FREE(data);
1328 if (nbytes != nbytes_written)
1329 return ERROR_INT("failure writing pdf data to stream", __func__, 1);
1330 return 0;
1331}
1332
1333
1353l_ok
1354pixWriteMemPdf(l_uint8 **pdata,
1355 size_t *pnbytes,
1356 PIX *pix,
1357 l_int32 res,
1358 const char *title)
1359{
1360l_int32 ret, type;
1361
1362 if (pdata) *pdata = NULL;
1363 if (pnbytes) *pnbytes = 0;
1364 if (!pdata || !pnbytes)
1365 return ERROR_INT("&data or &nbytes not defined", __func__, 1);
1366 if (!pix)
1367 return ERROR_INT("pix not defined", __func__, 1);
1368
1369 selectDefaultPdfEncoding(pix, &type);
1370 ret = pixConvertToPdfData(pix, type, 75, pdata, pnbytes,
1371 0, 0, res, title, NULL, 0);
1372 if (ret)
1373 return ERROR_INT("pdf data not made", __func__, 1);
1374 return 0;
1375}
1376
1377
1378/*---------------------------------------------------------------------*
1379 * Segmented multi-page, multi-image converter *
1380 *---------------------------------------------------------------------*/
1424l_ok
1425convertSegmentedFilesToPdf(const char *dirname,
1426 const char *substr,
1427 l_int32 res,
1428 l_int32 type,
1429 l_int32 thresh,
1430 BOXAA *baa,
1431 l_int32 quality,
1432 l_float32 scalefactor,
1433 const char *title,
1434 const char *fileout)
1435{
1436char *fname;
1437l_uint8 *imdata, *data;
1438l_int32 i, npages, nboxa, nboxes, ret;
1439size_t imbytes, databytes;
1440BOXA *boxa;
1441L_BYTEA *ba;
1442L_PTRA *pa_data;
1443SARRAY *sa;
1444
1445 if (!dirname)
1446 return ERROR_INT("dirname not defined", __func__, 1);
1447 if (!fileout)
1448 return ERROR_INT("fileout not defined", __func__, 1);
1449
1450 if ((sa = getNumberedPathnamesInDirectory(dirname, substr, 0, 0, 10000))
1451 == NULL)
1452 return ERROR_INT("sa not made", __func__, 1);
1453
1454 npages = sarrayGetCount(sa);
1455 /* If necessary, extend the boxaa, which is page-aligned with
1456 * the image files, to be as large as the set of images. */
1457 if (baa) {
1458 nboxa = boxaaGetCount(baa);
1459 if (nboxa < npages) {
1460 boxa = boxaCreate(1);
1461 boxaaExtendWithInit(baa, npages, boxa);
1462 boxaDestroy(&boxa);
1463 }
1464 }
1465
1466 /* Generate and save all the encoded pdf strings */
1467 pa_data = ptraCreate(npages);
1468 for (i = 0; i < npages; i++) {
1469 fname = sarrayGetString(sa, i, L_NOCOPY);
1470 if (!strcmp(fname, "")) continue;
1471 boxa = NULL;
1472 if (baa) {
1473 boxa = boxaaGetBoxa(baa, i, L_CLONE);
1474 nboxes = boxaGetCount(boxa);
1475 if (nboxes == 0)
1476 boxaDestroy(&boxa);
1477 }
1478 ret = convertToPdfDataSegmented(fname, res, type, thresh, boxa,
1479 quality, scalefactor, title,
1480 &imdata, &imbytes);
1481 boxaDestroy(&boxa); /* safe; in case nboxes > 0 */
1482 if (ret) {
1483 L_ERROR("pdf encoding failed for %s\n", __func__, fname);
1484 continue;
1485 }
1486 ba = l_byteaInitFromMem(imdata, imbytes);
1487 if (imdata) LEPT_FREE(imdata);
1488 ptraAdd(pa_data, ba);
1489 }
1490 sarrayDestroy(&sa);
1491
1492 ptraGetActualCount(pa_data, &npages);
1493 if (npages == 0) {
1494 L_ERROR("no pdf files made\n", __func__);
1495 ptraDestroy(&pa_data, FALSE, FALSE);
1496 return 1;
1497 }
1498
1499 /* Concatenate */
1500 ret = ptraConcatenatePdfToData(pa_data, NULL, &data, &databytes);
1501
1502 /* Clean up */
1503 ptraGetActualCount(pa_data, &npages); /* recalculate in case it changes */
1504 for (i = 0; i < npages; i++) {
1505 ba = (L_BYTEA *)ptraRemove(pa_data, i, L_NO_COMPACTION);
1506 l_byteaDestroy(&ba);
1507 }
1508 ptraDestroy(&pa_data, FALSE, FALSE);
1509
1510 if (ret) {
1511 if (data) LEPT_FREE(data);
1512 return ERROR_INT("pdf data not made", __func__, 1);
1513 }
1514
1515 ret = l_binaryWrite(fileout, "w", data, databytes);
1516 LEPT_FREE(data);
1517 if (ret)
1518 L_ERROR("pdf data not written to file\n", __func__);
1519 return ret;
1520}
1521
1522
1542BOXAA *
1544 const char *substr,
1545 l_int32 numpre,
1546 l_int32 numpost)
1547{
1548char *fname;
1549l_int32 i, n;
1550BOXA *boxa;
1551BOXAA *baa;
1552PIX *pix;
1553SARRAY *sa;
1554
1555 if (!dirname)
1556 return (BOXAA *)ERROR_PTR("dirname not defined", __func__, NULL);
1557
1558 if ((sa = getNumberedPathnamesInDirectory(dirname, substr, numpre,
1559 numpost, 10000)) == NULL)
1560 return (BOXAA *)ERROR_PTR("sa not made", __func__, NULL);
1561
1562 /* Generate and save all the encoded pdf strings */
1563 n = sarrayGetCount(sa);
1564 baa = boxaaCreate(n);
1565 boxa = boxaCreate(1);
1566 boxaaInitFull(baa, boxa);
1567 boxaDestroy(&boxa);
1568 for (i = 0; i < n; i++) {
1569 fname = sarrayGetString(sa, i, L_NOCOPY);
1570 if (!strcmp(fname, "")) continue;
1571 if ((pix = pixRead(fname)) == NULL) {
1572 L_WARNING("invalid image on page %d\n", __func__, i);
1573 continue;
1574 }
1575 boxa = pixConnComp(pix, NULL, 8);
1576 boxaaReplaceBoxa(baa, i, boxa);
1577 pixDestroy(&pix);
1578 }
1579
1580 sarrayDestroy(&sa);
1581 return baa;
1582}
1583
1584
1585/*---------------------------------------------------------------------*
1586 * Segmented single page, multi-image converters *
1587 *---------------------------------------------------------------------*/
1649l_ok
1650convertToPdfSegmented(const char *filein,
1651 l_int32 res,
1652 l_int32 type,
1653 l_int32 thresh,
1654 BOXA *boxa,
1655 l_int32 quality,
1656 l_float32 scalefactor,
1657 const char *title,
1658 const char *fileout)
1659{
1660l_int32 ret;
1661PIX *pixs;
1662
1663 if (!filein)
1664 return ERROR_INT("filein not defined", __func__, 1);
1665 if (!fileout)
1666 return ERROR_INT("fileout not defined", __func__, 1);
1667 if (type != L_G4_ENCODE && type != L_JPEG_ENCODE &&
1668 type != L_FLATE_ENCODE)
1669 return ERROR_INT("invalid conversion type", __func__, 1);
1670 if (boxa && scalefactor > 1.0) {
1671 L_WARNING("setting scalefactor to 1.0\n", __func__);
1672 scalefactor = 1.0;
1673 }
1674
1675 if ((pixs = pixRead(filein)) == NULL)
1676 return ERROR_INT("pixs not made", __func__, 1);
1677
1678 ret = pixConvertToPdfSegmented(pixs, res, type, thresh, boxa, quality,
1679 scalefactor, title, fileout);
1680 pixDestroy(&pixs);
1681 return ret;
1682}
1683
1684
1706l_ok
1708 l_int32 res,
1709 l_int32 type,
1710 l_int32 thresh,
1711 BOXA *boxa,
1712 l_int32 quality,
1713 l_float32 scalefactor,
1714 const char *title,
1715 const char *fileout)
1716{
1717l_uint8 *data;
1718l_int32 ret;
1719size_t nbytes;
1720
1721 if (!pixs)
1722 return ERROR_INT("pixs not defined", __func__, 1);
1723 if (!fileout)
1724 return ERROR_INT("fileout not defined", __func__, 1);
1725 if (type != L_G4_ENCODE && type != L_JPEG_ENCODE &&
1726 type != L_FLATE_ENCODE)
1727 return ERROR_INT("invalid conversion type", __func__, 1);
1728 if (boxa && scalefactor > 1.0) {
1729 L_WARNING("setting scalefactor to 1.0\n", __func__);
1730 scalefactor = 1.0;
1731 }
1732
1733 ret = pixConvertToPdfDataSegmented(pixs, res, type, thresh, boxa, quality,
1734 scalefactor, title, &data, &nbytes);
1735 if (ret)
1736 return ERROR_INT("pdf generation failure", __func__, 1);
1737
1738 ret = l_binaryWrite(fileout, "w", data, nbytes);
1739 if (data) LEPT_FREE(data);
1740 return ret;
1741}
1742
1743
1768l_ok
1769convertToPdfDataSegmented(const char *filein,
1770 l_int32 res,
1771 l_int32 type,
1772 l_int32 thresh,
1773 BOXA *boxa,
1774 l_int32 quality,
1775 l_float32 scalefactor,
1776 const char *title,
1777 l_uint8 **pdata,
1778 size_t *pnbytes)
1779{
1780l_int32 ret;
1781PIX *pixs;
1782
1783 if (!pdata)
1784 return ERROR_INT("&data not defined", __func__, 1);
1785 *pdata = NULL;
1786 if (!pnbytes)
1787 return ERROR_INT("&nbytes not defined", __func__, 1);
1788 *pnbytes = 0;
1789 if (!filein)
1790 return ERROR_INT("filein not defined", __func__, 1);
1791 if (type != L_G4_ENCODE && type != L_JPEG_ENCODE &&
1792 type != L_FLATE_ENCODE)
1793 return ERROR_INT("invalid conversion type", __func__, 1);
1794 if (boxa && scalefactor > 1.0) {
1795 L_WARNING("setting scalefactor to 1.0\n", __func__);
1796 scalefactor = 1.0;
1797 }
1798
1799 if ((pixs = pixRead(filein)) == NULL)
1800 return ERROR_INT("pixs not made", __func__, 1);
1801
1802 ret = pixConvertToPdfDataSegmented(pixs, res, type, thresh, boxa,
1803 quality, scalefactor, title,
1804 pdata, pnbytes);
1805 pixDestroy(&pixs);
1806 return ret;
1807}
1808
1809
1832l_ok
1834 l_int32 res,
1835 l_int32 type,
1836 l_int32 thresh,
1837 BOXA *boxa,
1838 l_int32 quality,
1839 l_float32 scalefactor,
1840 const char *title,
1841 l_uint8 **pdata,
1842 size_t *pnbytes)
1843{
1844l_int32 i, nbox, seq, bx, by, bw, bh, upscale;
1845l_float32 scale;
1846BOX *box, *boxc, *box2;
1847PIX *pix, *pixt1, *pixt2, *pixt3, *pixt4, *pixt5, *pixt6;
1848PIXCMAP *cmap;
1849L_PDF_DATA *lpd;
1850
1851 if (!pdata)
1852 return ERROR_INT("&data not defined", __func__, 1);
1853 *pdata = NULL;
1854 if (!pnbytes)
1855 return ERROR_INT("&nbytes not defined", __func__, 1);
1856 *pnbytes = 0;
1857 if (!pixs)
1858 return ERROR_INT("pixs not defined", __func__, 1);
1859 if (type != L_G4_ENCODE && type != L_JPEG_ENCODE &&
1860 type != L_FLATE_ENCODE)
1861 return ERROR_INT("invalid conversion type", __func__, 1);
1862 if (boxa && (scalefactor <= 0.0 || scalefactor > 1.0)) {
1863 L_WARNING("setting scalefactor to 1.0\n", __func__);
1864 scalefactor = 1.0;
1865 }
1866
1867 /* Adjust scalefactor so that the product with res gives an integer */
1868 if (res <= 0)
1869 res = DefaultInputRes;
1870 scale = (l_float32)((l_int32)(scalefactor * res + 0.5)) / (l_float32)res;
1871 cmap = pixGetColormap(pixs);
1872
1873 /* Simple case: single image to be encoded */
1874 if (!boxa || boxaGetCount(boxa) == 0) {
1875 if (pixGetDepth(pixs) > 1 && type == L_G4_ENCODE) {
1876 if (cmap)
1877 pixt1 = pixRemoveColormap(pixs, REMOVE_CMAP_TO_GRAYSCALE);
1878 else
1879 pixt1 = pixConvertTo8(pixs, FALSE);
1880 pixt2 = pixScaleGray2xLIThresh(pixt1, thresh);
1881 pixConvertToPdfData(pixt2, type, quality, pdata, pnbytes,
1882 0, 0, 2 * res, title, NULL, 0);
1883 pixDestroy(&pixt1);
1884 pixDestroy(&pixt2);
1885 } else {
1886 pixConvertToPdfData(pixs, type, quality, pdata, pnbytes,
1887 0, 0, res, title, NULL, 0);
1888 }
1889 return 0;
1890 }
1891
1892 /* Multiple images to be encoded. If %type == L_G4_ENCODE,
1893 * jpeg encode a version of pixs that is blanked in the non-image
1894 * regions, and paint the scaled non-image part onto it through a mask.
1895 * Otherwise, we must put the non-image part down first and
1896 * then render all the image regions separately on top of it,
1897 * at their own resolution. */
1898 pixt1 = pixSetBlackOrWhiteBoxa(pixs, boxa, L_SET_WHITE); /* non-image */
1899 nbox = boxaGetCount(boxa);
1900 if (type == L_G4_ENCODE) {
1901 pixt2 = pixCreateTemplate(pixs); /* only image regions */
1902 pixSetBlackOrWhite(pixt2, L_SET_WHITE);
1903 for (i = 0; i < nbox; i++) {
1904 box = boxaGetBox(boxa, i, L_CLONE);
1905 pix = pixClipRectangle(pixs, box, &boxc);
1906 boxGetGeometry(boxc, &bx, &by, &bw, &bh);
1907 pixRasterop(pixt2, bx, by, bw, bh, PIX_SRC, pix, 0, 0);
1908 pixDestroy(&pix);
1909 boxDestroy(&box);
1910 boxDestroy(&boxc);
1911 }
1912 pixt3 = pixRemoveColormap(pixt2, REMOVE_CMAP_BASED_ON_SRC);
1913 if (pixGetDepth(pixt3) == 1)
1914 pixt4 = pixScaleToGray(pixt3, scale);
1915 else
1916 pixt4 = pixScale(pixt3, scale, scale);
1917 pixConvertToPdfData(pixt4, L_JPEG_ENCODE, quality, pdata, pnbytes,
1918 0, 0, (l_int32)(scale * res), title,
1919 &lpd, L_FIRST_IMAGE);
1920
1921 if (pixGetDepth(pixt1) == 1) {
1922 pixt5 = pixClone(pixt1);
1923 upscale = 1;
1924 } else {
1925 pixt6 = pixConvertTo8(pixt1, 0);
1926 pixt5 = pixScaleGray2xLIThresh(pixt6, thresh);
1927 pixDestroy(&pixt6);
1928 upscale = 2;
1929 }
1930 pixConvertToPdfData(pixt5, L_G4_ENCODE, quality, pdata, pnbytes,
1931 0, 0, upscale * res, title, &lpd, L_LAST_IMAGE);
1932 pixDestroy(&pixt2);
1933 pixDestroy(&pixt3);
1934 pixDestroy(&pixt4);
1935 pixDestroy(&pixt5);
1936 } else {
1937 /* Put the non-image part down first. This is the full
1938 size of the page, so we can use it to find the page
1939 height in pixels, which is required for determining
1940 the LL corner of the image relative to the LL corner
1941 of the page. */
1942 pixConvertToPdfData(pixt1, type, quality, pdata, pnbytes, 0, 0,
1943 res, title, &lpd, L_FIRST_IMAGE);
1944 for (i = 0; i < nbox; i++) {
1945 box = boxaGetBox(boxa, i, L_CLONE);
1946 pixt2 = pixClipRectangle(pixs, box, &boxc);
1947 pixt3 = pixRemoveColormap(pixt2, REMOVE_CMAP_BASED_ON_SRC);
1948 if (pixGetDepth(pixt3) == 1)
1949 pixt4 = pixScaleToGray(pixt3, scale);
1950 else
1951 pixt4 = pixScale(pixt3, scale, scale);
1952 box2 = boxTransform(boxc, 0, 0, scale, scale);
1953 boxGetGeometry(box2, &bx, &by, NULL, &bh);
1954 seq = (i == nbox - 1) ? L_LAST_IMAGE : L_NEXT_IMAGE;
1955 pixConvertToPdfData(pixt4, L_JPEG_ENCODE, quality, pdata, pnbytes,
1956 bx, by, (l_int32)(scale * res), title,
1957 &lpd, seq);
1958 pixDestroy(&pixt2);
1959 pixDestroy(&pixt3);
1960 pixDestroy(&pixt4);
1961 boxDestroy(&box);
1962 boxDestroy(&boxc);
1963 boxDestroy(&box2);
1964 }
1965 }
1966
1967 pixDestroy(&pixt1);
1968 return 0;
1969}
1970
1971
1972/*---------------------------------------------------------------------*
1973 * Multi-page concatenation *
1974 *---------------------------------------------------------------------*/
1995l_ok
1996concatenatePdf(const char *dirname,
1997 const char *substr,
1998 const char *fileout)
1999{
2000l_int32 ret;
2001SARRAY *sa;
2002
2003 if (!dirname)
2004 return ERROR_INT("dirname not defined", __func__, 1);
2005 if (!fileout)
2006 return ERROR_INT("fileout not defined", __func__, 1);
2007
2008 if ((sa = getSortedPathnamesInDirectory(dirname, substr, 0, 0)) == NULL)
2009 return ERROR_INT("sa not made", __func__, 1);
2010 ret = saConcatenatePdf(sa, fileout);
2011 sarrayDestroy(&sa);
2012 return ret;
2013}
2014
2015
2028l_ok
2030 const char *fileout)
2031{
2032l_uint8 *data;
2033l_int32 ret;
2034size_t nbytes;
2035
2036 if (!sa)
2037 return ERROR_INT("sa not defined", __func__, 1);
2038 if (!fileout)
2039 return ERROR_INT("fileout not defined", __func__, 1);
2040
2041 ret = saConcatenatePdfToData(sa, &data, &nbytes);
2042 if (ret)
2043 return ERROR_INT("pdf data not made", __func__, 1);
2044 ret = l_binaryWrite(fileout, "w", data, nbytes);
2045 LEPT_FREE(data);
2046 return ret;
2047}
2048
2049
2062l_ok
2064 const char *fileout)
2065{
2066l_uint8 *data;
2067l_int32 ret;
2068size_t nbytes;
2069
2070 if (!pa)
2071 return ERROR_INT("pa not defined", __func__, 1);
2072 if (!fileout)
2073 return ERROR_INT("fileout not defined", __func__, 1);
2074
2075 ret = ptraConcatenatePdfToData(pa, NULL, &data, &nbytes);
2076 if (ret)
2077 return ERROR_INT("pdf data not made", __func__, 1);
2078 ret = l_binaryWrite(fileout, "w", data, nbytes);
2079 LEPT_FREE(data);
2080 return ret;
2081}
2082
2083
2105l_ok
2106concatenatePdfToData(const char *dirname,
2107 const char *substr,
2108 l_uint8 **pdata,
2109 size_t *pnbytes)
2110{
2111l_int32 ret;
2112SARRAY *sa;
2113
2114 if (!pdata)
2115 return ERROR_INT("&data not defined", __func__, 1);
2116 *pdata = NULL;
2117 if (!pnbytes)
2118 return ERROR_INT("&nbytes not defined", __func__, 1);
2119 *pnbytes = 0;
2120 if (!dirname)
2121 return ERROR_INT("dirname not defined", __func__, 1);
2122
2123 if ((sa = getSortedPathnamesInDirectory(dirname, substr, 0, 0)) == NULL)
2124 return ERROR_INT("sa not made", __func__, 1);
2125 ret = saConcatenatePdfToData(sa, pdata, pnbytes);
2126 sarrayDestroy(&sa);
2127 return ret;
2128}
2129
2130
2144l_ok
2146 l_uint8 **pdata,
2147 size_t *pnbytes)
2148{
2149char *fname;
2150l_int32 i, npages, ret;
2151L_BYTEA *bas;
2152L_PTRA *pa_data; /* input pdf data for each page */
2153
2154 if (!pdata)
2155 return ERROR_INT("&data not defined", __func__, 1);
2156 *pdata = NULL;
2157 if (!pnbytes)
2158 return ERROR_INT("&nbytes not defined", __func__, 1);
2159 *pnbytes = 0;
2160 if (!sa)
2161 return ERROR_INT("sa not defined", __func__, 1);
2162
2163 /* Read the pdf files into memory */
2164 if ((npages = sarrayGetCount(sa)) == 0)
2165 return ERROR_INT("no filenames found", __func__, 1);
2166 pa_data = ptraCreate(npages);
2167 for (i = 0; i < npages; i++) {
2168 fname = sarrayGetString(sa, i, L_NOCOPY);
2169 bas = l_byteaInitFromFile(fname);
2170 ptraAdd(pa_data, bas);
2171 }
2172
2173 ret = ptraConcatenatePdfToData(pa_data, sa, pdata, pnbytes);
2174
2175 /* Cleanup: some pages could have been removed */
2176 ptraGetActualCount(pa_data, &npages);
2177 for (i = 0; i < npages; i++) {
2178 bas = (L_BYTEA *)ptraRemove(pa_data, i, L_NO_COMPACTION);
2179 l_byteaDestroy(&bas);
2180 }
2181 ptraDestroy(&pa_data, FALSE, FALSE);
2182 return ret;
2183}
2184
2185/* --------------------------------------------*/
2186#endif /* USE_PDFIO */
2187/* --------------------------------------------*/
@ 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_FIRST_IMAGE
Definition imageio.h:208
@ L_NEXT_IMAGE
Definition imageio.h:209
@ L_LAST_IMAGE
Definition imageio.h:210
l_ok concatenatePdf(const char *dirname, const char *substr, const char *fileout)
concatenatePdf()
Definition pdfio1.c:1996
l_ok concatenatePdfToData(const char *dirname, const char *substr, l_uint8 **pdata, size_t *pnbytes)
concatenatePdfToData()
Definition pdfio1.c:2106
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:530
l_ok pixWriteMemPdf(l_uint8 **pdata, size_t *pnbytes, PIX *pix, l_int32 res, const char *title)
pixWriteMemPdf()
Definition pdfio1.c:1354
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:972
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:1109
l_ok ptraConcatenatePdf(L_PTRA *pa, const char *fileout)
ptraConcatenatePdf()
Definition pdfio1.c:2063
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:1425
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:811
l_ok saConcatenatePdfToData(SARRAY *sa, l_uint8 **pdata, size_t *pnbytes)
saConcatenatePdfToData()
Definition pdfio1.c:2145
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:1251
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:1650
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:759
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:1042
l_ok pixWriteStreamPdf(FILE *fp, PIX *pix, l_int32 res, const char *title)
pixWriteStreamPdf()
Definition pdfio1.c:1308
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:1175
l_ok saConvertUnscaledFilesToPdf(SARRAY *sa, const char *title, const char *fileout)
saConvertUnscaledFilesToPdf()
Definition pdfio1.c:565
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:1769
l_ok convertUnscaledToPdfData(const char *fname, const char *title, l_uint8 **pdata, size_t *pnbytes)
convertUnscaledToPdfData()
Definition pdfio1.c:684
l_ok saConcatenatePdf(SARRAY *sa, const char *fileout)
saConcatenatePdf()
Definition pdfio1.c:2029
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:1707
l_ok selectDefaultPdfEncoding(PIX *pix, l_int32 *ptype)
selectDefaultPdfEncoding()
Definition pdfio1.c:467
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:607
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:1833
BOXAA * convertNumberedMasksToBoxaa(const char *dirname, const char *substr, l_int32 numpre, l_int32 numpost)
convertNumberedMasksToBoxaa()
Definition pdfio1.c:1543
@ 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
#define PIX_SRC
Definition pix.h:444
@ L_NO_COMPACTION
Definition ptra.h:79
Definition ptra.h:54