2c9c469cc9
Motivation: while experimenting with serializing images immediately, I would like to keep serializing metadata first. TBR=djsollen@google.com GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1780463008 Review URL: https://codereview.chromium.org/1780463008
39 lines
1.3 KiB
Markdown
39 lines
1.3 KiB
Markdown
Using Skia's PDF Backend
|
|
========================
|
|
|
|
Here is an example of using Skia's PDF backend in the recommended way:
|
|
via the SkDocument and SkCanvas APIs.
|
|
|
|
<!--?prettify lang=cc?-->
|
|
|
|
#include "SkDocument.h"
|
|
|
|
bool WritePDF(SkWStream* outputStream) {
|
|
sk_sp<SkDocument> pdfDocument(SkDocument::CreatePDF(outputStream));
|
|
typedef SkDocument::Attribute Attr;
|
|
Attr info[] = {
|
|
Attr(SkString("Title"), SkString("....")),
|
|
Attr(SkString("Author"), SkString("....")),
|
|
Attr(SkString("Subject"), SkString("....")),
|
|
Attr(SkString("Keywords"), SkString("....")),
|
|
Attr(SkString("Creator"), SkString("....")),
|
|
};
|
|
int infoCount = sizeof(info) / sizeof(info[0]);
|
|
SkTime::DateTime now;
|
|
SkTime::GetDateTime(&now);
|
|
pdfDocument->setMetadata(info, infoCount, &now, &now);
|
|
|
|
int numberOfPages = ....;
|
|
for (int page = 0; page < numberOfPages; ++page) {
|
|
SkScalar pageWidth = ....;
|
|
SkScalar pageHeight = ....;
|
|
SkCanvas* pageCanvas =
|
|
pdfDocument->beginPage(pageWidth, pageHeight);
|
|
|
|
// ....insert canvas draw commands here....
|
|
|
|
pdfDocument->endPage();
|
|
}
|
|
return pdfDocument->close();
|
|
}
|