-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnit1.cpp
More file actions
193 lines (182 loc) · 5.92 KB
/
Unit1.cpp
File metadata and controls
193 lines (182 loc) · 5.92 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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#define UNICODE
// ---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "DebenuPDFLibraryDLL1013.h"
#include "DebenuPDFLicenseKey.h"
#include "Unit1.h"
// ---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "PtblRV"
#pragma link "RichView"
#pragma link "RVEdit"
#pragma link "RVReport"
#pragma link "RVScroll"
#pragma link "RVStyle"
#pragma link "PtblRV"
#pragma link "RichView"
#pragma link "RVEdit"
#pragma link "RVReport"
#pragma link "RVScroll"
#pragma link "RVStyle"
#pragma resource "*.dfm"
TForm1 *Form1;
// ---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner) :
TForm(Owner)
{
}
const int RTFPRINTINGDOTSPERINCH = 96;
const double RTFPAGEHEIGHTININCHES = 11;
const double RTFPAGEWIDTHININCHES = 8.5;
const int DEBENUUNITSIZE = 72; // 72 DPI is Debenu default
typedef DebenuPDFLibraryDLL1013 DebenuPDFLibrary;
DebenuPDFLibrary* GetGlobalDebenu(
bool fClearDocuments = false,
bool fReleaseLibrary = false) // default false, false
{
static DebenuPDFLibrary* gDebenuLibrary = NULL;
static int gDebenuLibraryUnlocked = 0;
if (fReleaseLibrary)
{
if (gDebenuLibrary)
{
delete(gDebenuLibrary);
gDebenuLibrary = NULL;
}
return NULL;
}
if (gDebenuLibrary == NULL)
{
gDebenuLibrary = new DebenuPDFLibraryDLL1013(L"DebenuPDFLibraryDLL1013.dll");
bool fLoaded = gDebenuLibrary->LibraryLoaded();
if (!fLoaded)
{
delete gDebenuLibrary;
gDebenuLibrary = NULL;
throw Exception("Unable to load Debenu library");
}
}
if (!gDebenuLibraryUnlocked)
{
// #define DEBENULICENSEKEY L"xxxabc123" // include your real (or trial) license key here or elsewhere
gDebenuLibrary->UnlockKey(DEBENULICENSEKEY);
gDebenuLibraryUnlocked = gDebenuLibrary->Unlocked();
if (!gDebenuLibraryUnlocked)
{
delete gDebenuLibrary; // so we will reload next time
gDebenuLibrary = NULL;
throw Exception("Unable to unlock Debenu library");
}
gDebenuLibrary->SetOrigin(1); // top left -- set when library first loaded and unlocked
}
if (fClearDocuments)
{
while (gDebenuLibrary->DocumentCount() > 1)
{
gDebenuLibrary->RemoveDocument(gDebenuLibrary->GetDocumentID(1));
}
// Remove the last document. It will be replaced with a new, blank document, so that DocumentCount() will still be 1
gDebenuLibrary->RemoveDocument(gDebenuLibrary->GetDocumentID(1));
gDebenuLibrary->SetOrigin(1); // top left -- set when documents cleared
}
return gDebenuLibrary;
}
// ---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int outputDocID = 0; // keeps track of Debenu PDF Document that is collecting the pages
/* to load the ReportHelper's RichView from a stream
RVReportHelper1->RichView->ClearAll();
RVReportHelper1->RichView->FormatAll();
if (format == TSPage::forRTF)
{
RVReportHelper1->RichView->LoadRTFFromStream(stream);
}
else
{
RVReportHelper1->RichView->LoadTextFromStream(
stream,
0,
0,
false);
} */
TMemoryStream* memStream = new TMemoryStream;
RichViewEdit1->SaveRTFToStream(
memStream,
false);
memStream->Position = 0;
RVReportHelper1->RichView->LoadRTFFromStream(memStream);
DebenuPDFLibrary* debenu = GetGlobalDebenu(true); // clear documents
HDC hdc = debenu->GetCanvasDC(
RTFPRINTINGDOTSPERINCH * RTFPAGEWIDTHININCHES,
RTFPRINTINGDOTSPERINCH * RTFPAGEHEIGHTININCHES);
TCanvas* canvas = new TCanvas;
canvas->Handle = hdc;
RVReportHelper1->RichView->TopMargin = RTFPRINTINGDOTSPERINCH * 1.25;
RVReportHelper1->RichView->BottomMargin = RTFPRINTINGDOTSPERINCH * 0.75;
RVReportHelper1->RichView->RightMargin = RTFPRINTINGDOTSPERINCH * 0.75;
RVReportHelper1->RichView->LeftMargin = RTFPRINTINGDOTSPERINCH * 0.75;
RVReportHelper1->Init(
canvas, // used just for dimensions
RTFPRINTINGDOTSPERINCH * RTFPAGEWIDTHININCHES);
delete memStream;
delete canvas;
canvas = NULL;
int PageCounter = 1;
while (RVReportHelper1->FormatNextPage(RTFPRINTINGDOTSPERINCH * RTFPAGEHEIGHTININCHES))
{
int LastPageHeight = RVReportHelper1->GetLastPageHeight();
HDC hdcNew = debenu->GetCanvasDC(
RTFPRINTINGDOTSPERINCH * RTFPAGEWIDTHININCHES,
RTFPRINTINGDOTSPERINCH * RTFPAGEHEIGHTININCHES);
canvas = new TCanvas;
canvas->Handle = hdcNew;
RVReportHelper1->DrawPage(
PageCounter,
canvas,
true,
RTFPRINTINGDOTSPERINCH * RTFPAGEHEIGHTININCHES); // LastPageHeight);
int LastPageHeight2 = RVReportHelper1->GetLastPageHeight();
PageCounter++;
int loadResult = debenu->LoadFromCanvasDC(RTFPRINTINGDOTSPERINCH, 0);
// creates a new document - 50 DPI
delete canvas;
canvas = NULL;
if (loadResult)
{
/* to draw some additional info on each page
debenu->SetOrigin(1);
debenu->SetTextSize(12);
int res =
debenu->DrawTextBox(DEBENUUNITSIZE * 0.5,
DEBENUUNITSIZE * (0.5), DEBENUUNITSIZE * 4, 12 + 4,
PatientName, 0); // vertically centered
if (int(ServiceStart) > 0)
{
debenu->SetTextSize(10);
debenu->DrawTextBox(
DEBENUUNITSIZE * 0.5,
(DEBENUUNITSIZE * ( 0.5) + 12 + 4),
DEBENUUNITSIZE * 4,
12 + 4,
ServiceStart.FormatString("dddd, mmmm d, yyyy"),
0); // vertically centered
}
*/
if (outputDocID == 0)
{
outputDocID = debenu->SelectedDocument();
}
else
{
int newLoadedDocument = debenu->SelectedDocument();
debenu->SelectDocument(outputDocID);
debenu->MergeDocument(newLoadedDocument); // this deletes the second document
}
}
}
debenu->SelectDocument(outputDocID);
debenu->SaveToFile("c:\\testtrichview.pdf");
}
// ---------------------------------------------------------------------------