EStatusCode SimpleTextUsage::RunNoTextTest(const TestConfiguration& inTestConfiguration,bool inEmbedFonts)
{
    // this one checks an edge case where a font object is created but no text written. should not fail.
	PDFWriter pdfWriter;
	EStatusCode status;
    
	do
	{
		status = pdfWriter.StartPDF(
			RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase, inEmbedFonts ? "SimpleNoTextUsage.PDF" : "SimpleNoTextUsageNoEmbed.PDF"),
                                    ePDFVersion13,
                                    LogConfiguration(true,true,RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"SimpleTextUsage.log")),
									PDFCreationSettings(true,inEmbedFonts));
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed to start PDF\n";
			break;
		}
        
		PDFPage* page = new PDFPage();
		page->SetMediaBox(PDFRectangle(0,0,595,842));
        
		PageContentContext* contentContext = pdfWriter.StartPageContentContext(page);
		if(NULL == contentContext)
		{
			status = PDFHummus::eFailure;
			cout<<"failed to create content context for page\n";
			break;
		}
        
		PDFUsedFont* font = pdfWriter.GetFontForFile(
                                                     RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TestMaterials/fonts/HLB_____.PFB"),
                                                     RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TestMaterials/fonts/HLB_____.PFM"));
		if(!font)
		{
			status = PDFHummus::eFailure;
			cout<<"Failed to create font object for Helvetica Neue font\n";
			break;
		}
        
        
		// Draw some text
		contentContext->BT();
		contentContext->k(0,0,0,1);
        
		contentContext->Tf(font,1);
        
		contentContext->Tm(30,0,0,30,78.4252,662.8997);

        // no text is written!!!
        
		// continue even if failed...want to see how it looks like
		contentContext->ET();
        
		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;
}
EStatusCode SimpleTextUsage::RunTrueTypeTest(const TestConfiguration& inTestConfiguration,bool inEmbedFonts)
{
	PDFWriter pdfWriter;
	EStatusCode status; 

	do
	{
		status = pdfWriter.StartPDF(
			RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase, inEmbedFonts ? "SimpleTextUsageTrueType.PDF" : "SimpleTextUsageTrueTypeNoEmbed.PDF"),
                                    ePDFVersion13,
                                    LogConfiguration(true,true,RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"SimpleTextUsage.log")),
									PDFCreationSettings(true,inEmbedFonts));
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed to start PDF\n";
			break;
		}	

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

		PageContentContext* contentContext = pdfWriter.StartPageContentContext(page);
		if(NULL == contentContext)
		{
			status = PDFHummus::eFailure;
			cout<<"failed to create content context for page\n";
			break;
		}

		PDFUsedFont* font = pdfWriter.GetFontForFile(
                                RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TestMaterials/fonts/arial.ttf"));
		if(!font)
		{
			status = PDFHummus::eFailure;
			cout<<"Failed to create font object for arial.ttf\n";
			break;
		}


		// Draw some text
		contentContext->BT();
		contentContext->k(0,0,0,1);

		contentContext->Tf(font,1);

		contentContext->Tm(30,0,0,30,78.4252,662.8997);

		EStatusCode encodingStatus = contentContext->Tj("hello world");
		if(encodingStatus != PDFHummus::eSuccess)
			cout<<"Could not find some of the glyphs for this font";

		// continue even if failed...want to see how it looks like
		contentContext->ET();

		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;	
}
int main(int argc, wchar_t* argv[])
{
	EStatusCode status;

	do
	{

		{
			PDFWriter pdfWriterA;
			
			status = pdfWriterA.StartPDF(scBasePath + L"PauseAndContinue.pdf",ePDFVersion13);
			if(status != eSuccess)
				break;

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

			// Create a content context for the page
			PageContentContext* pageContentContext = pdfWriterA.StartPageContentContext(pdfPage);

			PDFUsedFont* arialTTF = pdfWriterA.GetFontForFile(scSystemFontsPath + L"arial.ttf");
			if(!arialTTF)
			{
				status = eFailure;
				break;
			}

			pageContentContext->k(0,0,0,1);

			pageContentContext->BT();
			pageContentContext->Tf(arialTTF,1);
			pageContentContext->Tm(20,0,0,20,40,822);
			pageContentContext->Tj(L"Hello World");
			pageContentContext->ET();				

			// End content context, and write the page
			status = pdfWriterA.EndPageContentContext(pageContentContext);
			if(status != eSuccess)
				break;

			status = pdfWriterA.WritePageAndRelease(pdfPage);
			if(status != eSuccess)
				break;

			status = pdfWriterA.Shutdown(scBasePath + L"PauseAndContinueTest.txt");
			if(status != eSuccess)
				break;
		}
		

		{
			PDFWriter pdfWriterB;
			
			status = pdfWriterB.ContinuePDF(scBasePath + L"PauseAndContinue.pdf",scBasePath + L"PauseAndContinueTest.txt");
			if(status != eSuccess)
				break;

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

			// Create a content context for the page
			PageContentContext* pageContentContext = pdfWriterB.StartPageContentContext(pdfPage);

			PDFUsedFont* arialTTF = pdfWriterB.GetFontForFile(scSystemFontsPath + L"arial.ttf");
			if(!arialTTF)
			{
				status = eFailure;
				break;
			}

			pageContentContext->k(0,0,0,1);

			pageContentContext->BT();
			pageContentContext->Tf(arialTTF,1);
			pageContentContext->Tm(20,0,0,20,40,822);
			pageContentContext->Tj(L"Hello Again, World");
			pageContentContext->ET();				

			// End content context, and write the page
			status = pdfWriterB.EndPageContentContext(pageContentContext);
			if(status != eSuccess)
				break;

			status = pdfWriterB.WritePageAndRelease(pdfPage);
			if(status != eSuccess)
				break;

			status = pdfWriterB.EndPDF();
			if(status != eSuccess)
				break;
		}

	}while(false);
		
	if(eSuccess == status)
		cout<<"Succeeded in creating PauseAndContinue.PDF file\n";
	else
		cout<<"Failed in creating PauseAndContinue.PDF file\n";
		
	return 0;
}
示例#4
0
int main(int argc, wchar_t* argv[])
{
	EStatusCode status;
	PDFWriter pdfWriter;

	do
	{
		status = pdfWriter.StartPDF(scBasePath + L"Links.pdf",ePDFVersion13);
		if(status != eSuccess)
			break;

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

		PDFFormXObject* soundCloudLogo = pdfWriter.CreateFormXObjectFromJPGFile(scBasePath + L"soundcloud_logo.jpg");

		PageContentContext* contentContext = pdfWriter.StartPageContentContext(page);
		if(!contentContext)
			break;

		PDFUsedFont* font = pdfWriter.GetFontForFile(scSystemFontsPath + L"arial.ttf");
		if(!font)
			break;

		// Draw some text
		contentContext->BT();
		contentContext->k(0,0,0,1);
		contentContext->Tf(font,1);
		contentContext->Tm(11,0,0,11,90.024,709.54);
		contentContext->Tj(L"http://pdfhummus.com");
		contentContext->ET();

		// Draw soundcloud loog
		contentContext->q();
		contentContext->cm(0.5,0,0,0.5,90.024,200);
		contentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(soundCloudLogo->GetObjectID()));
		contentContext->Q();
		
		status = pdfWriter.EndPageContentContext(contentContext);
		if(status != eSuccess)
			break;

		delete soundCloudLogo;

		// now let's attach some links.

		// first, the link for the test:
		pdfWriter.AttachURLLinktoCurrentPage(L"http://www.pdfhummus.com",PDFRectangle(87.75,694.56,198.76,720));

		// second, link for the logo.
		pdfWriter.AttachURLLinktoCurrentPage(L"http://www.soundcloud.com",PDFRectangle(90.024,200,367.524,375));

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

		status = pdfWriter.EndPDF();
			break;
	}while(false);
	return 0;
}
int wmain(int argc, wchar_t* argv[])
{
	PDFWriter pdfWriter;
	EStatusCode status;

	do
	{
		status = pdfWriter.StartPDF(scBasePath + L"MakingComments.pdf",ePDFVersion16);
		if(status != eSuccess)
			break;

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

		// Create a content context for the page
		PageContentContext* pageContentContext = pdfWriter.StartPageContentContext(pdfPage);

		// just put some text
		PDFUsedFont* arialTTF = pdfWriter.GetFontForFile(scSystemFontsPath + L"arial.ttf");
		if(!arialTTF)
		{
			status = eFailure;
			break;
		}

		pageContentContext->k(0,0,0,1);
		pageContentContext->BT();
		pageContentContext->Tf(arialTTF,1);
		pageContentContext->Tm(20,0,0,20,40,822);
		pageContentContext->Tj(L"Text placed and scaled with Tm");
		pageContentContext->ET();				


		// End content context
		status = pdfWriter.EndPageContentContext(pageContentContext);
		if(status != eSuccess)
			break;


		// Now let's add some comments
		PDFCommentWriter commentWriter(&pdfWriter);

		PDFComment* aComment = new PDFComment();

		aComment->Text = L"a very important comment";
		aComment->CommentatorName = L"Someone";
		aComment->FrameBoundings[0] = 100;
		aComment->FrameBoundings[1] = 500;
		aComment->FrameBoundings[2] = 200;
		aComment->FrameBoundings[3] = 600;
		aComment->Color = CMYKRGBColor(255,0,0);

		status = commentWriter.AttachCommentToNextPage(aComment);
		if(status != eSuccess)
			break;

		PDFComment* bComment = new PDFComment();

		bComment->Text = L"I have nothing to say about this";
		bComment->CommentatorName = L"Someone";
		bComment->FrameBoundings[0] = 100;
		bComment->FrameBoundings[1] = 100;
		bComment->FrameBoundings[2] = 200;
		bComment->FrameBoundings[3] = 200;
		bComment->Color = CMYKRGBColor(255,0,0);

		status = commentWriter.AttachCommentToNextPage(bComment);
		if(status != eSuccess)
			break;

		PDFComment* cComment = new PDFComment();

		cComment->Text = L"yeah. me too. it's just perfect";
		cComment->CommentatorName = L"Someone Else";
		cComment->FrameBoundings[0] = 150;
		cComment->FrameBoundings[1] = 150;
		cComment->FrameBoundings[2] = 250;
		cComment->FrameBoundings[3] = 250;
		cComment->Color = CMYKRGBColor(0,255,0);
		cComment->ReplyTo = bComment;
		
		status = commentWriter.AttachCommentToNextPage(cComment);
		if(status != eSuccess)
			break;

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

		status = pdfWriter.EndPDF();
	}while(false);

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

	return 0;
}