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

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

Issue 1780463008: SkPDF: metadata first (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 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 | « no previous file | tests/PDFMetadataAttributeTest.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?--> 7 <!--?prettify lang=cc?-->
8 8
9 #include "SkDocument.h" 9 #include "SkDocument.h"
10 10
11 bool WritePDF() { 11 bool WritePDF(SkWStream* outputStream) {
12 SkWStream* outputStream = ....; 12 sk_sp<SkDocument> pdfDocument(SkDocument::CreatePDF(outputStream));
13 13 typedef SkDocument::Attribute Attr;
14 SkAutoTUnref<SkDocument> pdfDocument( 14 Attr info[] = {
15 SkDocument::CreatePDF(outputStream)); 15 Attr(SkString("Title"), SkString("....")),
16 Attr(SkString("Author"), SkString("....")),
17 Attr(SkString("Subject"), SkString("....")),
18 Attr(SkString("Keywords"), SkString("....")),
19 Attr(SkString("Creator"), SkString("....")),
20 };
21 int infoCount = sizeof(info) / sizeof(info[0]);
22 SkTime::DateTime now;
23 SkTime::GetDateTime(&now);
24 pdfDocument->setMetadata(info, infoCount, &now, &now);
16 25
17 int numberOfPages = ....; 26 int numberOfPages = ....;
18 for (int page = 0; page < numberOfPages; ++page) { 27 for (int page = 0; page < numberOfPages; ++page) {
19 SkScalar pageWidth = ....; 28 SkScalar pageWidth = ....;
20 SkScalar pageHeight = ....; 29 SkScalar pageHeight = ....;
21 SkCanvas* pageCanvas = 30 SkCanvas* pageCanvas =
22 pdfDocument->beginPage(pageWidth, pageHeight); 31 pdfDocument->beginPage(pageWidth, pageHeight);
23 32
24 // ....insert canvas draw commands here.... 33 // ....insert canvas draw commands here....
25 34
26 pdfDocument->endPage(); 35 pdfDocument->endPage();
27 } 36 }
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(); 37 return pdfDocument->close();
40 } 38 }
OLDNEW
« no previous file with comments | « no previous file | tests/PDFMetadataAttributeTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698