<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>cairomm: pdf-surface.cc</title> <link href="cairomm.css" rel="stylesheet" type="text/css"> </head> <body> <!-- Generated by Doxygen 1.7.3 --> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li><a href="examples.html"><span>Examples</span></a></li> </ul> </div> </div> <div class="header"> <div class="headertitle"> <h1>pdf-surface.cc</h1> </div> </div> <div class="contents"> <p>An example of using <a class="el" href="classCairo_1_1PdfSurface.html" title="A PdfSurface provides a way to render PDF documents from cairo.">Cairo::PdfSurface</a> class to render to PDF</p> <div class="fragment"><pre class="fragment"><span class="comment">/* M_PI is defined in math.h in the case of Microsoft Visual C++, Solaris,</span> <span class="comment"> * et. al.</span> <span class="comment"> */</span> <span class="preprocessor">#if defined(_MSC_VER)</span> <span class="preprocessor"></span><span class="preprocessor">#define _USE_MATH_DEFINES</span> <span class="preprocessor"></span><span class="preprocessor">#endif </span> <span class="preprocessor"></span> <span class="preprocessor">#include <string></span> <span class="preprocessor">#include <iostream></span> <span class="preprocessor">#include <cairommconfig.h></span> <span class="preprocessor">#include <cairomm/context.h></span> <span class="preprocessor">#include <cairomm/surface.h></span> <span class="preprocessor">#include <cmath></span> <span class="keywordtype">int</span> main() { <span class="preprocessor">#ifdef CAIRO_HAS_PDF_SURFACE</span> <span class="preprocessor"></span> <a name="_a0"></a><a class="codeRef" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a00254.html">std::string</a> filename = <span class="stringliteral">"image.pdf"</span>; <span class="keywordtype">int</span> width = 600; <span class="keywordtype">int</span> height = 400; <a name="_a1"></a><a class="code" href="classCairo_1_1RefPtr.html" title="RefPtr&lt;&gt; is a reference-counting shared smartpointer.">Cairo::RefPtr<Cairo::PdfSurface></a> surface = <a name="a2"></a><a class="code" href="classCairo_1_1PdfSurface.html#a92403fe5ad8ae6862e005c3d185e9123" title="Creates a PdfSurface with a specified dimensions that will be saved as the given filename.">Cairo::PdfSurface::create</a>(filename, width, height); <a class="code" href="classCairo_1_1RefPtr.html" title="RefPtr&lt;&gt; is a reference-counting shared smartpointer.">Cairo::RefPtr<Cairo::Context></a> cr = <a name="a3"></a><a class="code" href="classCairo_1_1Context.html#a9a27f6ec57d788fd3ecbc310aeb24d99">Cairo::Context::create</a>(surface); cr->save(); <span class="comment">// save the state of the context</span> cr->set_source_rgb(0.86, 0.85, 0.47); cr->paint(); <span class="comment">// fill image with the color</span> cr->restore(); <span class="comment">// color is back to black now</span> cr->save(); <span class="comment">// draw a border around the image</span> cr->set_line_width(20.0); <span class="comment">// make the line wider</span> cr->rectangle(0.0, 0.0, cairo_image_surface_get_width(surface->cobj()), height); cr->stroke(); cr->set_source_rgba(0.0, 0.0, 0.0, 0.7); <span class="comment">// draw a circle in the center of the image</span> cr->arc(width / 2.0, height / 2.0, height / 4.0, 0.0, 2.0 * M_PI); cr->stroke(); <span class="comment">// draw a diagonal line</span> cr->move_to(width / 4.0, height / 4.0); cr->line_to(width * 3.0 / 4.0, height * 3.0 / 4.0); cr->stroke(); cr->restore(); cr->show_page(); <a name="a4"></a><a class="codeRef" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a01136.html#aaf93fdf0812752e0e02c501dea1b38f0">std::cout</a> << <span class="stringliteral">"Wrote PDF file \""</span> << filename << <span class="stringliteral">"\""</span> << <a name="a5"></a><a class="codeRef" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a01136.html#a9e2ba1ed9813a1f03adc9a87dbf491a5">std::endl</a>; <span class="keywordflow">return</span> 0; <span class="preprocessor">#else</span> <span class="preprocessor"></span> <a class="codeRef" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a01136.html#aaf93fdf0812752e0e02c501dea1b38f0">std::cout</a> << <span class="stringliteral">"You must compile cairo with PDF support for this example to work."</span> << <a class="codeRef" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a01136.html#a9e2ba1ed9813a1f03adc9a87dbf491a5">std::endl</a>; <span class="keywordflow">return</span> 1; <span class="preprocessor">#endif</span> <span class="preprocessor"></span>} </pre></div> </div> </div> <hr class="footer"/><address class="footer"><small>Generated on Mon May 9 2011 09:51:07 for cairomm by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.3 </small></address> </body> </html>