Home | History | Annotate | Download | only in sample
      1 Using Skia's PDF Backend
      2 ========================
      3 
      4 Here is an example of using Skia's PDF backend in the recommended way:
      5 via the SkDocument and SkCanvas APIs.
      6 
      7 <!--?prettify?-->
      8 
      9     #include "SkDocument.h"
     10 
     11     bool WritePDF() {
     12         SkWStream* outputStream = ....;
     13 
     14         SkAutoTUnref<SkDocument> pdfDocument(
     15                 SkDocument::CreatePDF(outputStream));
     16 
     17         int numberOfPages = ....;
     18         for (int page = 0; page < numberOfPages; ++page) {
     19             SkScalar pageWidth = ....;
     20             SkScalar pageHeight = ....;
     21             SkCanvas* pageCanvas =
     22                     pdfDocument->beginPage(pageWidth, pageHeight);
     23 
     24             // ....insert canvas draw commands here....
     25 
     26             pdfDocument->endPage();
     27         }
     28 
     29         SkTArray<SkDocument::Attribute> info;
     30         info.emplace_back(SkString("Title"), SkString("...."));
     31         info.emplace_back(SkString("Author"), SkString("...."));
     32         info.emplace_back(SkString("Subject"), SkString("...."));
     33         info.emplace_back(SkString("Keywords"), SkString("...."));
     34         info.emplace_back(SkString("Creator"), SkString("...."));
     35         SkTime::DateTime now;
     36         SkTime::GetDateTime(&now);
     37         pdfDocument->setMetadata(info, &now, &now);
     38 
     39         return pdfDocument->close();
     40     }
     41