blob: 93766ee2cfc58e3c020970e78320c08c8b3acdbd [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// Copyright 2014 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Tom Sepez1ed8a212015-05-11 15:25:39 -07007#include "../../public/fpdf_ppo.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07008#include "../include/fsdk_define.h"
Bo Xufdc00a72014-10-28 23:03:33 -07009#include "../include/fpdfxfa/fpdfxfa_doc.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070010
11class CPDF_PageOrganizer
12{
13public:
Tom Sepez2f2ffec2015-07-23 14:42:09 -070014 CPDF_PageOrganizer();
15 ~CPDF_PageOrganizer();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070016
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070017public:
Tom Sepez2f2ffec2015-07-23 14:42:09 -070018 FX_BOOL PDFDocInit(CPDF_Document *pDestPDFDoc, CPDF_Document *pSrcPDFDoc);
19 FX_BOOL ExportPage(CPDF_Document *pSrcPDFDoc, CFX_WordArray* nPageNum, CPDF_Document *pDestPDFDoc, int nIndex);
20 CPDF_Object* PageDictGetInheritableTag(CPDF_Dictionary *pDict, CFX_ByteString nSrctag);
21 FX_BOOL UpdateReference(CPDF_Object *pObj, CPDF_Document *pDoc, CFX_MapPtrToPtr* pMapPtrToPtr);
22 int GetNewObjId(CPDF_Document *pDoc, CFX_MapPtrToPtr* pMapPtrToPtr, CPDF_Reference *pRef);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070023
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070024};
25
26
27CPDF_PageOrganizer::CPDF_PageOrganizer()
28{
29
30}
31
32CPDF_PageOrganizer::~CPDF_PageOrganizer()
33{
34
35}
36
37FX_BOOL CPDF_PageOrganizer::PDFDocInit(CPDF_Document *pDestPDFDoc, CPDF_Document *pSrcPDFDoc)
38{
Tom Sepez2f2ffec2015-07-23 14:42:09 -070039 if(!pDestPDFDoc || !pSrcPDFDoc)
40 return false;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070041
Tom Sepez2f2ffec2015-07-23 14:42:09 -070042 CPDF_Dictionary* pNewRoot = pDestPDFDoc->GetRoot();
43 if(!pNewRoot) return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070044
Tom Sepez2f2ffec2015-07-23 14:42:09 -070045 //Set the document information////////////////////////////////////////////
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070046
Tom Sepez2f2ffec2015-07-23 14:42:09 -070047 CPDF_Dictionary* DInfoDict = pDestPDFDoc->GetInfo();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070048
Tom Sepez2f2ffec2015-07-23 14:42:09 -070049 if(!DInfoDict)
50 return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070051
Tom Sepez2f2ffec2015-07-23 14:42:09 -070052 CFX_ByteString producerstr;
53 producerstr.Format("PDFium");
54 DInfoDict->SetAt("Producer", new CPDF_String(producerstr));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070055
Tom Sepez2f2ffec2015-07-23 14:42:09 -070056 //Set type////////////////////////////////////////////////////////////////
57 CFX_ByteString cbRootType = pNewRoot->GetString("Type","");
58 if( cbRootType.Equal("") )
59 {
60 pNewRoot->SetAt("Type", new CPDF_Name("Catalog"));
61 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070062
Tom Sepez2f2ffec2015-07-23 14:42:09 -070063 CPDF_Dictionary* pNewPages = (CPDF_Dictionary*)(pNewRoot->GetElement("Pages")? pNewRoot->GetElement("Pages")->GetDirect() : NULL);
64 if(!pNewPages)
65 {
66 pNewPages = new CPDF_Dictionary;
67 FX_DWORD NewPagesON = pDestPDFDoc->AddIndirectObject(pNewPages);
68 pNewRoot->SetAt("Pages", new CPDF_Reference(pDestPDFDoc, NewPagesON));
69 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070070
Tom Sepez2f2ffec2015-07-23 14:42:09 -070071 CFX_ByteString cbPageType = pNewPages->GetString("Type","");
72 if(cbPageType.Equal(""))
73 {
74 pNewPages->SetAt("Type", new CPDF_Name("Pages"));
75 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070076
Tom Sepez2f2ffec2015-07-23 14:42:09 -070077 CPDF_Array* pKeysArray = pNewPages->GetArray("Kids");
78 if(pKeysArray == NULL)
79 {
80 CPDF_Array* pNewKids = new CPDF_Array;
81 FX_DWORD Kidsobjnum = -1;
82 Kidsobjnum = pDestPDFDoc->AddIndirectObject(pNewKids);//, Kidsobjnum, Kidsgennum);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070083
Tom Sepez2f2ffec2015-07-23 14:42:09 -070084 pNewPages->SetAt("Kids", new CPDF_Reference(pDestPDFDoc, Kidsobjnum));//, Kidsgennum));
85 pNewPages->SetAt("Count", new CPDF_Number(0));
86 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070087
Tom Sepez2f2ffec2015-07-23 14:42:09 -070088 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070089}
90
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070091FX_BOOL CPDF_PageOrganizer::ExportPage(CPDF_Document *pSrcPDFDoc, CFX_WordArray* nPageNum,
Tom Sepez2f2ffec2015-07-23 14:42:09 -070092 CPDF_Document *pDestPDFDoc,int nIndex)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070093{
Tom Sepez2f2ffec2015-07-23 14:42:09 -070094 int curpage =nIndex;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070095
Tom Sepez2f2ffec2015-07-23 14:42:09 -070096 CFX_MapPtrToPtr* pMapPtrToPtr = new CFX_MapPtrToPtr;
97 pMapPtrToPtr->InitHashTable(1001);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070098
Tom Sepez2f2ffec2015-07-23 14:42:09 -070099 for(int i=0; i<nPageNum->GetSize(); i++)
100 {
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700101
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700102 CPDF_Dictionary* pCurPageDict = pDestPDFDoc->CreateNewPage(curpage);
103 CPDF_Dictionary* pSrcPageDict = pSrcPDFDoc->GetPage(nPageNum->GetAt(i)-1);
104 if(!pSrcPageDict || !pCurPageDict)
105 {
106 delete pMapPtrToPtr;
107 return FALSE;
108 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700109
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700110 // Clone the page dictionary///////////
111 FX_POSITION SrcPos = pSrcPageDict->GetStartPos();
112 while (SrcPos)
113 {
114 CFX_ByteString cbSrcKeyStr;
115 CPDF_Object* pObj = pSrcPageDict->GetNextElement(SrcPos, cbSrcKeyStr);
116 if(cbSrcKeyStr.Compare(("Type")) && cbSrcKeyStr.Compare(("Parent")))
117 {
118 if(pCurPageDict->KeyExist(cbSrcKeyStr))
119 pCurPageDict->RemoveAt(cbSrcKeyStr);
120 pCurPageDict->SetAt(cbSrcKeyStr, pObj->Clone());
121 }
122 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700123
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700124 //inheritable item///////////////////////
125 CPDF_Object* pInheritable = NULL;
126 //1 MediaBox //required
127 if(!pCurPageDict->KeyExist("MediaBox"))
128 {
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700129
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700130 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "MediaBox");
131 if(!pInheritable)
132 {
133 //Search the "CropBox" from source page dictionary, if not exists,we take the letter size.
134 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "CropBox");
135 if(pInheritable)
136 pCurPageDict->SetAt("MediaBox", pInheritable->Clone());
137 else
138 {
139 //Make the default size to be letter size (8.5'x11')
140 CPDF_Array* pArray = new CPDF_Array;
141 pArray->AddNumber(0);
142 pArray->AddNumber(0);
143 pArray->AddNumber(612);
144 pArray->AddNumber(792);
145 pCurPageDict->SetAt("MediaBox", pArray);
146 }
147 }
148 else
149 pCurPageDict->SetAt("MediaBox", pInheritable->Clone());
150 }
151 //2 Resources //required
152 if(!pCurPageDict->KeyExist("Resources"))
153 {
154 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "Resources");
155 if(!pInheritable)
156 {
157 delete pMapPtrToPtr;
158 return FALSE;
159 }
160 pCurPageDict->SetAt("Resources", pInheritable->Clone());
161 }
162 //3 CropBox //Optional
163 if(!pCurPageDict->KeyExist("CropBox"))
164 {
165 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "CropBox");
166 if(pInheritable)
167 pCurPageDict->SetAt("CropBox", pInheritable->Clone());
168 }
169 //4 Rotate //Optional
170 if(!pCurPageDict->KeyExist("Rotate"))
171 {
172 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "Rotate");
173 if(pInheritable)
174 pCurPageDict->SetAt("Rotate", pInheritable->Clone());
175 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700176
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700177 /////////////////////////////////////////////
178 //Update the reference
179 FX_DWORD dwOldPageObj = pSrcPageDict->GetObjNum();
180 FX_DWORD dwNewPageObj = pCurPageDict->GetObjNum();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700181
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700182 pMapPtrToPtr->SetAt((void*)(uintptr_t)dwOldPageObj, (void*)(uintptr_t)dwNewPageObj);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700183
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700184 UpdateReference(pCurPageDict, pDestPDFDoc, pMapPtrToPtr);
185 curpage++;
186 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700187
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700188 delete pMapPtrToPtr;
189 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700190}
191
192CPDF_Object* CPDF_PageOrganizer::PageDictGetInheritableTag(CPDF_Dictionary *pDict, CFX_ByteString nSrctag)
193{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700194 if(!pDict || !pDict->KeyExist("Type") || nSrctag.IsEmpty())
195 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700196
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700197 CPDF_Object* pType = pDict->GetElement("Type")->GetDirect();
198 if(!pType || pType->GetType() != PDFOBJ_NAME) return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700199
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700200 if(pType->GetString().Compare("Page")) return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700201
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700202 if(!pDict->KeyExist("Parent")) return NULL;
203 CPDF_Object* pParent = pDict->GetElement("Parent")->GetDirect();
204 if(!pParent || pParent->GetType() != PDFOBJ_DICTIONARY) return NULL;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700205
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700206 CPDF_Dictionary* pp = (CPDF_Dictionary*)pParent;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700207
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700208 if(pDict->KeyExist((const char*)nSrctag))
209 return pDict->GetElement((const char*)nSrctag);
210 while (pp)
211 {
212 if (pp->KeyExist((const char*)nSrctag))
213 return pp->GetElement((const char*)nSrctag);
214 if (pp->KeyExist("Parent"))
215 {
216 pp = (CPDF_Dictionary*)pp->GetElement("Parent")->GetDirect();
217 if (pp->GetType() == PDFOBJ_NULL)
218 break;
219 }
220 else
221 break;
222 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700223
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700224 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700225}
226
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700227FX_BOOL CPDF_PageOrganizer::UpdateReference(CPDF_Object *pObj, CPDF_Document *pDoc,
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700228 CFX_MapPtrToPtr* pMapPtrToPtr)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700229{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700230 switch (pObj->GetType())
231 {
232 case PDFOBJ_REFERENCE:
233 {
234 CPDF_Reference* pReference = (CPDF_Reference*)pObj;
235 int newobjnum = GetNewObjId(pDoc, pMapPtrToPtr, pReference);
236 if (newobjnum == 0) return FALSE;
237 pReference->SetRef(pDoc, newobjnum);//, 0);
238 break;
239 }
240 case PDFOBJ_DICTIONARY:
241 {
242 CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700243
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700244 FX_POSITION pos = pDict->GetStartPos();
245 while(pos)
246 {
247 CFX_ByteString key("");
248 CPDF_Object* pNextObj = pDict->GetNextElement(pos, key);
249 if (!FXSYS_strcmp(key, "Parent") || !FXSYS_strcmp(key, "Prev") || !FXSYS_strcmp(key, "First"))
250 continue;
251 if(pNextObj)
252 {
253 if(!UpdateReference(pNextObj, pDoc, pMapPtrToPtr))
254 pDict->RemoveAt(key);
255 }
256 else
257 return FALSE;
258 }
259 break;
260 }
261 case PDFOBJ_ARRAY:
262 {
263 CPDF_Array* pArray = (CPDF_Array*)pObj;
264 FX_DWORD count = pArray->GetCount();
265 for(FX_DWORD i = 0; i < count; i ++)
266 {
267 CPDF_Object* pNextObj = pArray->GetElement(i);
268 if(pNextObj)
269 {
270 if(!UpdateReference(pNextObj, pDoc, pMapPtrToPtr))
271 return FALSE;
272 }
273 else
274 return FALSE;
275 }
276 break;
277 }
278 case PDFOBJ_STREAM:
279 {
280 CPDF_Stream* pStream = (CPDF_Stream*)pObj;
281 CPDF_Dictionary* pDict = pStream->GetDict();
282 if(pDict)
283 {
284 if(!UpdateReference(pDict, pDoc, pMapPtrToPtr))
285 return FALSE;
286 }
287 else
288 return FALSE;
289 break;
290 }
291 default: break;
292 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700293
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700294 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700295}
296
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700297int CPDF_PageOrganizer::GetNewObjId(CPDF_Document *pDoc, CFX_MapPtrToPtr* pMapPtrToPtr,
298 CPDF_Reference *pRef)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700299{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700300 if(!pRef)
301 return 0;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700302
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700303 size_t dwObjnum = pRef->GetRefObjNum();
304 size_t dwNewObjNum = 0;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700305
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700306 pMapPtrToPtr->Lookup((void*)dwObjnum, (void*&)dwNewObjNum);
307 if(dwNewObjNum)
308 {
309 return (int)dwNewObjNum;
310 }
Jun Fang4cf36952014-09-08 11:27:02 -0700311
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700312 CPDF_Object* pDirect = pRef->GetDirect();
313 if(!pDirect)
314 {
315 return 0;
316 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700317
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700318 CPDF_Object* pClone = pDirect->Clone();
319 if(!pClone)
320 {
321 return 0;
322 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700323
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700324 if(pClone->GetType() == PDFOBJ_DICTIONARY)
325 {
326 CPDF_Dictionary* pDictClone = (CPDF_Dictionary*)pClone;
327 if(pDictClone->KeyExist("Type"))
328 {
329 CFX_ByteString strType = pDictClone->GetString("Type");
330 if(!FXSYS_stricmp(strType, "Pages"))
331 {
332 pDictClone->Release();
333 return 4;
334 }
335 else if(!FXSYS_stricmp(strType, "Page"))
336 {
337 pDictClone->Release();
338 return 0;
339 }
340 }
341 }
342
343 dwNewObjNum = pDoc->AddIndirectObject(pClone);
344 pMapPtrToPtr->SetAt((void*)dwObjnum, (void*)dwNewObjNum);
345 if(!UpdateReference(pClone, pDoc, pMapPtrToPtr))
346 {
347 pClone->Release();
348 return 0;
349 }
350
351 return (int)dwNewObjNum;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700352}
353
354FPDF_BOOL ParserPageRangeString(CFX_ByteString rangstring, CFX_WordArray* pageArray,int nCount)
355{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700356 if(rangstring.GetLength() != 0)
357 {
358 rangstring.Remove(' ');
359 int nLength = rangstring.GetLength();
360 CFX_ByteString cbCompareString("0123456789-,");
361 for(int i=0; i<nLength; i++)
362 {
363 if(cbCompareString.Find(rangstring[i]) == -1)
364 return FALSE;
365 }
366 CFX_ByteString cbMidRange;
367 int nStringFrom = 0;
368 int nStringTo=0;
369 while(nStringTo < nLength)
370 {
371 nStringTo = rangstring.Find(',',nStringFrom);
372 if(nStringTo == -1)
373 {
374 nStringTo = nLength;
375 }
376 cbMidRange = rangstring.Mid(nStringFrom,nStringTo-nStringFrom);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700377
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700378 int nMid = cbMidRange.Find('-');
379 if(nMid == -1)
380 {
381 long lPageNum = atol(cbMidRange);
382 if(lPageNum <= 0 || lPageNum > nCount)
383 return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700384
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700385 pageArray->Add((FX_WORD)lPageNum);
386 }
387 else
388 {
389 int nStartPageNum = atol(cbMidRange.Mid(0,nMid));
390 if (nStartPageNum ==0)
391 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700392
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700393 nMid = nMid+1;
394 int nEnd = cbMidRange.GetLength()-nMid;
395 if (nEnd ==0)
396 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700397
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700398 int nEndPageNum = atol(cbMidRange.Mid(nMid,nEnd));
399 if (nStartPageNum < 0 ||nStartPageNum >nEndPageNum|| nEndPageNum > nCount)
400 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700401
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700402 for (int nIndex = nStartPageNum; nIndex <= nEndPageNum; ++nIndex)
403 pageArray->Add(nIndex);
404 }
405 nStringFrom = nStringTo + 1;
406 }
407 }
408 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700409}
410
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700411DLLEXPORT FPDF_BOOL STDCALL FPDF_ImportPages(FPDF_DOCUMENT dest_doc,FPDF_DOCUMENT src_doc,
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700412 FPDF_BYTESTRING pagerange, int index)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700413{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700414 if(dest_doc == NULL || src_doc == NULL )
415 return FALSE;
416 CFX_WordArray pageArray;
417 CPDFXFA_Document* pSrcDoc = (CPDFXFA_Document*)src_doc;
418 CPDF_Document* pSrcPDFDoc = pSrcDoc->GetPDFDoc();
419 int nCount = pSrcPDFDoc->GetPageCount();
420 if(pagerange)
421 {
422 if(ParserPageRangeString(pagerange,&pageArray,nCount) == FALSE)
423 return FALSE;
424 }
425 else
426 {
427 for(int i=1; i<=nCount; i++)
428 {
429 pageArray.Add(i);
430 }
431 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700432
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700433 CPDFXFA_Document* pDestDoc = (CPDFXFA_Document*)dest_doc;
434 CPDF_Document* pDestPDFDoc = pDestDoc->GetPDFDoc();
435 CPDF_PageOrganizer pageOrg;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700436
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700437 pageOrg.PDFDocInit(pDestPDFDoc,pSrcPDFDoc);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700438
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700439 if(pageOrg.ExportPage(pSrcPDFDoc,&pageArray,pDestPDFDoc,index))
440 return TRUE;
441 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700442}
443
444DLLEXPORT FPDF_BOOL STDCALL FPDF_CopyViewerPreferences(FPDF_DOCUMENT dest_doc, FPDF_DOCUMENT src_doc)
445{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700446 if(src_doc == NULL || dest_doc == NULL)
447 return false;
448 CPDFXFA_Document* pSrcDoc = (CPDFXFA_Document*)src_doc;
449 CPDF_Document* pSrcPDFDoc = pSrcDoc->GetPDFDoc();
450 CPDF_Dictionary* pSrcDict = pSrcPDFDoc->GetRoot();
451 pSrcDict = pSrcDict->GetDict(FX_BSTRC("ViewerPreferences"));
452 if(!pSrcDict)
453 return FALSE;
454 CPDFXFA_Document* pDstDoc = (CPDFXFA_Document*)dest_doc;
455 CPDF_Document* pDstPDFDoc = pDstDoc->GetPDFDoc();
456 CPDF_Dictionary* pDstDict = pDstPDFDoc->GetRoot();
457 if(!pDstDict)
458 return FALSE;
459 pDstDict->SetAt(FX_BSTRC("ViewerPreferences"), pSrcDict->Clone(TRUE));
460 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700461}
462