Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(655)

Side by Side Diff: site/user/sample/pdf.md

Issue 1936283003: documentation: SkDocument::MakePDF() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2016-05-02 (Monday) 17:27:37 EDT Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « site/user/api/canvas.md ('k') | src/utils/SkLua.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 Using Skia's PDF Backend 1 Using Skia's PDF Backend
2 ======================== 2 ========================
3 3
4 Here is an example of using Skia's PDF backend in the recommended way: 4 Here is an example of using Skia's PDF backend in the recommended way:
5 via the SkDocument and SkCanvas APIs. 5 via the SkDocument and SkCanvas APIs.
6 6
7 <!--?prettify lang=cc?--> 7 <!--?prettify lang=cc?-->
8 8
9 #include "SkDocument.h" 9 #include "SkDocument.h"
10 10
11 bool WritePDF(SkWStream* outputStream) { 11 bool WritePDF(SkWStream* outputStream) {
12 sk_sp<SkDocument> pdfDocument(SkDocument::CreatePDF(outputStream)); 12 SkDocument::PDFMetadata metadata;
13 typedef SkDocument::Attribute Attr; 13 metadata.fCreator = "creator....";
14 Attr info[] = { 14 metadata.fTitle = "title...";
15 Attr(SkString("Title"), SkString("....")), 15 metadata.fAuthor = "author...";
16 Attr(SkString("Author"), SkString("....")), 16 metadata.fSubject = "subject...";
17 Attr(SkString("Subject"), SkString("....")), 17 metadata.fKeywords = "keywords...";
18 Attr(SkString("Keywords"), SkString("....")), 18 metadata.fCreator = "creator...";
19 Attr(SkString("Creator"), SkString("....")), 19 SkTime::DateTime now = get_current_date_and_time();
20 }; 20 metadata.fCreation.fEnabled = true;
21 int infoCount = sizeof(info) / sizeof(info[0]); 21 metadata.fCreation.fDateTime = now;
22 SkTime::DateTime now; 22 metadata.fModified.fEnabled = true;
23 SkTime::GetDateTime(&now); 23 metadata.fModified.fDateTime = now;
24 pdfDocument->setMetadata(info, infoCount, &now, &now); 24 sk_sp<SkDocument> pdfDocument(SkDocument::MakePDF(
25 outputStream, SK_ScalarDefaultRasterDPI, metadata,
26 nullptr, true);
27 assert(pdfDocument);
25 28
26 int numberOfPages = ....; 29 int numberOfPages = ....;
27 for (int page = 0; page < numberOfPages; ++page) { 30 for (int page = 0; page < numberOfPages; ++page) {
28 SkScalar pageWidth = ....; 31 SkScalar pageWidth = ....;
29 SkScalar pageHeight = ....; 32 SkScalar pageHeight = ....;
30 SkCanvas* pageCanvas = 33 SkCanvas* pageCanvas =
31 pdfDocument->beginPage(pageWidth, pageHeight); 34 pdfDocument->beginPage(pageWidth, pageHeight);
32 35
33 // ....insert canvas draw commands here.... 36 // ....insert canvas draw commands here....
34 37
35 pdfDocument->endPage(); 38 pdfDocument->endPage();
36 } 39 }
37 return pdfDocument->close(); 40 return pdfDocument->close();
38 } 41 }
OLDNEW
« no previous file with comments | « site/user/api/canvas.md ('k') | src/utils/SkLua.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698