~efargaspro/+junk/codeblocks-16.01-release

« back to all changes in this revision

Viewing changes to src/plugins/contrib/source_exporter/wxPdfDocument/samples/minimal/tutorial6.cpp

  • Committer: damienlmoore at gmail
  • Date: 2016-02-02 02:43:22 UTC
  • Revision ID: damienlmoore@gmail.com-20160202024322-yql5qmtbwdyamdwd
Code::BlocksĀ 16.01

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
///////////////////////////////////////////////////////////////////////////////
 
2
// Name:        tutorial6.cpp
 
3
// Purpose:     Tutorial 6: Test program for wxPdfDocument
 
4
// Author:      Ulrich Telle
 
5
// Modified by:
 
6
// Created:     2006-02-12
 
7
// Copyright:   (c) Ulrich Telle
 
8
// Licence:     wxWindows licence
 
9
///////////////////////////////////////////////////////////////////////////////
 
10
 
 
11
// For compilers that support precompilation, includes "wx/wx.h".
 
12
#include "wx/wxprec.h"
 
13
 
 
14
#ifdef __BORLANDC__
 
15
#pragma hdrstop
 
16
#endif
 
17
 
 
18
#ifndef WX_PRECOMP
 
19
#include "wx/wx.h"
 
20
#endif
 
21
 
 
22
#include "wx/pdfdoc.h"
 
23
 
 
24
/**
 
25
* Links and flowing text
 
26
*
 
27
* This tutorial explains how to insert links (internal and external) and shows
 
28
* a new text writing mode. It also contains a rudimentary HTML parser.
 
29
* The new method to print text is Write(). It is very close to MultiCell();
 
30
* the differences are: The end of line is at the right margin and the next line
 
31
* begins at the left one. The current position moves at the end of the text. 
 
32
* So it allows to write a chunk of text, alter the font style, then continue from
 
33
* the exact place we left it. On the other hand, you cannot full justify it. 
 
34
*
 
35
* The method is used on the first page to put a link pointing to the second one.
 
36
* The beginning of the sentence is written in regular style, then we switch to
 
37
* underline and finish it. The link is created with AddLink(), which returns a
 
38
* link identifier. The identifier is passed as third parameter of Write(). Once
 
39
* the second page is created, we use SetLink() to make the link point to the
 
40
* beginning of the current page. 
 
41
*
 
42
* Then we put an image with a link on it. An external link points to an URL
 
43
* (HTTP, mailto...). The URL is simply passed as last parameter of Image().
 
44
*
 
45
* Finally, the left margin is moved after the image with SetLeftMargin() and some
 
46
* text in XML format is output. 
 
47
* Recognized tags are <B>, <I>, <U>, <A> and <BR>; the others are ignored.
 
48
*
 
49
*/
 
50
 
 
51
void
 
52
tutorial6()
 
53
{
 
54
  wxString xmlString =
 
55
    wxString(wxT("You can now easily print text mixing different styles : <b>bold</b>, <i>italic</i>, ")) +
 
56
    wxString(wxT("<u>underlined</u>, or <b><i><u>all at once</u></i></b>!<br/>You can also insert links ")) +
 
57
    wxString(wxT("on text, such as <a href=\"http://www.fpdf.org\">www.fpdf.org</a>, or on an image: click on the logo."));
 
58
 
 
59
  wxPdfDocument pdf;
 
60
  // First page
 
61
  pdf.AddPage();
 
62
  pdf.SetFont(wxT("Helvetica"), wxT(""), 20.0);
 
63
  pdf.StartTransform();
 
64
  pdf.Write(5, wxT("To find out what's new in this tutorial, click "));
 
65
  pdf.SetFont(wxT(""), wxT("U"));
 
66
  int link = pdf.AddLink();
 
67
  pdf.Write(5, wxT("here"), wxPdfLink(link));
 
68
  pdf.SetFont(wxT(""));
 
69
  pdf.StopTransform();
 
70
  // Second page
 
71
  pdf.AddPage();
 
72
  pdf.SetLink(link);
 
73
  pdf.Image(wxT("logo.png"), 10, 10, 30, 0, wxT(""),wxPdfLink(wxT("http://www.fpdf.org")));
 
74
  pdf.SetLeftMargin(45);
 
75
  pdf.SetFontSize(14);
 
76
  pdf.WriteXml(xmlString);
 
77
 
 
78
  pdf.SaveAsFile(wxT("tutorial6.pdf"));
 
79
}
 
80