-
Notifications
You must be signed in to change notification settings - Fork 217
/
HighLevelImages.cpp
141 lines (109 loc) · 4.09 KB
/
HighLevelImages.cpp
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
Source File : TestMeasurementsTest.cpp
Copyright 2011 Gal Kahana PDFWriter
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "PDFWriter.h"
#include "PDFPage.h"
#include "PageContentContext.h"
#include "testing/TestIO.h"
#include <iostream>
using namespace PDFHummus;
int HighLevelImages(int argc, char* argv[])
{
EStatusCode status = eSuccess;
PDFWriter pdfWriter;
do
{
status = pdfWriter.StartPDF(BuildRelativeOutputPath(argv,"HighLevelImages.pdf"),
ePDFVersion13,
LogConfiguration(true,true,
BuildRelativeOutputPath(argv,"HighLevelImages.log")));
if(status != eSuccess)
{
cout<<"Failed to start file\n";
break;
}
PDFPage* page = new PDFPage();
page->SetMediaBox(PDFRectangle(0,0,595,842));
PageContentContext* cxt = pdfWriter.StartPageContentContext(page);
// simple image placement
cxt->DrawImage(10,10,BuildRelativeInputPath(argv,"images/soundcloud_logo.jpg"));
#ifndef PDFHUMMUS_NO_TIFF
cxt->DrawImage(10,500,BuildRelativeInputPath(argv,"images/tiff/cramps.tif"));
#endif // PDFHUMMUS_NO_TIFF
cxt->DrawImage(0,0,BuildRelativeInputPath(argv,"XObjectContent.pdf"));
status = pdfWriter.EndPageContentContext(cxt);
if(status != eSuccess)
{
status = PDFHummus::eFailure;
cout<<"Failed to end content context\n";
break;
}
status = pdfWriter.WritePageAndRelease(page);
if(status != eSuccess)
{
status = PDFHummus::eFailure;
cout<<"Failed to write page\n";
break;
}
page = new PDFPage();
page->SetMediaBox(PDFRectangle(0,0,595,842));
cxt = pdfWriter.StartPageContentContext(page);
AbstractContentContext::ImageOptions opt1;
opt1.imageIndex = 2;
#ifndef PDFHUMMUS_NO_TIFF
cxt->DrawImage(10,10,BuildRelativeInputPath(argv,"images/tiff/multipage.tif"),opt1);
#endif // PDFHUMMUS_NO_TIFF
AbstractContentContext::ImageOptions opt2;
opt2.transformationMethod = AbstractContentContext::eMatrix;
opt2.matrix[0] = opt2.matrix[3] = 0.25;
cxt->DrawImage(10,10,BuildRelativeInputPath(argv,"images/soundcloud_logo.jpg"),opt2);
AbstractContentContext::ImageOptions opt3;
opt3.transformationMethod = AbstractContentContext::eFit;
opt3.boundingBoxHeight = 100;
opt3.boundingBoxWidth = 100;
cxt->DrawImage(0,0,BuildRelativeInputPath(argv,"XObjectContent.pdf"),opt3);
opt3.fitProportional = true;
cxt->DrawImage(100,100,BuildRelativeInputPath(argv,"XObjectContent.pdf"),opt3);
// draw frames for soundcloud_logo.jpg and the 2 fitted version of XObjectContent.pdf
AbstractContentContext::GraphicOptions pathStrokeOptions(AbstractContentContext::eStroke,
AbstractContentContext::eRGB,
AbstractContentContext::ColorValueForName("DarkMagenta"),
4);
cxt->DrawRectangle(0,0,100,100,pathStrokeOptions);
cxt->DrawRectangle(100,100,100,100,pathStrokeOptions);
DoubleAndDoublePair jpgDimensions = pdfWriter.GetImageDimensions(BuildRelativeInputPath(argv,"images/soundcloud_logo.jpg"));
cxt->DrawRectangle(10,10,jpgDimensions.first/4,jpgDimensions.second/4,pathStrokeOptions);
status = pdfWriter.EndPageContentContext(cxt);
if(status != eSuccess)
{
status = PDFHummus::eFailure;
cout<<"Failed to end content context\n";
break;
}
status = pdfWriter.WritePageAndRelease(page);
if(status != eSuccess)
{
status = PDFHummus::eFailure;
cout<<"Failed to write page\n";
break;
}
status = pdfWriter.EndPDF();
if(status != eSuccess)
{
status = PDFHummus::eFailure;
cout<<"Failed to end pdf\n";
break;
}
}while(false);
return status;
}