04d7de42c1
Land after http://crrev.com/1359943003 NOTRY=true DOCS_PREVIEW= https://skia.org/user/sample/pdf?cl=1360193002 Review URL: https://codereview.chromium.org/1360193002
1.3 KiB
1.3 KiB
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.
#include "SkDocument.h"
bool WritePDF() {
SkWStream* outputStream = ....;
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();
}
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);
return pdfDocument->close();
}