2015-01-20 18:39:06 +00:00
|
|
|
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?-->
|
|
|
|
|
|
|
|
#include "SkDocument.h"
|
|
|
|
|
|
|
|
bool WritePDF() {
|
2015-09-23 19:50:54 +00:00
|
|
|
SkWStream* outputStream = ....;
|
2015-01-20 18:39:06 +00:00
|
|
|
|
|
|
|
SkAutoTUnref<SkDocument> pdfDocument(
|
|
|
|
SkDocument::CreatePDF(outputStream));
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
2015-09-23 19:50:54 +00:00
|
|
|
|
|
|
|
SkTArray<SkDocument::Attribute> info;
|
|
|
|
info.emplace_back(SkString("Title"), SkString("...."));
|
|
|
|
info.emplace_back(SkString("Author"), SkString("...."));
|
|
|
|
info.emplace_back(SkString("Subject"), SkString("...."));
|
|
|
|
info.emplace_back(SkString("Keywords"), SkString("...."));
|
|
|
|
info.emplace_back(SkString("Creator"), SkString("...."));
|
|
|
|
SkTime::DateTime now;
|
|
|
|
SkTime::GetDateTime(&now);
|
|
|
|
pdfDocument->setMetadata(info, &now, &now);
|
|
|
|
|
2015-01-20 18:39:06 +00:00
|
|
|
return pdfDocument->close();
|
|
|
|
}
|