3
Copyright (c) 2006-2007, BBR Inc. All rights reserved.
5
Permission is hereby granted, free of charge, to any person obtaining
6
a copy of this software and associated documentation files (the
7
"Software"), to deal in the Software without restriction, including
8
without limitation the rights to use, copy, modify, merge, publish,
9
distribute, sublicense, and/or sell copies of the Software, and to
10
permit persons to whom the Software is furnished to do so, subject to
11
the following conditions:
13
The above copyright notice and this permission notice shall be included
14
in all copies or substantial portions of the Software.
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
#include "P2PCatalog.h"
38
P2PDoc::Options P2PDoc::options;
41
P2PDoc::P2PDoc(PDFDoc *orgDocA)
44
catalog = new P2PCatalog(orgDoc->getCatalog(),orgDoc->getXRef());
53
void P2PDoc::output(P2POutputStream *str, int deviceCopies, bool deviceCollate)
61
XRef *xref = orgDoc->getXRef();
63
Dict documentInfo(xref);
67
curtm = localtime(&curtime);
68
strftime(curdate, sizeof(curdate),"D:%Y%m%d%H%M%S%z", curtm);
73
if (options.title != 0) {
74
documentInfo.add(strdup("Title"),(new Object())->initString(new GooString(options.title)));
76
documentInfo.add(strdup("CreationDate"),(new Object())->initString(new GooString(curdate)));
77
documentInfo.add(strdup("ModDate"),(new Object())->initString(new GooString(curdate)));
78
documentInfo.add(strdup("Producer"),(new Object())->initString(new GooString("pdftopdf")));
80
/* Hack to produce "/False". Object::initBool results wrongly in "false" */
81
documentInfo.add(strdup("Trapped"),(new Object())->initName("False"));
83
obj.initDict(&documentInfo);
85
P2PXRef::put(&object);
89
snprintf(version,sizeof(version),"%%PDF-%d.%d\n",
90
orgDoc->getPDFMajorVersion(),orgDoc->getPDFMinorVersion());
92
str->puts("%\0201\0202\0203\0204\n");
93
str->puts("% This file was generated by pdftopdf\n");
96
* output device copies commen
97
* This is not standard, but like PostScript.
99
if (deviceCopies > 0) {
100
str->printf("%%%%PDFTOPDFNumCopies : %d\n",deviceCopies);
101
str->printf("%%%%PDFTOPDFCollate : %s\n",deviceCollate ? "true" : "false");
105
catalog->output(str,options.copies,options.collate);
106
/* output objects that are not output yet. */
107
P2PXRef::flush(str,xref);
109
/* output cross reference */
110
xrefOffset = P2PXRef::output(str);
113
catalog->getNum(&num,&gen);
114
str->puts("trailer\n");
115
str->printf("<< /Size %d /Root %d %d R \n",P2PXRef::getNObjects(),
118
object.getNum(&num,&gen);
119
str->printf(" /Info %d %d R\n",num,gen);
122
str->puts("startxref\n");
123
str->printf("%d\n",xrefOffset);
124
str->puts("%%EOF\n");
127
int P2PDoc::nup(int n, PDFRectangle *box,
128
unsigned int borderFlag, unsigned int layout,
131
if (n == 1) return 0;
143
return catalog->nup(n,box,borderFlag,layout,xpos,ypos);
146
void P2PDoc::select()
148
catalog->select(options.pageSet,options.pageRanges);
151
void P2PDoc::fit(PDFRectangle *box, double zoom)
153
catalog->fit(box,zoom);
156
void P2PDoc::mirror()
161
void P2PDoc::rotate(int orientation)
163
catalog->rotate(orientation);
166
void P2PDoc::position(PDFRectangle *box, int xpos, int ypos)
168
catalog->position(box,xpos,ypos);
171
void P2PDoc::scale(double zoom)
173
catalog->scale(zoom);
176
void P2PDoc::autoRotate(PDFRectangle *box)
178
catalog->autoRotate(box);
181
void P2PDoc::setMediaBox(PDFRectangle *mediaBoxA)
183
catalog->setMediaBox(mediaBoxA);
186
int P2PDoc::getNumberOfPages()
188
return catalog->getNumberOfPages();