Created
August 1, 2017 12:37
-
-
Save sahilarora535/4c6ee8fa773d42b8b556568decdd396b to your computer and use it in GitHub Desktop.
Code to generate a PCLm file using QPDF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#include <qpdf/QPDF.hh> | |
#include <qpdf/QPDFObjectHandle.hh> | |
#include <qpdf/QPDFWriter.hh> | |
int main() { | |
QPDF pdf; | |
pdf.emptyPDF(); | |
QPDFObjectHandle unreferenced_obj = QPDFObjectHandle::newStream(&pdf); | |
QPDFObjectHandle page = QPDFObjectHandle::parse( | |
"<<" | |
" /Type /Page" | |
" /Resources <<" | |
" /XObject << >> " | |
" >>" | |
" /MediaBox null " | |
" /Contents null " | |
">>"); | |
page.replaceKey("/Contents",QPDFObjectHandle::newStream(&pdf, "PAGE CONTENT STREAM\n")); // data will be provided later | |
pdf.addPage(page, false); | |
unreferenced_obj.replaceStreamData("UNREFERENCED STREAM\n",QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); | |
QPDFWriter output(pdf, NULL); | |
output.setPCLm(true); | |
output.write(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The PCLm produced by this does not contain the unreferenced stream. The final PCLm produced looks like this: