예제 #1
0
EStatusCode UseCopyingContext()
{
	PDFWriter pdfWriter;
	EStatusCode status;

	PDFDocumentCopyingContext* firstContext = NULL;
	PDFDocumentCopyingContext* secondContext = NULL;

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

		firstContext = pdfWriter.CreatePDFCopyingContext(scBasePath + "XObjectContent.PDF");
		if(!firstContext)
		{
			status = eFailure;
			break;
		}
		 
		secondContext = pdfWriter.CreatePDFCopyingContext(scBasePath + "BasicTIFFImagesTest.PDF");
		if(!firstContext)
		{
			status = eFailure;
			break;
		}

		// appending pages, first from XObjectContent, then from BasicTIFFImageTest, and then again from XObjectContent
		status = firstContext->AppendPDFPageFromPDF(0).first;
		if(status != eSuccess)
			break;

		status = secondContext->AppendPDFPageFromPDF(0).first;
		if(status != eSuccess)
			break;

		status = firstContext->AppendPDFPageFromPDF(1).first;
		if(status != eSuccess)
			break;

		// placing pages as xobjects, from multiple PDFs
		EStatusCodeAndObjectIDType resultFirst = firstContext->CreateFormXObjectFromPDFPage(0,ePDFPageBoxMediaBox);
		if(resultFirst.first != eSuccess)
		{
			status = eFailure;
			break;
		}

		EStatusCodeAndObjectIDType resultSecond = secondContext->CreateFormXObjectFromPDFPage(0,ePDFPageBoxMediaBox);
		if(resultSecond.first != eSuccess)
		{
			status = eFailure;
			break;
		}

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

		PageContentContext* contentContext = pdfWriter.StartPageContentContext(page);

		// placing the pages in a result page
		contentContext->q();
		contentContext->cm(0.5,0,0,0.5,0,421);
		contentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(resultFirst.second));
		contentContext->Q();
		
		contentContext->q();
		contentContext->cm(0.5,0,0,0.5,297.5,0);
		contentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(resultSecond.second));
		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);

	delete firstContext;
	delete secondContext;
	return status;
}
EStatusCode PDFCopyingContextTest::Run()
{
	EStatusCode status;
	PDFWriter pdfWriter;
	PDFDocumentCopyingContext* copyingContext = NULL;

	do
	{
		status = pdfWriter.StartPDF("C:\\PDFLibTests\\PDFCopyingContextTest.PDF",ePDFVersion13,LogConfiguration(true,true,"c:\\pdflibtests\\PDFCopyingContextTest.txt"));
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed to start PDF\n";
			break;
		}	


		copyingContext = pdfWriter.CreatePDFCopyingContext("C:\\PDFLibTests\\TestMaterials\\BasicTIFFImagesTest.PDF");
		if(!copyingContext)
		{
			cout<<"failed to initialize copying context from BasicTIFFImagesTest\n";
			status = PDFHummus::eFailure;
			break;
		}

		EStatusCodeAndObjectIDType result = copyingContext->AppendPDFPageFromPDF(1);
		if(result.first != PDFHummus::eSuccess)
		{
			cout<<"failed to append page 1 from BasicTIFFImagesTest.PDF\n";
			status = result.first;
			break;
		}

		result = copyingContext->AppendPDFPageFromPDF(18);
		if(result.first != PDFHummus::eSuccess)
		{
			cout<<"failed to append page 18 from BasicTIFFImagesTest.PDF\n";
			status = result.first;
			break;
		}

		result = copyingContext->AppendPDFPageFromPDF(4);
		if(result.first != PDFHummus::eSuccess)
		{
			cout<<"failed to append page 4 from BasicTIFFImagesTest.PDF\n";
			status = result.first;
			break;
		}

		copyingContext->End(); // delete will call End() as well...so can avoid

		delete copyingContext;
		copyingContext = NULL;

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

	}while(false);

	delete copyingContext;
	return status;

}