forked from pocoproject/poco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImage.cpp
More file actions
65 lines (53 loc) · 1.8 KB
/
Image.cpp
File metadata and controls
65 lines (53 loc) · 1.8 KB
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
//
// Image.cpp
//
// $Id: //poco/Main/PDF/samples/Image/src/Image.cpp#1 $
//
// This sample demonstrates the Data library.
//
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
// All rights reserved.
//
// This is unpublished proprietary source code of Applied Informatics
// Software Engineering GmbH.
// The contents of this pdfFile may not be disclosed to third parties,
// copied or duplicated in any form, in whole or in part, without
// prior written permission from Applied Informatics.
//
#include "Poco/PDF/Document.h"
#include "Poco/Path.h"
#include "Poco/File.h"
#if defined(POCO_OS_FAMILY_UNIX)
const std::string pdfFileName = "${POCO_BASE}/PDF/samples/Image/Image.pdf";
const std::string pngFileName = "${POCO_BASE}/PDF/samples/Image/logo.PNG";
#elif defined(POCO_OS_FAMILY_WINDOWS)
const std::string pdfFileName = "%POCO_BASE%/PDF/samples/Image/Image.pdf";
const std::string pngFileName = "%POCO_BASE%/PDF/samples/Image/logo.PNG";
#endif
using Poco::PDF::Document;
using Poco::PDF::Font;
using Poco::PDF::Page;
using Poco::PDF::Image;
using Poco::Path;
using Poco::File;
int main(int argc, char** argv)
{
File pdfFile(Path::expand(pdfFileName));
if (pdfFile.exists()) pdfFile.remove();
File pngFile(Path::expand(pngFileName));
Document document(pdfFile.path());
Page page = document[0];
Font helv = document.font("Helvetica");
page.setFont(helv, 24);
std::string hello = "Hello PDF World from ";
float textWidth = page.textWidth(hello);
float textBegin = (page.getWidth() - textWidth) / 2;
page.writeOnce(textBegin, page.getHeight() - 50, hello);
Image image = document.loadPNGImage(pngFile.path());
page.drawImage(image, textBegin + textWidth / 2 - image.width() / 2,
page.getHeight() - 100 - image.height(),
image.width(),
image.height());
document.save();
return 0;
}