EStatusCode UseAsXObjects()
{
	PDFWriter pdfWriter;
	EStatusCode status;

	do
	{
		status = pdfWriter.StartPDF(scBasePath + "UseAsXObjects.PDF",ePDFVersion13);
		if(status != eSuccess)
			break;

		// creating XObjects for all pages of XObjectContent.pdf (2 pages)
		EStatusCodeAndObjectIDTypeList result = pdfWriter.CreateFormXObjectsFromPDF(scBasePath + "XObjectContent.PDF",PDFPageRange(),ePDFPageBoxMediaBox);
		if(result.first != eSuccess)
		{
			status = eFailure;
			break;
		}

		// determine page IDs
		ObjectIDTypeList::iterator it = result.second.begin();
		ObjectIDType firstPageID = *it;
		++it;
		ObjectIDType secondPageID = *it;

		// create a page using both xobjects
		PDFPage* page = new PDFPage();
		page->SetMediaBox(PDFRectangle(0,0,595,842));

		PageContentContext* contentContext = pdfWriter.StartPageContentContext(page);

		// place the first page in the top left corner of the document
		contentContext->q();
		contentContext->cm(0.5,0,0,0.5,0,421);
		contentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(firstPageID));
		contentContext->Q();
		
		// draw a rectangle around the page bounds
		contentContext->G(0);
		contentContext->w(1);
		contentContext->re(0,421,297.5,421);
		contentContext->S();


		// place the second page in the bottom right corner of the document
		contentContext->q();
		contentContext->cm(0.5,0,0,0.5,297.5,0);
		contentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(secondPageID));
		contentContext->Q();

		// draw a rectangle around the page bounds
		contentContext->G(0);
		contentContext->w(1);
		contentContext->re(297.5,0,297.5,421);
		contentContext->S();


		status = pdfWriter.EndPageContentContext(contentContext);
		if(status != eSuccess)
			break;

		status = pdfWriter.WritePageAndRelease(page);
		if(status != eSuccess)
			break;


		// appending pages 0,1,2,3 of BasicTIFFImagesTest.PDF
		PDFPageRange selectivePageRange;
		selectivePageRange.mType = PDFPageRange::eRangeTypeSpecific;
		selectivePageRange.mSpecificRanges.push_back(ULongAndULong(0,3));

		result = pdfWriter.CreateFormXObjectsFromPDF(scBasePath + "BasicTIFFImagesTest.PDF",selectivePageRange,ePDFPageBoxMediaBox);
		if(result.first != eSuccess)
		{
			status = eFailure;
			break;
		}

		page = new PDFPage();
		page->SetMediaBox(PDFRectangle(0,0,595,842));

		contentContext = pdfWriter.StartPageContentContext(page);

		// placing them in all 4 corners of the 2nd page [going left right, top bottom]
		it = result.second.begin();
		contentContext->q();
		contentContext->cm(0.5,0,0,0.5,0,421);
		contentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(*it));
		contentContext->Q();
		
		++it;
		contentContext->q();
		contentContext->cm(0.5,0,0,0.5,297.5,421);
		contentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(*it));
		contentContext->Q();

		++it;
		contentContext->q();
		contentContext->cm(0.5,0,0,0.5,0,0);
		contentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(*it));
		contentContext->Q();

		++it;
		contentContext->q();
		contentContext->cm(0.5,0,0,0.5,297.5,0);
		contentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(*it));
		contentContext->Q();


		status = pdfWriter.EndPageContentContext(contentContext);
		if(status != eSuccess)
			break;

		status = pdfWriter.WritePageAndRelease(page);
		if(status != eSuccess)
			break;

		status = pdfWriter.EndPDF();
		if(status != eSuccess)
			break;

	}while(false);


	if(eSuccess == status)
		cout<<"Succeeded in creating UseAsXObjects.PDF file\n";
	else
		cout<<"Failed in creating UseAsXObjects.PDF file\n";

	return status;
}
EStatusCode PDFEmbedTest::Run(const TestConfiguration& inTestConfiguration)
{
	EStatusCode status;
	PDFWriter pdfWriter;

	do
	{
		status = pdfWriter.StartPDF(RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"PDFEmbedTest.pdf"),ePDFVersion13);
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed to start PDF\n";
			break;
		}	

		// Create XObjects from PDF to embed
		EStatusCodeAndObjectIDTypeList result = pdfWriter.CreateFormXObjectsFromPDF(
                                                        RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TestMaterials/XObjectContent.PDF"),PDFPageRange(),ePDFPageBoxMediaBox);
		if(result.first != PDFHummus::eSuccess)
		{
			cout<<"failed to create PDF XObjects from PDF file\n";
			status = result.first;
			break;
		}

		PDFPage* page = new PDFPage();
		page->SetMediaBox(PDFRectangle(0,0,595,842));

		PageContentContext* contentContext = pdfWriter.StartPageContentContext(page);

		// place the first page in the top left corner of the document
		contentContext->q();
		contentContext->cm(0.5,0,0,0.5,0,421);
		contentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(result.second.front()));
		contentContext->Q();
		
		contentContext->G(0);
		contentContext->w(1);
		contentContext->re(0,421,297.5,421);
		contentContext->S();


		// place the second page in the bottom right corner of the document
		contentContext->q();
		contentContext->cm(0.5,0,0,0.5,297.5,0);
		contentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(result.second.back()));
		contentContext->Q();

		contentContext->G(0);
		contentContext->w(1);
		contentContext->re(297.5,0,297.5,421);
		contentContext->S();


		status = pdfWriter.EndPageContentContext(contentContext);
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed to end page content context\n";
			break;
		}

		status = pdfWriter.WritePageAndRelease(page);
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed to write page\n";
			break;
		}

		status = pdfWriter.EndPDF();
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed in end PDF\n";
			break;
		}

	}while(false);

	return status;
}