Use QPDF::newStream in examples

This commit is contained in:
m-holger 2022-09-26 19:29:26 +01:00 committed by Jay Berkenbilt
parent 9ebabd1953
commit f69ed209d0
6 changed files with 21 additions and 30 deletions

View File

@ -89,15 +89,13 @@ process(
// Create appearance stream for the attachment.
auto ap = QPDFObjectHandle::newStream(
&q,
"0 10 m\n"
"10 0 l\n"
"20 10 l\n"
"10 0 m\n"
"10 20 l\n"
"0 0 20 20 re\n"
"S\n");
auto ap = q.newStream("0 10 m\n"
"10 0 l\n"
"20 10 l\n"
"10 0 m\n"
"10 20 l\n"
"0 0 20 20 re\n"
"S\n");
auto apdict = ap.getDict();
// The following four lines demonstrate the use of the qpdf literal syntax
@ -127,15 +125,13 @@ process(
">>")));
// Generate contents for the page.
auto contents = QPDFObjectHandle::newStream(
&q,
("q\n"
"BT\n"
" 102 700 Td\n"
" /F1 16 Tf\n"
" (Here is an attachment.) Tj\n"
"ET\n"
"Q\n"));
auto contents = q.newStream(("q\n"
"BT\n"
" 102 700 Td\n"
" /F1 16 Tf\n"
" (Here is an attachment.) Tj\n"
"ET\n"
"Q\n"));
// Create the page object.
auto page = QPDFObjectHandle::parse(

View File

@ -139,7 +139,7 @@ createPageContents(QPDF& pdf, std::string const& text)
std::string contents = "BT /F1 24 Tf 72 320 Td (" + text +
") Tj ET\n"
"q 244 0 0 144 184 100 cm /Im1 Do Q\n";
return QPDFObjectHandle::newStream(&pdf, contents);
return pdf.newStream(contents);
}
QPDFObjectHandle
@ -172,7 +172,7 @@ add_page(
std::shared_ptr<QPDFObjectHandle::StreamDataProvider> provider(p);
size_t width = p->getWidth();
size_t height = p->getHeight();
QPDFObjectHandle image = QPDFObjectHandle::newStream(&pdf);
QPDFObjectHandle image = pdf.newStream();
auto image_dict =
// line-break
"<<"

View File

@ -365,8 +365,7 @@ StreamReplacer::registerStream(
// or create objects during write.
char p[1] = {static_cast<char>(this->keys[og])};
std::string p_str(p, 1);
QPDFObjectHandle dp_stream =
QPDFObjectHandle::newStream(this->pdf, p_str);
QPDFObjectHandle dp_stream = this->pdf->newStream(p_str);
// Create /DecodeParms as expected by our fictitious
// /XORDecode filter.
QPDFObjectHandle decode_parms =

View File

@ -75,8 +75,7 @@ main(int argc, char* argv[])
for (auto& page: QPDFPageDocumentHelper(qpdf).getAllPages()) {
// Prepend the buffer to the page's contents
page.addPageContents(
QPDFObjectHandle::newStream(&qpdf, content), true);
page.addPageContents(qpdf.newStream(content), true);
// Double the size of each of the content boxes
doubleBoxSize(page, "/MediaBox");

View File

@ -57,10 +57,8 @@ stamp_page(char const* infile, char const* stampfile, char const* outfile)
// page's original content.
resources.mergeResources("<< /XObject << >> >>"_qpdf);
resources.getKey("/XObject").replaceKey(name, stamp_fo);
ph.addPageContents(
QPDFObjectHandle::newStream(&inpdf, "q\n"), true);
ph.addPageContents(
QPDFObjectHandle::newStream(&inpdf, "\nQ\n" + content), false);
ph.addPageContents(inpdf.newStream("q\n"), true);
ph.addPageContents(inpdf.newStream("\nQ\n" + content), false);
}
// Copy the annotations and form fields from the original page
// to the new page. For more efficiency when copying multiple

View File

@ -22,8 +22,7 @@ usage()
static QPDFObjectHandle
createPageContents(QPDF& pdf, std::string const& text)
{
std::string contents = "BT /F1 15 Tf 72 720 Td (" + text + ") Tj ET\n";
return QPDFObjectHandle::newStream(&pdf, contents);
return pdf.newStream("BT /F1 15 Tf 72 720 Td (" + text + ") Tj ET\n");
}
QPDFObjectHandle