1Using Skia's PDF Backend
2========================
3
4Here is an example of using Skia's PDF backend (SkPDF) via the
5SkDocument and SkCanvas APIs.
6
7<!--?prettify lang=cc?-->
8
9    #include "SkPDFDocument.h"
10
11    void WritePDF(SkWStream* outputStream,
12                  const char* documentTitle,
13                  void (*writePage)(SkCanvas*, int page),
14                  int numberOfPages,
15                  SkSize pageSize) {
16        SkPDF::Metadata metadata;
17        metadata.fTitle = documentTitle;
18        metadata.fCreator = "Example WritePDF() Function";
19        SkTime::DateTime now;
20        SkTime::GetDateTime(&now);
21        metadata.fCreation = now;
22        metadata.fModified = now;
23        auto pdfDocument = SkPDF::MakeDocument(outputStream, metadata);
24        assert(pdfDocument);
25
26        for (int page = 0; page < numberOfPages; ++page) {
27            SkCanvas* pageCanvas = pdfDocument->beginPage(pageSize.width(),
28                                                          pageSize.height());
29            writePage(pageCanvas, page);
30            pdfDocument->endPage();
31        }
32        pdfDocument->close();
33    }
34
35* * *
36
37<span id="limits">SkPDF Limitations</span>
38------------------------------------------
39
40There are several corners of Skia's public API that SkPDF currently
41does not handle because either no known client uses the feature or
42there is no simple PDF-ish way to handle it.
43
44In this document:
45
46  + **drop** means to draw nothing.
47
48  + **ignore** means to draw without the effect
49
50  + **expand** means to implement something in a non-PDF-ish way.
51    This may mean to rasterize vector graphics, to expand paths with
52    path effects into many individual paths, or to convert text to
53    paths.
54
55<style scoped><!--
56#pdftable {border-collapse:collapse;}
57#pdftable tr th, #pdftable tr td {border:#888888 2px solid;padding: 5px;}
58--></style>
59<table id="pdftable">
60<tr><th>Effect</th>                  <th>text</th>   <th>images</th> <th>everything
61                                                                         else</th></tr>
62<tr><th>SkMaskFilter</th>            <td>drop</td>   <td>ignore</td> <td>ignore</td></tr>
63<tr><th>SkPathEffect</th>            <td>ignore</td> <td>n/a</td>    <td>expand</td></tr>
64<tr><th>SkColorFilter</th>           <td>ignore</td> <td>expand</td> <td>ignore</td></tr>
65<tr><th>SkImageFilter</th>           <td>expand</td> <td>expand</td> <td>expand</td></tr>
66<tr><th>unsupported SkXferModes</th> <td>ignore</td> <td>ignore</td> <td>ignore</td></tr>
67<tr><th>non-gradient SkShader</th>   <td>expand</td> <td>n/a</td>    <td>expand</td></tr>
68</table>
69
70Notes:
71
72  - *SkImageFilter*: When SkImageFilter is expanded, text-as-text is lost.
73
74  - *SkXferMode*: The following transfer modes are not natively
75    supported by PDF: DstOver, SrcIn, DstIn, SrcOut, DstOut, SrcATop,
76    DstATop, and Modulate.
77
78Other limitations:
79
80  - *drawText with VerticalText* — drop. No known clients seem to make use
81    of the VerticalText flag.
82
83  - *drawTextOnPath* — expand. (Text-as-text is lost.)
84
85  - *drawVertices* — drop.
86
87  - *drawPatch* — drop.
88
89* * *
90