-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJpeg2PDF.h
72 lines (56 loc) · 2.87 KB
/
Jpeg2PDF.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#ifndef _JPEG2PDF_H_
#define _JPEG2PDF_H_
/* Defined for Compiling on Windows. Might need to be changed for other compiler */
typedef unsigned char UINT8;
typedef unsigned long UINT32;
typedef int STATUS;
#define logMsg printf
#define ERROR 1
#define OK 0
/* */
#ifndef JPEG2PDF_DEBUG
#define JPEG2PDF_DEBUG 0
#endif /* JPEG2PDF_DEBUG */
#define MAX_PDF_PAGES 15256
#define PDF_DOT_PER_INCH 72
#define MAX_PDF_PREFORMAT_SIZE 256 /* Format Before each image, Usually less than 142 Bytes */
#define MAX_PDF_PSTFORMAT_SIZE 512 /* Format After each image, Usually less than 400 Bytes */
struct jpeg2pdf_Node_struct {
struct jpeg2pdf_Node_struct *pNext;
UINT8 *pJpeg;
UINT32 JpegSize;
UINT32 JpegW, JpegH;
UINT32 PageObj;
UINT8 preFormat[MAX_PDF_PREFORMAT_SIZE];
UINT8 pstFormat[MAX_PDF_PSTFORMAT_SIZE];
};
typedef struct jpeg2pdf_Node_struct JPEG2PDF_NODE, *PJPEG2PDF_NODE;
#define XREF_ENTRY_LEN 20 /* Each XREF entry is 20 Bytes */
#define OBJNUM_EXTRA 3 /* First Free Object; Kids Object; Catalog Object */
#define OBJNUM_PER_IMAGE 5
#define MAX_KIDS_STRLEN 10 /* Kids Str Looks Like: "X 0 R ", X = OBJNUM_EXTRA + OBJNUM_PER_IMAGE * (pageNum - 1) */
#define MAX_PDF_XREF (MAX_PDF_PAGES * OBJNUM_PER_IMAGE + OBJNUM_EXTRA)
#define MAX_PDF_HEADER 64 /* PDF Header, Usually less than 40 Bytes */
#define MAX_PDF_TAILER ( ( MAX_PDF_PAGES * (MAX_KIDS_STRLEN + (OBJNUM_PER_IMAGE * XREF_ENTRY_LEN)) ) + (OBJNUM_EXTRA * XREF_ENTRY_LEN) + 256 )
typedef struct {
/* Link List Stuff */
PJPEG2PDF_NODE pFirstNode;
PJPEG2PDF_NODE pLastNode;
UINT32 nodeCount;
/* PDF Stuff */
UINT8 pdfHeader[MAX_PDF_HEADER];
UINT8 pdfTailer[MAX_PDF_TAILER]; /* 28K Bytes */
UINT8 pdfXREF[MAX_PDF_XREF][XREF_ENTRY_LEN + 1]; /* 27K Bytes */
UINT32 pageW, pageH, pdfObj, currentOffSet, imgObj;
double margin;
double maxImgW, maxImgH;
} JPEG2PDF, *PJPEG2PDF;
typedef enum {PageOrientationAuto, Portrait, Landscape} PageOrientation; // specified by user
typedef enum {ScaleFit, ScaleFitWidth, ScaleFitHeight, ScaleReduce, ScaleReduceWidth, ScaleReduceHeight, ScaleNone} ScaleMethod; // specified by user
typedef enum {FitWidth, FitHeight, FitNone} Fit; // how we should actually fit the image
typedef enum {false=0, true} bool;
PJPEG2PDF Jpeg2PDF_BeginDocument(double pdfW, double pdfH, double margin); /* pdfW, pdfH: Page Size in Inch ( 1 inch=25.4 mm ) */
STATUS Jpeg2PDF_AddJpeg(PJPEG2PDF pPDF, UINT32 imgW, UINT32 imgH, UINT32 fileSize, UINT8 *pJpeg, UINT8 isColor, PageOrientation pageOrientation, double dpiX, double dpiY, ScaleMethod scale, bool cropHeight, bool cropWidth);
UINT32 Jpeg2PDF_EndDocument(PJPEG2PDF pPDF, char *timestamp, char* title, char* author, char* keywords, char* subject, char *creator);
STATUS Jpeg2PDF_GetFinalDocumentAndCleanup(PJPEG2PDF pPDF, UINT8 *outPDF, UINT32 *outPDFSize);
#endif /* _JPEG2PDF_H_ */