Commit 0089357d authored by Thomas Freitag's avatar Thomas Freitag Committed by Albert Astals Cid

pdfseparate: Produce PDF/X conformant pdf pages if the original PDF was PDF/X conformant.

parent be62a4f2
......@@ -603,22 +603,38 @@ int PDFDoc::savePageAs(GooString *name, int pageNo)
}
outStr = new FileOutStream(f,0);
yRef = new XRef();
yRef = new XRef(getXRef()->getTrailerDict());
countRef = new XRef();
yRef->add(0, 65535, 0, gFalse);
writeHeader(outStr, getPDFMajorVersion(), getPDFMinorVersion());
// get and mark optional content groups
OCGs *ocgs = getCatalog()->getOptContentConfig();
if (ocgs != NULL) {
Object catDict, optContentProps;
getXRef()->getCatalog(&catDict);
catDict.dictLookup("OCProperties", &optContentProps);
Dict *pageDict = optContentProps.getDict();
markPageObjects(pageDict, yRef, countRef, 0);
catDict.free();
optContentProps.free();
// get and mark info dict
Object infoObj;
getXRef()->getDocInfo(&infoObj);
if (infoObj.isDict()) {
Dict *infoDict = infoObj.getDict();
markPageObjects(infoDict, yRef, countRef, 0);
Object *trailerObj = getXRef()->getTrailerDict();
if (trailerObj->isDict()) {
Dict *trailerDict = trailerObj->getDict();
Object ref;
trailerDict->lookupNF("Info", &ref);
if (ref.isRef()) {
yRef->add(ref.getRef().num, ref.getRef().gen, 0, gTrue);
if (getXRef()->getEntry(ref.getRef().num)->type == xrefEntryCompressed) {
yRef->getEntry(ref.getRef().num)->type = xrefEntryCompressed;
}
}
ref.free();
}
}
infoObj.free();
// get and mark output intents etc.
Object catObj;
getXRef()->getCatalog(&catObj);
Dict *catDict = catObj.getDict();
markPageObjects(catDict, yRef, countRef, 0);
Dict *pageDict = page.getDict();
markPageObjects(pageDict, yRef, countRef, 0);
......@@ -627,24 +643,20 @@ int PDFDoc::savePageAs(GooString *name, int pageNo)
yRef->add(rootNum,0,outStr->getPos(),gTrue);
outStr->printf("%d 0 obj\n", rootNum);
outStr->printf("<< /Type /Catalog /Pages %d 0 R", rootNum + 1);
if (ocgs != NULL) {
Object catDict, optContentProps;
getXRef()->getCatalog(&catDict);
catDict.dictLookup("OCProperties", &optContentProps);
outStr->printf(" /OCProperties <<");
Dict *pageDict = optContentProps.getDict();
for (int n = 0; n < pageDict->getLength(); n++) {
if (n > 0) outStr->printf(" ");
const char *key = pageDict->getKey(n);
Object value; pageDict->getValNF(n, &value);
for (int j = 0; j < catDict->getLength(); j++) {
const char *key = catDict->getKey(j);
if (strcmp(key, "Type") != 0 &&
strcmp(key, "Catalog") != 0 &&
strcmp(key, "Pages") != 0)
{
if (j > 0) outStr->printf(" ");
Object value; catDict->getValNF(j, &value);
outStr->printf("/%s ", key);
writeObject(&value, NULL, outStr, getXRef(), 0);
value.free();
}
outStr->printf(" >> ");
catDict.free();
optContentProps.free();
}
catObj.free();
outStr->printf(">>\nendobj\n");
objectsCount++;
......@@ -1293,6 +1305,9 @@ void PDFDoc::replacePageDict(int pageNo, int rotate,
cropBoxObj->arrayAdd(cllx);
cropBoxObj->arrayAdd(clly);
pageDict->add(copyString("CropBox"), cropBoxObj);
pageDict->add(copyString("TrimBox"), cropBoxObj);
} else {
pageDict->add(copyString("TrimBox"), mediaBoxObj);
}
Object *rotateObj = new Object();
rotateObj->initInt(rotate);
......
......@@ -19,7 +19,8 @@
// Copyright (C) 2007-2008 Julien Rebetez <julienr@svn.gnome.org>
// Copyright (C) 2007 Carlos Garcia Campos <carlosgc@gnome.org>
// Copyright (C) 2009, 2010 Ilya Gorenbein <igorenbein@finjan.com>
// Copyright 2010 Hib Eris <hib@hiberis.nl>
// Copyright (C) 2010 Hib Eris <hib@hiberis.nl>
// Copyright (C) 2012 Thomas Freitag <Thomas.Freitag@kabelmail.de>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
......@@ -271,6 +272,12 @@ XRef::XRef() {
init();
}
XRef::XRef(Object *trailerDictA) {
init();
if (trailerDictA->isDict())
trailerDict.initDict(trailerDictA->getDict());
}
XRef::XRef(BaseStream *strA, Guint pos, Guint mainXRefEntriesOffsetA, GBool *wasReconstructed, GBool reconstruct) {
Object obj;
......
......@@ -18,7 +18,8 @@
// Copyright (C) 2007-2008 Julien Rebetez <julienr@svn.gnome.org>
// Copyright (C) 2007 Carlos Garcia Campos <carlosgc@gnome.org>
// Copyright (C) 2010 Ilya Gorenbein <igorenbein@finjan.com>
// Copyright 2010 Hib Eris <hib@hiberis.nl>
// Copyright (C) 2010 Hib Eris <hib@hiberis.nl>
// Copyright (C) 2012 Thomas Freitag <Thomas.Freitag@kabelmail.de>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
......@@ -66,6 +67,8 @@ public:
// Constructor, create an empty XRef, used for PDF writing
XRef();
// Constructor, create an empty XRef but with info dict, used for PDF writing
XRef(Object *trailerDictA);
// Constructor. Read xref table from stream.
XRef(BaseStream *strA, Guint pos, Guint mainXRefEntriesOffsetA = 0, GBool *wasReconstructed = NULL, GBool reconstruct = false);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment