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.
|
|
|
|
|
2016-03-20 14:07:11 +00:00
|
|
|
<!--?prettify lang=cc?-->
|
2015-01-20 18:39:06 +00:00
|
|
|
|
|
|
|
#include "SkDocument.h"
|
|
|
|
|
2016-03-20 14:07:11 +00:00
|
|
|
bool WritePDF(SkWStream* outputStream) {
|
2016-05-03 19:10:04 +00:00
|
|
|
SkDocument::PDFMetadata metadata;
|
|
|
|
metadata.fCreator = "creator....";
|
|
|
|
metadata.fTitle = "title...";
|
|
|
|
metadata.fAuthor = "author...";
|
|
|
|
metadata.fSubject = "subject...";
|
|
|
|
metadata.fKeywords = "keywords...";
|
|
|
|
metadata.fCreator = "creator...";
|
|
|
|
SkTime::DateTime now = get_current_date_and_time();
|
|
|
|
metadata.fCreation.fEnabled = true;
|
|
|
|
metadata.fCreation.fDateTime = now;
|
|
|
|
metadata.fModified.fEnabled = true;
|
|
|
|
metadata.fModified.fDateTime = now;
|
|
|
|
sk_sp<SkDocument> pdfDocument(SkDocument::MakePDF(
|
|
|
|
outputStream, SK_ScalarDefaultRasterDPI, metadata,
|
|
|
|
nullptr, true);
|
|
|
|
assert(pdfDocument);
|
2015-01-20 18:39:06 +00:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|