Debian Codegraph @

podofo/test/CreationTest/CreationTest.cpp

raw symbols SCIP
1 /***************************************************************************
2 * Copyright (C) 2005 by Dominik Seichter *
3 * [email protected] *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21 #include "../PdfTest.h"
22
23 #include <cstdlib>
24 #include <cstdio>
25 #include <iostream>
26
27 using namespace PoDoFo;
28
29 #define CONVERSION_CONSTANT 0.002834645669291339
30
31 const char* pszLoremIpsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse lacinia sollicitudin viverra. Praesent augue tellus, feugiat vel tempus ac, semper in tellus. Maecenas et vehicula urna. Suspendisse ullamcorper molestie leo id aliquet. Mauris ultricies porttitor lectus vel facilisis. Integer euismod libero ut lectus mattis sed venenatis metus molestie. Aliquam feugiat, dolor a adipiscing ullamcorper, sapien orci ultrices erat, eget porttitor ipsum purus id magna. Morbi malesuada malesuada sagittis. Curabitur viverra posuere sem, quis condimentum eros viverra et. Pellentesque tristique aliquam orci a aliquam.\n\nIn hac habitasse platea dictumst. Maecenas vitae lorem velit. Donec at ultrices arcu. Phasellus et justo in quam fermentum volutpat. Nam vestibulum tempus lorem nec lacinia. Cras ac dignissim tortor. Morbi pellentesque, nisi sit amet sollicitudin accumsan, ante quam egestas lorem, a dapibus quam orci quis nulla. Donec quis orci ut lacus dictum sollicitudin at eget turpis. Nam condimentum iaculis enim, id volutpat est dapibus id. Quisque sed enim in est condimentum convallis. Cras at posuere ipsum. Cras tempor dui nunc, vel malesuada odio.";
32
33 void WriteStringToStream( const PdfString & rsString, std::ostringstream & oss, PdfFont* pFont )
34 {
35 PdfEncoding* pEncoding = new PdfIdentityEncoding( 0, 0xffff, true );
36 PdfRefCountedBuffer buffer = pEncoding->ConvertToEncoding( rsString, pFont );
37 pdf_long lLen = 0;
38 char* pBuffer = NULL;
39
40 PODOFO_UNIQUEU_PTR<PdfFilter> pFilter( PdfFilterFactory::Create( ePdfFilter_ASCIIHexDecode ) );
41 pFilter->Encode( buffer.GetBuffer(), buffer.GetSize(), &pBuffer, &lLen );
42
43 oss << "<";
44 oss << std::string( pBuffer, lLen );
45 oss << ">";
46 free( pBuffer );
47 delete pEncoding;
48 }
49
50 void CreateUnicodeAnnotationText( PdfPage* pPage, PdfDocument* /*pDocument*/ )
51 {
52 PdfString sJap(reinterpret_cast<const pdf_utf8*>("「PoDoFo」は今から日本語も話せます。"));
53 PdfAnnotation* pAnnotation =
54 pPage->CreateAnnotation( ePdfAnnotation_Text, PdfRect( 400.0, 200.0, 20.0, 20.0 ) );
55
56 PdfString sGerman(reinterpret_cast<const pdf_utf8*>("Unicode Umlauts: ÄÖÜß"));
57 pAnnotation->SetTitle( sGerman );
58 pAnnotation->SetContents( sJap );
59 pAnnotation->SetOpen( true );
60 }
61
62 void CreateUnicodeAnnotationFreeText( PdfPage* pPage, PdfDocument* pDocument )
63 {
64 PdfString sJap(reinterpret_cast<const pdf_utf8*>("「PoDoFo」は今から日本語も話せます。"));
65 PdfFont* pFont = pDocument->CreateFont( "Arial Unicode MS", false, new PdfIdentityEncoding( 0, 0xffff, true ) );
66
67 PdfRect rect( 200.0, 200.0, 200.0, 200.0 );
68 /*
69 PdfXObject xObj( rect, pDocument );
70
71 PdfPainter painter;
72 painter.SetPage( &xObj );
73 painter.SetFont( pFont );
74 painter.SetColor( 1.0, 0.0, 0.0 );
75 painter.Rectangle( 10.0, 10.0, 100.0, 100.0 );
76 painter.FillAndStroke();
77 painter.DrawText( 100.0, 100.0, sJap );
78 painter.FinishPage();
79 */
80
81 std::ostringstream oss;
82 oss << "BT" << std::endl << "/" << pFont->GetIdentifier().GetName()
83 << " " << pFont->GetFontSize()
84 << " Tf " << std::endl;
85
86 WriteStringToStream( sJap, oss, pFont );
87 oss << "Tj ET" << std::endl;
88
89 PdfDictionary fonts;
90 fonts.AddKey(pFont->GetIdentifier().GetName(), pFont->GetObject()->Reference());
91 PdfDictionary resources;
92 resources.AddKey( PdfName("Fonts"), fonts );
93
94 PdfAnnotation* pAnnotation =
95 pPage->CreateAnnotation( ePdfAnnotation_FreeText, rect );
96
97 PdfString sGerman(reinterpret_cast<const pdf_utf8*>("Unicode Umlauts: ÄÖÜß"));
98 pAnnotation->SetTitle( sGerman );
99 pAnnotation->SetContents( sJap );
100 //pAnnotation->SetAppearanceStream( &xObj );
101 pAnnotation->GetObject()->GetDictionary().AddKey( PdfName("DA"), PdfString(oss.str()) );
102 pAnnotation->GetObject()->GetDictionary().AddKey( PdfName("DR"), resources );
103
104
105 }
106
107 void LineTest( PdfPainter* pPainter, PdfPage* pPage, PdfDocument* pDocument )
108 {
109 double x = 10000 * CONVERSION_CONSTANT;
110 double y = pPage->GetPageSize().GetHeight() - 10000 * CONVERSION_CONSTANT;
111 PdfFont* pFont;
112
113 const double dLineLength = 50000 * CONVERSION_CONSTANT; // 5cm
114 double h;
115 double w;
116 int i;
117
118 /*
119 pFont = pDocument->CreateFont( "Arial Unicode MS", new PdfIdentityEncoding( 0, 0xffff, true ) );
120 printf("GOT: %s\n", pFont->GetFontMetrics()->GetFontname() );
121 PdfString sJap(reinterpret_cast<const pdf_utf8*>("「Po\tDoFo」は今から日本語も話せます。"));
122 const long lUtf8BufferLen = 256;
123 pdf_utf8 pUtf8Buffer[lUtf8BufferLen];
124
125
126 PdfString::ConvertUTF16toUTF8( sJap.GetUnicode(), sJap.GetUnicodeLength(), pUtf8Buffer, lUtf8BufferLen );
127 printf("UNIC: %s\n", pUtf8Buffer );
128
129 pFont->SetFontSize( 8.0 );
130 pPainter->SetFont( pFont );
131 pPainter->DrawText( 100.0, 100.0, sJap );
132 */
133
134 std::vector<int> vecCharacters;
135 vecCharacters.push_back( static_cast<int>('C') );
136 vecCharacters.push_back( static_cast<int>('G') );
137 vecCharacters.push_back( static_cast<int>('a') );
138 vecCharacters.push_back( static_cast<int>('c') );
139 vecCharacters.push_back( static_cast<int>('e') );
140 vecCharacters.push_back( static_cast<int>('l') );
141 vecCharacters.push_back( static_cast<int>('o') );
142 vecCharacters.push_back( static_cast<int>('p') );
143 vecCharacters.push_back( static_cast<int>('s') );
144 vecCharacters.push_back( static_cast<int>('r') );
145 vecCharacters.push_back( static_cast<int>('y') );
146 vecCharacters.push_back( static_cast<int>(' ') );
147 vecCharacters.push_back( static_cast<int>('-') );
148
149 pFont = pDocument->CreateFont( "Comic Sans MS", false, false ); //, vecCharacters );
150 if( !pFont )
151 {
152 PODOFO_RAISE_ERROR( ePdfError_InvalidHandle );
153 }
154
155 pFont->SetFontSize( 16.0 );
156
157
158 const wchar_t* msg = L"Grayscale - Colorspace";
159 h = pFont->GetFontMetrics()->GetLineSpacing();
160 w = pFont->GetFontMetrics()->StringWidth( msg );
161
162 pPainter->SetFont( pFont );
163 pPainter->DrawText( 120000 * CONVERSION_CONSTANT, y - pFont->GetFontMetrics()->GetLineSpacing(), msg );
164 pPainter->Rectangle( 120000 * CONVERSION_CONSTANT, y - pFont->GetFontMetrics()->GetLineSpacing(), w, h );
165 pPainter->Stroke();
166
167 // Draw 10 lines in gray scale
168 for( i = 0; i < 10; i++ )
169 {
170 x += (10000 * CONVERSION_CONSTANT);
171
172 pPainter->SetStrokeWidth( (i*1000) * CONVERSION_CONSTANT );
173 pPainter->SetStrokingGray( static_cast<double>(i)/10.0 );
174 pPainter->DrawLine( x, y, x, y - dLineLength );
175 }
176
177 x = 10000 * CONVERSION_CONSTANT;
178 y -= dLineLength;
179 y -= (10000 * CONVERSION_CONSTANT);
180
181 pFont = pDocument->CreateFont( "Arial", true, false ); // arial bold - not italic
182 if( !pFont )
183 {
184 PODOFO_RAISE_ERROR( ePdfError_InvalidHandle );
185 }
186
187 pFont->SetFontSize( 16.0 );
188 pPainter->SetFont( pFont );
189 pPainter->DrawText( 120000 * CONVERSION_CONSTANT, y - pFont->GetFontMetrics()->GetLineSpacing(), "RGB Colorspace" );
190
191 // Draw 10 lines in rgb
192 for( i = 0; i < 10; i++ )
193 {
194 x += (10000 * CONVERSION_CONSTANT);
195
196 pPainter->SetStrokeWidth( (i*1000) * CONVERSION_CONSTANT );
197 pPainter->SetStrokingColor( static_cast<double>(i)/10.0, 0.0, static_cast<double>(10-i)/10.0 );
198 pPainter->DrawLine( x, y, x, y - dLineLength );
199 }
200
201 x = 10000 * CONVERSION_CONSTANT;
202 y -= dLineLength;
203 y -= (10000 * CONVERSION_CONSTANT);
204
205 pFont = pDocument->CreateFont( "Arial", false, true ); // arial italic - not bold
206 if( !pFont )
207 {
208 PODOFO_RAISE_ERROR( ePdfError_InvalidHandle );
209 }
210
211 pFont->SetFontSize( 16.0 );
212 pPainter->SetFont( pFont );
213 pPainter->DrawText( 120000 * CONVERSION_CONSTANT, y - pFont->GetFontMetrics()->GetLineSpacing(), "CMYK Colorspace" );
214
215 // Draw 10 lines in cmyk
216 for( i = 0; i < 10; i++ )
217 {
218 x += (10000 * CONVERSION_CONSTANT);
219
220 pPainter->SetStrokeWidth( (i*1000) * CONVERSION_CONSTANT );
221 pPainter->SetStrokingColorCMYK( static_cast<double>(i)/10.0, 0.0, static_cast<double>(10-i)/10.0, 0.0 );
222 pPainter->DrawLine( x, y, x, y - dLineLength );
223 }
224
225 x = 20000 * CONVERSION_CONSTANT;
226 y -= 60000 * CONVERSION_CONSTANT;
227
228 pPainter->SetStrokeWidth( 1000 * CONVERSION_CONSTANT );
229 pPainter->SetStrokingColor( 0.0, 0.0, 0.0 );
230
231 pPainter->SetStrokeStyle( ePdfStrokeStyle_Solid );
232 pPainter->DrawLine( x, y, x + (100000 * CONVERSION_CONSTANT), y );
233 y -= (10000 * CONVERSION_CONSTANT);
234
235 pPainter->SetStrokeStyle( ePdfStrokeStyle_Dash );
236 pPainter->DrawLine( x, y, x + (100000 * CONVERSION_CONSTANT), y );
237 y -= (10000 * CONVERSION_CONSTANT);
238
239 pPainter->SetStrokeStyle( ePdfStrokeStyle_Dot );
240 pPainter->DrawLine( x, y, x + (100000 * CONVERSION_CONSTANT), y );
241 y -= (10000 * CONVERSION_CONSTANT);
242
243 pPainter->SetStrokeStyle( ePdfStrokeStyle_DashDot );
244 pPainter->DrawLine( x, y, x + (100000 * CONVERSION_CONSTANT), y );
245 y -= (10000 * CONVERSION_CONSTANT);
246
247 pPainter->SetStrokeStyle( ePdfStrokeStyle_DashDotDot );
248 pPainter->DrawLine( x, y, x + (100000 * CONVERSION_CONSTANT), y );
249 y -= (10000 * CONVERSION_CONSTANT);
250
251 pPainter->SetStrokeStyle( ePdfStrokeStyle_Custom, "[7 9 2] 4" );
252 pPainter->DrawLine( x, y, x + (100000 * CONVERSION_CONSTANT), y );
253 y -= (10000 * CONVERSION_CONSTANT);
254
255 //CreateUnicodeAnnotationText( pPage, pDocument );
256 CreateUnicodeAnnotationFreeText( pPage, pDocument );
257
258 return;
259 ///////////////////////
260 pPage = pDocument->CreatePage( PdfPage::CreateStandardPageSize( ePdfPageSize_A4 ) );
261 pPainter->SetPage( pPage );
262
263 x = 10000 * CONVERSION_CONSTANT;
264 y = pPage->GetPageSize().GetHeight() - 10000 * CONVERSION_CONSTANT;
265 char buffer[1024];
266
267 double dStroke = 0.01;
268 double dLine = pPainter->GetFont()->GetFontMetrics()->GetLineSpacing();
269 for( i=0;i<23; i++ )
270 {
271 sprintf( buffer, "Linewidth: %.3fpt", dStroke );
272 pPainter->DrawText( x, y, PdfString( buffer ) );
273
274 pPainter->Save();
275 pPainter->SetStrokeWidth( dStroke );
276 pPainter->DrawLine( x + 60000 * CONVERSION_CONSTANT, y + dLine/2.0, x + 140000 * CONVERSION_CONSTANT, y + dLine/2.0 );
277 pPainter->DrawLine( x + 60000 * CONVERSION_CONSTANT, y, x + 140000 * CONVERSION_CONSTANT, y );
278 pPainter->DrawLine( x + 60000 * CONVERSION_CONSTANT, y + dLine, x + 140000 * CONVERSION_CONSTANT, y + dLine );
279
280 pPainter->DrawLine( x + 60000 * CONVERSION_CONSTANT, y, x + 60000 * CONVERSION_CONSTANT, y + dLine );
281 pPainter->DrawLine( x + 140000 * CONVERSION_CONSTANT, y, x + 140000 * CONVERSION_CONSTANT, y + dLine );
282
283 pPainter->Restore();
284 dStroke += 0.05;
285
286 y -= dLine*2.0;
287 }
288 }
289
290 void RectTest( PdfPainter* pPainter, PdfPage* pPage, PdfDocument* pDocument )
291 {
292 double x = 10000 * CONVERSION_CONSTANT;
293 double y = pPage->GetPageSize().GetHeight() - 10000 * CONVERSION_CONSTANT;
294 PdfFont* pFont;
295
296 const double dWidth = 50000 * CONVERSION_CONSTANT; // 5cm
297 const double dHeight = 30000 * CONVERSION_CONSTANT; // 3cm
298
299 y -= dHeight;
300
301 pFont = pDocument->CreateFont( "Arial" );
302 if( !pFont )
303 {
304 PODOFO_RAISE_ERROR( ePdfError_InvalidHandle );
305 }
306
307 pFont->SetFontSize( 16.0 );
308 pPainter->SetFont( pFont );
309
310 pPainter->DrawText( 125000 * CONVERSION_CONSTANT, y - pFont->GetFontMetrics()->GetLineSpacing(), "Rectangles" );
311
312 pPainter->SetStrokeWidth( 100 * CONVERSION_CONSTANT );
313 pPainter->SetStrokingColor( 0.0, 0.0, 0.0 );
314 pPainter->Rectangle( x, y, dWidth, dHeight );
315 pPainter->Stroke();
316
317 PdfString sMultiLine("Hello World! We try to draw text using PdfPainter and DrawMultiLineText into an rectangle - including wordwrapping.");
318 pPainter->DrawMultiLineText( x, y, dWidth, dHeight, sMultiLine);
319
320 x += dWidth;
321 x += 10000 * CONVERSION_CONSTANT;
322
323 pPainter->SetStrokeWidth( 1000 * CONVERSION_CONSTANT );
324 pPainter->SetStrokingColor( 0.0, 0.0, 0.0 );
325 pPainter->Rectangle( x, y, dWidth, dHeight );
326 pPainter->Stroke();
327
328 y -= dHeight;
329 y -= 10000 * CONVERSION_CONSTANT;
330 x = 10000 * CONVERSION_CONSTANT;
331
332 pPainter->SetStrokeWidth( 100 * CONVERSION_CONSTANT );
333 pPainter->SetStrokingColor( 1.0, 0.0, 0.0 );
334 pPainter->Rectangle( x, y, dWidth, dHeight );
335 pPainter->Stroke();
336
337 x += dWidth;
338 x += 10000 * CONVERSION_CONSTANT;
339 pPainter->SetStrokeWidth( 1000 * CONVERSION_CONSTANT );
340 pPainter->SetStrokingColor( 0.0, 1.0, 0.0 );
341 pPainter->Rectangle( x, y, dWidth, dHeight );
342 pPainter->Stroke();
343
344 y -= dHeight;
345 y -= 10000 * CONVERSION_CONSTANT;
346 x = 10000 * CONVERSION_CONSTANT;
347
348 pPainter->SetStrokeWidth( 100 * CONVERSION_CONSTANT );
349 pPainter->SetStrokingColor( 0.0, 0.0, 0.0 );
350 pPainter->SetColor( 1.0, 0.0, 0.0 );
351 pPainter->Rectangle( x, y, dWidth, dHeight );
352 pPainter->FillAndStroke();
353
354 x += dWidth;
355 x += 10000 * CONVERSION_CONSTANT;
356 pPainter->SetStrokeWidth( 100 * CONVERSION_CONSTANT );
357 pPainter->SetStrokingColor( 0.0, 1.0, 0.0 );
358 pPainter->SetColor( 0.0, 0.0, 1.0 );
359 x = 0.0;
360 y = 0.0;
361 pPainter->Rectangle( x, y, 50000 * CONVERSION_CONSTANT, 50000 * CONVERSION_CONSTANT);
362 pPainter->FillAndStroke();
363
364 y -= dHeight;
365 y -= 10000 * CONVERSION_CONSTANT;
366 x = (10000 * CONVERSION_CONSTANT) + dWidth;
367
368 pPainter->DrawText( 120000 * CONVERSION_CONSTANT, y - pFont->GetFontMetrics()->GetLineSpacing(), "Triangles" );
369
370 // Draw a triangle at the current position
371 pPainter->SetColor( 0.0, 1.0, 1.0 );
372 pPainter->MoveTo( x, y );
373 pPainter->LineTo( x+dWidth, y-dHeight );
374 pPainter->LineTo( x-dWidth, y-dHeight );
375 pPainter->ClosePath();
376 pPainter->Fill();
377
378 y -= dHeight;
379 y -= 10000 * CONVERSION_CONSTANT;
380 x = (10000 * CONVERSION_CONSTANT) + dWidth;
381
382 pPainter->SetStrokingColor( 0.0, 0.0, 0.0 );
383 pPainter->MoveTo( x, y );
384 pPainter->LineTo( x+dWidth, y-dHeight );
385 pPainter->LineTo( x-dWidth, y-dHeight );
386 pPainter->ClosePath();
387 pPainter->Stroke();
388 }
389
390 void TextTest( PdfPainter* pPainter, PdfPage* pPage, PdfDocument* pDocument )
391 {
392 double x = 10000 * CONVERSION_CONSTANT;
393 double y = pPage->GetPageSize().GetHeight() - 10000 * CONVERSION_CONSTANT;
394
395 printf("Embedding Font\n");
396 printf("!!!!!!!!!!!!!!!\n");
397 pPainter->SetFont( pDocument->CreateFont( "Times New Roman" ) );
398 pPainter->GetFont()->SetFontSize( 24.0 );
399 printf("!!!!!!!!!!!!!!!\n");
400 y -= pPainter->GetFont()->GetFontMetrics()->GetLineSpacing();
401
402 pPainter->SetColor( 0.0, 0.0, 0.0 );
403 pPainter->DrawText( x, y, "Hallo Welt!" );
404
405 y -= pPainter->GetFont()->GetFontMetrics()->GetLineSpacing();
406 pPainter->GetFont()->SetUnderlined( true );
407 pPainter->SetStrokingColor( 1.0, 0.0, 0.0 );
408 pPainter->DrawText( x, y, "Underlined text in the same font!" );
409
410 pPainter->GetFont()->SetUnderlined( false );
411 y -= pPainter->GetFont()->GetFontMetrics()->GetLineSpacing();
412 pPainter->DrawText( x, y, "Disabled the underline again..." );
413 y -= pPainter->GetFont()->GetFontMetrics()->GetLineSpacing();
414
415 PdfFont* pFont = pDocument->CreateFont( "Arial" );
416 pFont->SetFontSize( 12.0 );
417
418 pPainter->SetFont( pFont );
419
420 pPainter->DrawText( x, y, "Normal" );
421 y -= pPainter->GetFont()->GetFontMetrics()->GetLineSpacing();
422
423 pPainter->GetFont()->SetUnderlined( true );
424 pPainter->DrawText( x, y, "Normal+underlinded" );
425 y -= pPainter->GetFont()->GetFontMetrics()->GetLineSpacing();
426
427 pPainter->GetFont()->SetUnderlined( false );
428 pFont->SetFontCharSpace( 100.0 );
429 pPainter->DrawText( x, y, "Mormal+spaced" );
430 y -= pPainter->GetFont()->GetFontMetrics()->GetLineSpacing();
431
432 pPainter->GetFont()->SetUnderlined( true );
433 pPainter->DrawText( x, y, "Normal+underlined+spaced" );
434 y -= pPainter->GetFont()->GetFontMetrics()->GetLineSpacing();
435 pPainter->GetFont()->SetUnderlined( false );
436 pFont->SetFontCharSpace( 0.0 );
437
438
439 y -= pPainter->GetFont()->GetFontMetrics()->GetLineSpacing();
440
441
442 pFont->SetFontScale( 50.0 );
443 pPainter->DrawText( x, y, "Condensed" );
444 y -= pPainter->GetFont()->GetFontMetrics()->GetLineSpacing();
445
446 pFont->SetFontCharSpace( 0.0 );
447 pPainter->GetFont()->SetUnderlined( true );
448 pPainter->DrawText( x, y, "Condensed+underlinded" );
449 y -= pPainter->GetFont()->GetFontMetrics()->GetLineSpacing();
450
451 pPainter->GetFont()->SetUnderlined( false );
452 pFont->SetFontCharSpace( 100.0 );
453 pPainter->DrawText( x, y, "Condensed+spaced" );
454 y -= pPainter->GetFont()->GetFontMetrics()->GetLineSpacing();
455
456
457 pPainter->GetFont()->SetUnderlined( true );
458 pPainter->DrawText( x, y, "Condensed+underlined+spaced" );
459 y -= pPainter->GetFont()->GetFontMetrics()->GetLineSpacing();
460 pPainter->GetFont()->SetUnderlined( false );
461 pFont->SetFontCharSpace( 0.0 );
462
463
464 y -= pPainter->GetFont()->GetFontMetrics()->GetLineSpacing();
465
466 pFont->SetFontScale( 200.0 );
467 pPainter->DrawText( x, y, "Expanded" );
468 y -= pPainter->GetFont()->GetFontMetrics()->GetLineSpacing();
469
470 pPainter->GetFont()->SetUnderlined( true );
471 pPainter->DrawText( x, y, "Expanded+underlinded" );
472 y -= pPainter->GetFont()->GetFontMetrics()->GetLineSpacing();
473
474 pPainter->GetFont()->SetUnderlined( false );
475 pFont->SetFontCharSpace( 100.0 );
476 pPainter->DrawText( x, y, "Expanded+spaced" );
477 y -= pPainter->GetFont()->GetFontMetrics()->GetLineSpacing();
478
479 pPainter->GetFont()->SetUnderlined( true );
480 pPainter->DrawText( x, y, "Expanded+underlined+spaced" );
481 y -= pPainter->GetFont()->GetFontMetrics()->GetLineSpacing();
482 pPainter->GetFont()->SetUnderlined( false );
483 pFont->SetFontCharSpace( 0.0 );
484 pFont->SetFontScale( 100.0 );
485
486
487 y -= pPainter->GetFont()->GetFontMetrics()->GetLineSpacing();
488 y -= pPainter->GetFont()->GetFontMetrics()->GetLineSpacing();
489
490 pPainter->GetFont()->SetStrikeOut( true );
491 pPainter->DrawText( x, y, "Strikeout" );
492 y -= pPainter->GetFont()->GetFontMetrics()->GetLineSpacing();
493 pPainter->GetFont()->SetUnderlined( false );
494
495
496 pPainter->DrawText( x, y, "PoDoFo rocks!" );
497 }
498
499 void ImageTest( PdfPainter* pPainter, PdfPage* pPage, PdfDocument* pDocument )
500 {
501 double y = pPage->GetPageSize().GetHeight() - 60000 * CONVERSION_CONSTANT;
502
503 #ifdef PODOFO_HAVE_JPEG_LIB
504 PdfImage image( pDocument );
505 #endif // PODOFO_HAVE_JPEG_LIB
506
507 PdfRect rect( 0, 0, 50000 * CONVERSION_CONSTANT, 50000 * CONVERSION_CONSTANT );
508 PdfRect rect1( 80000 * CONVERSION_CONSTANT, 3000 * CONVERSION_CONSTANT, 20000 * CONVERSION_CONSTANT, 20000 * CONVERSION_CONSTANT );
509 PdfRect rect2( 40000 * CONVERSION_CONSTANT, y, 50000 * CONVERSION_CONSTANT, 50000 * CONVERSION_CONSTANT );
510 PdfXObject xObj( rect, pDocument );
511 PdfPainter pnt; // XObject painter
512
513 #ifdef PODOFO_HAVE_JPEG_LIB
514 image.LoadFromFile( "resources/watzmann.jpg" );
515 #endif // PODOFO_HAVE_JPEG_LIB
516
517 pnt.SetPage( &xObj );
518 // Draw onto the XObject
519 pnt.SetFont( pDocument->CreateFont( "Comic Sans MS" ) );
520
521 pnt.GetFont()->SetFontSize( 8.0 );
522 pnt.SetStrokingColor( 1.0, 1.0, 1.0 );
523 pnt.SetColor( 1.0, 1.0, 0.0 );
524 pnt.Rectangle( 0, 0, xObj.GetPageSize().GetWidth(), xObj.GetPageSize().GetHeight() );
525 pnt.Fill();
526 pnt.SetColor( 0.0, 0.0, 0.0 );
527 pnt.Rectangle( 0, 1000 * CONVERSION_CONSTANT, 1000 * CONVERSION_CONSTANT, 1000 * CONVERSION_CONSTANT );
528 pnt.Stroke();
529 pnt.DrawText( 0, 1000 * CONVERSION_CONSTANT, "I am a XObject." );
530 pnt.FinishPage();
531
532 printf("Drawing on the page!\n");
533 // Draw onto the page
534
535 #ifdef PODOFO_HAVE_JPEG_LIB
536 /*
537 pPainter->DrawImage( 40000 * CONVERSION_CONSTANT, y, &image, 0.3, 0.3 );
538 pPainter->DrawImage( 40000 * CONVERSION_CONSTANT, y - (100000 * CONVERSION_CONSTANT), &image, 0.2, 0.5 );
539 pPainter->DrawImage( 40000 * CONVERSION_CONSTANT, y - (200000 * CONVERSION_CONSTANT), &image, 0.3, 0.3 );
540 */
541 pPainter->DrawImage( 0.0, pPage->GetPageSize().GetHeight() - image.GetHeight(), &image );
542 #endif // PODOFO_HAVE_JPEG_LIB
543
544 pPainter->DrawXObject( 120000 * CONVERSION_CONSTANT, y - (50000 * CONVERSION_CONSTANT), &xObj );
545 pPainter->Rectangle( 120000 * CONVERSION_CONSTANT, y - (50000 * CONVERSION_CONSTANT), 1000 * CONVERSION_CONSTANT, 1000 * CONVERSION_CONSTANT );
546 pPainter->Fill();
547
548 PdfAnnotation* pAnnot1 = pPage->CreateAnnotation( ePdfAnnotation_Widget, rect1 );
549 PdfAnnotation* pAnnot2 = pPage->CreateAnnotation( ePdfAnnotation_Link, rect2 );
550 PdfAnnotation* pAnnot3 = pPage->CreateAnnotation( ePdfAnnotation_Text, PdfRect( 20.0, 20.0, 20.0, 20.0 ) );
551 PdfAnnotation* pAnnot4 = pPage->CreateAnnotation( ePdfAnnotation_FreeText, PdfRect( 70.0, 20.0, 250.0, 50.0 ) );
552 PdfAnnotation* pAnnot5 = pPage->CreateAnnotation( ePdfAnnotation_Popup, PdfRect( 300.0, 20.0, 250.0, 50.0 ) );
553
554 pAnnot1->SetTitle( PdfString("Author: Dominik Seichter") );
555 pAnnot1->SetContents( PdfString("Hallo Welt!") );
556 pAnnot1->SetAppearanceStream( &xObj );
557
558 PdfAction action( ePdfAction_URI, pDocument );
559 action.SetURI( PdfString("http://podofo.sf.net") );
560
561 //pAnnot2->SetDestination( pPage );
562 pAnnot2->SetAction( action );
563 pAnnot2->SetFlags( ePdfAnnotationFlags_NoZoom );
564
565 pAnnot3->SetTitle( "A text annotation" );
566 pAnnot3->SetContents( "Lorum ipsum dolor..." );
567
568 pAnnot4->SetContents( "An annotation of type ePdfAnnotation_FreeText." );
569
570 pAnnot5->SetContents( "A popup annotation." );
571 pAnnot5->SetOpen( true );
572 }
573
574 void EllipseTest( PdfPainter* pPainter, PdfPage* pPage, PdfDocument* pDocument )
575 {
576 PdfAnnotation* pFileAnnotation;
577
578 double dX = 10000 * CONVERSION_CONSTANT;
579 double dY = pPage->GetPageSize().GetHeight() - 40000 * CONVERSION_CONSTANT;
580
581 pPainter->SetStrokingColor( 0.0, 0.0, 0.0 );
582 pPainter->Ellipse( dX, dY, 20000 * CONVERSION_CONSTANT, 20000 * CONVERSION_CONSTANT );
583 pPainter->Stroke();
584
585 dY -= 30000 * CONVERSION_CONSTANT;
586 pPainter->SetColor( 1.0, 0.0, 0.0 );
587 pPainter->Ellipse( dX, dY, 20000 * CONVERSION_CONSTANT, 20000 * CONVERSION_CONSTANT );
588 pPainter->Fill();
589
590 PdfFileSpec file( "resources/watzmann.jpg", true, pDocument );
591 pFileAnnotation = pPage->CreateAnnotation( ePdfAnnotation_FileAttachement, PdfRect( 300.0, 400.0, 250.0, 50.0 ) );
592 pFileAnnotation->SetContents( "A JPEG image of the Watzmann mountain, taken by Dominik 2016-07-05." );
593 pFileAnnotation->SetFileAttachement( file );
594 }
595
596 void XObjectTest( PdfPainter* pPainter, PdfPage* pPage, PdfDocument* pDocument )
597 {
598 double x = 10000 * CONVERSION_CONSTANT;
599 double y = pPage->GetPageSize().GetHeight() - 10000 * CONVERSION_CONSTANT;
600 const double dWidth = 180000 * CONVERSION_CONSTANT; // 18cm
601 const double dHeight = 270000 * CONVERSION_CONSTANT; // 27cm
602
603 pPainter->SetColor( 1.0, 0.8, 0.8 );
604 pPainter->Rectangle( x, y - dHeight, dWidth, dHeight );
605 pPainter->Fill();
606
607 // Das funktioniert immer
608 PdfXObject xObj1( "resources/Illust.pdf", 0, pDocument );
609 pPainter->DrawXObject( x + 90000 * CONVERSION_CONSTANT,
610 y - dHeight,
611 &xObj1 );
612 pPainter->SetColor( 1.0, 0.0, 0.0 );
613 pPainter->Rectangle( x + 90000 * CONVERSION_CONSTANT,
614 y - dHeight,
615 1000 * CONVERSION_CONSTANT,
616 1000 * CONVERSION_CONSTANT );
617 pPainter->Fill();
618
619
620 // Test XObject in XObject
621 PdfRect rectX( 0, 0, 50000 * CONVERSION_CONSTANT, 50000 * CONVERSION_CONSTANT );
622 PdfXObject xObj3( rectX, pDocument );
623 PdfXObject xObj4( rectX, pDocument );
624
625 // Draw text onto the XObject3
626 pPainter->SetPage( &xObj3 );
627 pPainter->SetColor( 0.0, 1.0, 0.0 );
628 pPainter->Rectangle( 0.0, 0.0, rectX.GetWidth(), rectX.GetHeight() );
629 pPainter->Fill();
630 pPainter->SetFont( pDocument->CreateFont( "Comic Sans MS" ) );
631 pPainter->SetColor( 0.0, 0.0, 0.0 );
632 pPainter->DrawText( 0, 1000 * CONVERSION_CONSTANT, "I am XObject 3." );
633 pPainter->FinishPage();
634
635 // Draw text and pdf onto the XObject4
636 pPainter->SetPage( &xObj4 );
637 pPainter->SetColor( 0.0, 1.0, 0.0 );
638 pPainter->Rectangle( 0.0, 0.0, rectX.GetWidth(), rectX.GetHeight() );
639 pPainter->Fill();
640 pPainter->SetFont( pDocument->CreateFont( "Comic Sans MS" ) );
641 pPainter->SetColor( 0.0, 0.0, 0.0 );
642 pPainter->DrawText( 0, 1000 * CONVERSION_CONSTANT, "I am XObject 4." );
643 PdfXObject xObj5( "resources/Illust.pdf", 0, pDocument );
644 pPainter->DrawXObject( 5000 * CONVERSION_CONSTANT,
645 5000 * CONVERSION_CONSTANT,
646 &xObj5,
647 0.1,
648 0.1 );
649 pPainter->FinishPage();
650
651
652 // Switch back to page and draw Xobject 3+4
653 pPainter->SetPage( pPage );
654 pPainter->DrawXObject( 20000 * CONVERSION_CONSTANT,
655 y - 60000 * CONVERSION_CONSTANT,
656 &xObj3 );
657 pPainter->DrawXObject( 120000 * CONVERSION_CONSTANT,
658 y - 60000 * CONVERSION_CONSTANT,
659 &xObj4 );
660 }
661
662 void MMTest( PdfPainterMM* pPainter, PdfPage* pPage, PdfDocument* pDocument )
663 {
664 long lX = 10000;
665 long lY = static_cast<long>(pPage->GetPageSize().GetHeight()/CONVERSION_CONSTANT) - 40000;
666
667 pPainter->SetStrokingColor( 0.0, 0.0, 0.0 );
668 pPainter->EllipseMM( lX, lY, 20000, 20000 );
669 pPainter->Stroke();
670
671 lY -= 30000;
672
673 pPainter->SetColor( 1.0, 0.0, 0.0 );
674 pPainter->EllipseMM( lX, lY, 20000, 20000 );
675 pPainter->Fill();
676
677 lY -= 60000;
678
679 // let's test out the opacity features
680 PdfExtGState trans( pDocument );
681 trans.SetFillOpacity( 0.5 );
682 pPainter->SetExtGState( &trans );
683 pPainter->SetColor( 1.0, 0.0, 0.0 );
684 pPainter->EllipseMM( lX, lY, 20000, 20000 );
685 pPainter->Fill();
686 pPainter->SetColor( 0.0, 1.0, 0.0 );
687 pPainter->EllipseMM( lX+20000, lY, 20000, 20000 );
688 pPainter->Fill();
689 pPainter->SetColor( 0.0, 0.0, 1.0 );
690 pPainter->EllipseMM( lX+10000, lY-10000, 20000, 20000 );
691 pPainter->Fill();
692
693
694 }
695
696 void TableTest( PdfPainter* pPainter, PdfPage* pPage, PdfDocument* pDocument )
697 {
698 int i,z;
699 double dX = 10000 * CONVERSION_CONSTANT;
700 double dY = (pPage->GetPageSize().GetHeight() - 40000 * CONVERSION_CONSTANT);
701
702 PdfFont* pFont = pDocument->CreateFont( "Comic Sans MS" );
703 pFont->SetFontSize( 12.0f );
704 pPainter->SetFont( pFont );
705
706 const int nCols = 3;
707 const int nRows = 10;
708 PdfSimpleTableModel model( nCols, nRows );
709 for(i=0;i<nCols;i++)
710 for(z=0;z<nRows;z++)
711 {
712 std::ostringstream oss;
713 oss << "Cell " << i << " " << z;
714 model.SetText( i, z, PdfString( oss.str() ) );
715 }
716
717 PdfTable table1( nCols, nRows );
718 table1.SetTableWidth ( 80000 * CONVERSION_CONSTANT );
719 table1.SetTableHeight( 120000 * CONVERSION_CONSTANT );
720 table1.SetModel( &model );
721 table1.Draw( dX, dY, pPainter );
722
723
724 dY = pPage->GetPageSize().GetHeight()/2.0 - 30000 * CONVERSION_CONSTANT;
725 dX = 2000.0 * CONVERSION_CONSTANT;
726
727 const int nCols2 = 5;
728 const int nRows2 = 4;
729 PdfSimpleTableModel model2( nCols2, nRows2 );
730 model2.SetAlignment( ePdfAlignment_Center );
731 model2.SetBackgroundColor( PdfColor( 0.3 ) );
732 model2.SetBackgroundEnabled( true );
733 for(i=0;i<nCols2;i++)
734 for(z=0;z<nRows2;z++)
735 {
736 std::ostringstream oss;
737 oss << rand();
738 model2.SetText( i, z, PdfString( oss.str() ) );
739 }
740
741 PdfTable table2( nCols2, nRows2 );
742 table2.SetModel( &model2 );
743 table2.Draw( dX, dY, pPainter );
744 }
745
746 void LargeMultiLineTextTest( PdfPainter* pPainter, PdfPage* pPage, PdfDocument* pDocument )
747 {
748 double x = 10000 * CONVERSION_CONSTANT;
749 double y = pPage->GetPageSize().GetHeight() - 10000 * CONVERSION_CONSTANT;
750 PdfFont* pFont;
751
752 const double dWidth = 100000 * CONVERSION_CONSTANT; // 10cm
753 const double dHeight = 50000 * CONVERSION_CONSTANT; // 5cm
754
755 y -= dHeight;
756
757 pFont = pDocument->CreateFont( "Arial" );
758 if( !pFont )
759 {
760 PODOFO_RAISE_ERROR( ePdfError_InvalidHandle );
761 }
762
763 pFont->SetFontSize( 48.0 );
764 pPainter->SetFont( pFont );
765
766 pPainter->SetStrokeWidth( 100 * CONVERSION_CONSTANT );
767 pPainter->SetStrokingColor( 0.0, 0.0, 0.0 );
768 pPainter->Rectangle( x, y, dWidth, dHeight );
769 pPainter->Stroke();
770
771 PdfString sMultiLine("PoDoFo is a library to work with the PDF file format and includes also a few tools. The name comes from the first three letters of PDF (Portable Document Format).");
772 pPainter->DrawMultiLineText( x, y, dWidth, dHeight, sMultiLine, ePdfAlignment_Left, ePdfVerticalAlignment_Top );
773
774 y = y - dHeight - dHeight / 2.0;
775
776 pPainter->Rectangle( x, y, dWidth, dHeight );
777 pPainter->Stroke();
778
779 pFont->SetFontSize( 12.0 );
780 pPainter->DrawMultiLineText( x, y, dWidth, dHeight, sMultiLine, ePdfAlignment_Left, ePdfVerticalAlignment_Top );
781
782 y = y - dHeight - dHeight / 2.0;
783
784 pPainter->Rectangle( x, y, dWidth, dHeight );
785 pPainter->Stroke();
786
787 pFont->SetFontSize( 16.0 );
788 pPainter->DrawMultiLineText( x, y, dWidth, dHeight, sMultiLine, ePdfAlignment_Left, ePdfVerticalAlignment_Center );
789
790 y = y - dHeight - dHeight / 2.0;
791
792 pPainter->Rectangle( x, y, dWidth, dHeight );
793 pPainter->Stroke();
794
795 pFont->SetFontSize( 32.0 );
796 pPainter->DrawMultiLineText( x, y, dWidth, dHeight, PdfString("PoDoFo is spelled without a g."), ePdfAlignment_Left, ePdfVerticalAlignment_Bottom );
797
798 }
799
800 void FontSubsetTest( PdfPainter* pPainter, PdfPage* pPage, PdfDocument* pDocument )
801 {
802 double x = 10000 * CONVERSION_CONSTANT;
803 double y = pPage->GetPageSize().GetHeight() - 10000 * CONVERSION_CONSTANT;
804 PdfFont* pFont;
805
806 const double dHeight = 50000 * CONVERSION_CONSTANT; // 5cm
807
808 y -= dHeight;
809
810 PdfEncoding* pEncoding = new PdfIdentityEncoding();
811 pFont = pDocument->CreateFontSubset( "Verdana", false, false, false, pEncoding );
812 if( !pFont )
813 {
814 PODOFO_RAISE_ERROR( ePdfError_InvalidHandle );
815 }
816
817 pFont->SetFontSize( 16.0 );
818 pPainter->DrawText(x, y, "Hello World!");
819
820 y -= dHeight;
821
822 pFont->SetFontSize( 32.0 );
823 pPainter->DrawText(x, y, "Subsetting in action!");
824 }
825
826 int main( int argc, char* argv[] )
827 {
828 try {
829 PdfMemDocument writer;
830 //PdfStreamedDocument writer ( argv[1], ePdfVersion_1_5, &PdfEncrypt( "dominik", "owner" ) );
831 PdfPage* pPage;
832 PdfPainter painter;
833 PdfPainterMM painterMM;
834 PdfOutlines* outlines;
835 PdfOutlineItem* pRoot;
836 if( argc != 2 )
837 {
838 printf("Usage: CreationTest [output_filename]\n");
839 return 0;
840 }
841
842 printf("This test tests the PdfWriter and PdfDocument classes.\n");
843 printf("It creates a new PdfFile from scratch.\n");
844 printf("---\n");
845
846 printf("PoDoFo DataType Size Information:\n");
847 printf("---\n");
848 printf("sizeof variant=%" PDF_FORMAT_UINT64 "\n", static_cast<pdf_uint64>(sizeof(PdfVariant)) );
849 printf("sizeof object=%" PDF_FORMAT_UINT64 "\n", static_cast<pdf_uint64>(sizeof(PdfObject)) );
850 printf("sizeof reference=%" PDF_FORMAT_UINT64 "\n", static_cast<pdf_uint64>(sizeof(PdfReference)) );
851 printf("---\n\n");
852
853 outlines = writer.GetOutlines();
854 pRoot = outlines->CreateRoot("PoDoFo Test Document" );
855
856 pPage = writer.CreatePage( PdfPage::CreateStandardPageSize( ePdfPageSize_A4 ) );
857 painter.SetPage( pPage );
858 pRoot->CreateChild( "Line Test", PdfDestination( pPage ) );
859
860 printf("Drawing the first page with various lines.\n");
861 TEST_SAFE_OP( LineTest( &painter, pPage, &writer ) );
862
863 pPage = writer.CreatePage( PdfPage::CreateStandardPageSize( ePdfPageSize_Letter ) );
864 painter.SetPage( pPage );
865
866 PdfString sLoremIpsum( pszLoremIpsum );
867
868 painter.DrawMultiLineText( 50.0, 50.0,
869 pPage->GetMediaBox().GetWidth() - 100.0,
870 pPage->GetMediaBox().GetHeight() - 100.0, sLoremIpsum );
871 painter.FinishPage();
872
873 pPage = writer.CreatePage( PdfPage::CreateStandardPageSize( ePdfPageSize_Letter ) );
874 painter.SetPage( pPage );
875 pRoot->Last()->CreateNext( "Rectangles Test", PdfDestination( pPage ) );
876
877 printf("Drawing the second page with various rectangle and triangles.\n");
878 TEST_SAFE_OP( RectTest( &painter, pPage, &writer ) );
879
880 pPage = writer.CreatePage( PdfPage::CreateStandardPageSize( ePdfPageSize_A4 ) );
881 painter.SetPage( pPage );
882 pRoot->Last()->CreateNext( "Text Test", PdfDestination( pPage ) );
883
884 printf("Drawing some text.\n");
885 TEST_SAFE_OP( TextTest( &painter, pPage, &writer ) );
886
887 pPage = writer.CreatePage( PdfPage::CreateStandardPageSize( ePdfPageSize_A4 ) );
888 painter.SetPage( pPage );
889 pRoot->Last()->CreateNext( "Image Test", PdfDestination( pPage ) );
890
891 printf("Drawing some images.\n");
892 TEST_SAFE_OP( ImageTest( &painter, pPage, &writer ) );
893
894 pPage = writer.CreatePage( PdfPage::CreateStandardPageSize( ePdfPageSize_A4 ) );
895 painter.SetPage( pPage );
896 pRoot->Last()->CreateNext( "Circle Test", PdfDestination( pPage ) );
897
898 printf("Drawing some circles and ellipsis.\n");
899 TEST_SAFE_OP( EllipseTest( &painter, pPage, &writer ) );
900 painter.FinishPage();
901
902 printf("Drawing some XObject's.\n");
903 pPage = writer.CreatePage( PdfPage::CreateStandardPageSize( ePdfPageSize_A4 ) );
904 painter.SetPage( pPage );
905 TEST_SAFE_OP( XObjectTest( &painter, pPage, &writer ) );
906 painter.FinishPage();
907
908 printf("Drawing using PdfTable.\n");
909 pPage = writer.CreatePage( PdfPage::CreateStandardPageSize( ePdfPageSize_A4 ) );
910 painter.SetPage( pPage );
911 pRoot->Last()->CreateNext( "PdfTable Test", PdfDestination( pPage ) );
912 TEST_SAFE_OP( TableTest( &painter, pPage, &writer ) );
913 painter.FinishPage();
914
915 printf("Drawing using PdfPainterMM.\n");
916 pPage = writer.CreatePage( PdfPage::CreateStandardPageSize( ePdfPageSize_A4 ) );
917 painterMM.SetPage( pPage );
918 pRoot->Last()->CreateNext( "MM Test", PdfDestination( pPage ) );
919 TEST_SAFE_OP( MMTest( &painterMM, pPage, &writer ) );
920 painterMM.FinishPage();
921
922 printf("Drawing using PdfPainter MultilineText.\n");
923 pPage = writer.CreatePage( PdfPage::CreateStandardPageSize( ePdfPageSize_A4 ) );
924 painter.SetPage( pPage );
925 pRoot->Last()->CreateNext( "Large MultilineText Test", PdfDestination( pPage ) );
926 TEST_SAFE_OP( LargeMultiLineTextTest( &painter, pPage, &writer ) );
927 painter.FinishPage();
928
929 printf("Drawing using Font Subset.\n");
930 pPage = writer.CreatePage( PdfPage::CreateStandardPageSize( ePdfPageSize_A4 ) );
931 painter.SetPage( pPage );
932 pRoot->Last()->CreateNext( "Font Subset Test", PdfDestination( pPage ) );
933 TEST_SAFE_OP( FontSubsetTest( &painter, pPage, &writer ) );
934 painter.FinishPage();
935
936 #if 0
937 /** Create a really large name tree to test the name tree implementation
938 */
939 for( int zz=1;zz<500;zz++ )
940 {
941 std::ostringstream oss;
942 oss << "A" << zz;
943
944 writer.GetNamesTree()->AddValue( "TestDict", PdfString( oss.str() ), PdfVariant( static_cast<long>(zz) ) );
945 }
946
947 writer.GetNamesTree()->AddValue( "TestDict", PdfString( "Berta" ), PdfVariant( 42L ) );
948 #endif
949
950 printf("Setting document informations.\n\n");
951 // Setup the document information dictionary
952 TEST_SAFE_OP( writer.GetInfo()->SetCreator ( PdfString("CreationTest - A simple test application") ) );
953 TEST_SAFE_OP( writer.GetInfo()->SetAuthor ( PdfString("Dominik Seichter") ) );
954 TEST_SAFE_OP( writer.GetInfo()->SetTitle ( PdfString("Test Document") ) );
955 //TEST_SAFE_OP( writer.GetInfo()->SetSubject ( PdfString("Testing the PDF Library") ) );
956 TEST_SAFE_OP( writer.GetInfo()->SetSubject (
957 PdfString(reinterpret_cast<const pdf_utf8*>("「PoDoFo」は今から日本語も話せます。") ) ) );
958 TEST_SAFE_OP( writer.GetInfo()->SetKeywords( PdfString("Test;PDF;") ) );
959
960 //xTEST_SAFE_OP( writer.AttachFile( PdfFileSpec("../../../podofo/test/CreationTest/CreationTest.cpp", true, &writer ) ) );
961
962 TEST_SAFE_OP( writer.Write( argv[1] ) );
963 //TEST_SAFE_OP( writer.Close() );
964
965 #ifdef TEST_MEM_BUFFER
966 // ---
967 const char* pszMemFile = "./mem_out.pdf";
968 FILE* hFile;
969
970 PdfRefCountedBuffer buffer;
971 PdfOutputDevice device( &buffer );
972 printf("Writing document from a memory buffer to: %s\n", pszMemFile );
973 TEST_SAFE_OP( writer.Write( &device ) );
974
975 hFile = fopen( pszMemFile, "wb" );
976 if( !hFile )
977 {
978 fprintf( stderr, "Cannot open file %s for writing.\n", pszMemFile );
979 return ePdfError_InvalidHandle;
980 }
981
982 long lBufferLen = device.GetLength();
983 printf("lBufferLen=%li\n", lBufferLen );
984 printf("Wrote=%i\n", static_cast<int>(fwrite( buffer.GetBuffer(), lBufferLen, sizeof( char ), hFile )) );
985 fclose( hFile );
986 #endif
987 } catch( PdfError & e ) {
988 std::cerr << "Error: An error " << e.GetError() << " ocurred." << std::endl;
989 e.PrintErrorMsg();
990 return e.GetError();
991 }
992
993 return 0;
994 }