2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-06-13 07:32:22 +00:00

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,9 +89,7 @@ process(
// Create appearance stream for the attachment. // Create appearance stream for the attachment.
auto ap = QPDFObjectHandle::newStream( auto ap = q.newStream("0 10 m\n"
&q,
"0 10 m\n"
"10 0 l\n" "10 0 l\n"
"20 10 l\n" "20 10 l\n"
"10 0 m\n" "10 0 m\n"
@ -127,9 +125,7 @@ process(
">>"))); ">>")));
// Generate contents for the page. // Generate contents for the page.
auto contents = QPDFObjectHandle::newStream( auto contents = q.newStream(("q\n"
&q,
("q\n"
"BT\n" "BT\n"
" 102 700 Td\n" " 102 700 Td\n"
" /F1 16 Tf\n" " /F1 16 Tf\n"

View File

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

View File

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

View File

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

View File

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

View File

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