예제 #1
0
EStatusCode TiffSpecialsTest::Run(const TestConfiguration& inTestConfiguration)
{
	PDFWriter pdfWriter;
	EStatusCode status; 
	TIFFUsageParameters TIFFParameters;

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


		// multipage Tiff
		for(int i=0;i<4 && (PDFHummus::eSuccess == status);++i)
		{
			TIFFParameters.PageIndex = i;
			PDFFormXObject* imageFormXObject = pdfWriter.CreateFormXObjectFromTIFFFile(RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TestMaterials/images/tiff/multipage.tif"),TIFFParameters);
			if(!imageFormXObject)
			{
				cout<<"failed to create image form XObject from file, for file "<<"multipage.tif page "<<i<<"\n";
				status = PDFHummus::eFailure;
			}
			else
				status = CreatePageForImageAndRelease(pdfWriter,imageFormXObject);
		}

		if(status != PDFHummus::eSuccess)
			break;

		// Black and White mask
		status = CreateBlackAndWhiteMaskImage(inTestConfiguration,pdfWriter);
		if(status != PDFHummus::eSuccess)
			break;

		//Create BiLevel grayscales
		status = CreateBiLevelGrayScales(inTestConfiguration,pdfWriter);
		if(status != PDFHummus::eSuccess)
			break;

		status = pdfWriter.EndPDF();
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed in end PDF\n";
			break;
		}
	}while(false);
	return status;
}
예제 #2
0
int PosteRazorCore::savePoster(const QString &fileName) const
{
    int err = 0;

    const QSizeF posterSizePages = posterSize(Types::PosterSizeModePages);
    const QSizeF sizeCm = convertSizeToCm(printablePaperAreaSize());
    const int pagesCount = (int)(ceil(posterSizePages.width())) * (int)(ceil(posterSizePages.height()));
    const QSize imageSize = m_imageLoader->sizePixels();
    const QByteArray imageData = m_imageLoader->bits();

    PDFWriter pdfWriter;
    err = pdfWriter.startSaving(fileName, pagesCount, sizeCm.width(), sizeCm.height());
    if (!err) {
        if (m_imageLoader->isJpeg())
            err = pdfWriter.saveJpegImage(m_imageLoader->fileName(), imageSize, m_imageLoader->colorDataType());
        else
            err = pdfWriter.saveImage(imageData, imageSize, m_imageLoader->bitsPerPixel(), m_imageLoader->colorDataType(), m_imageLoader->colorTable());
    }

    if (!err) {
        for (int page = 0; page < pagesCount; page++) {
            pdfWriter.startPage();
            paintOnCanvas(&pdfWriter, QString(QLatin1String("posterpage %1")).arg(page));
            pdfWriter.finishPage();
        }
        err = pdfWriter.finishSaving();
    }

    return err;
}
예제 #3
0
파일: main.cpp 프로젝트: keitee/kb
void print_pdf(
   fs::path const & pdfpath,
   fs::path const & dirpath)
{
   const int height = 842;
   const int width = 595;
   const int margin = 20;

   auto image_paths = get_images(dirpath);

   PDFWriter pdf;
   pdf.StartPDF(pdfpath.string(), ePDFVersion13);

   PDFPage* page = nullptr;
   PageContentContext* context = nullptr;

   auto top = height - margin;
   for (size_t i = 0; i < image_paths.size(); ++i)
   {
      auto dims = pdf.GetImageDimensions(image_paths[i]);

      if (i == 0 || top - dims.second < margin)
      {
         if (page != nullptr)
         {
            pdf.EndPageContentContext(context);
            pdf.WritePageAndRelease(page);
         }

         page = new PDFPage();
         page->SetMediaBox(PDFRectangle(0, 0, width, height));
         context = pdf.StartPageContentContext(page);

         top = height - margin;
      }

      context->DrawImage(margin, top - dims.second, image_paths[i]);

      top -= dims.second + margin;
   }

   if (page != nullptr)
   {
      pdf.EndPageContentContext(context);
      pdf.WritePageAndRelease(page);
   }

   pdf.EndPDF();
}
예제 #4
0
EStatusCode TiffSpecialsTest::CreatePageForImageAndRelease(PDFWriter& inpdfWriter,PDFFormXObject* inImageObject)
{
	EStatusCode status = PDFHummus::eSuccess;

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

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


		string imageXObjectName = page->GetResourcesDictionary().AddFormXObjectMapping(inImageObject->GetObjectID());

		pageContentContext->q();
		pageContentContext->cm(1,0,0,1,0,0);
		pageContentContext->Do(imageXObjectName);
		pageContentContext->Q();

		delete inImageObject;

		status = inpdfWriter.EndPageContentContext(pageContentContext);
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed to end page content context, for Image form xobject"<<inImageObject->GetObjectID()<<"\n";
			break;
		}

		status = inpdfWriter.WritePageAndRelease(page);
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed to write page, for image form xobject "<<inImageObject->GetObjectID()<<"\n";
			break;
		}
	}while(false);

	return status;
}
예제 #5
0
EStatusCode EmbedAsPages()
{
	PDFWriter pdfWriter;
	EStatusCode status;

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

		// appending all pages of XObjectContent.pdf
		status = pdfWriter.AppendPDFPagesFromPDF(scBasePath + "XObjectContent.PDF",PDFPageRange()).first;
		if(status != eSuccess)
			break;

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

		status = pdfWriter.AppendPDFPagesFromPDF(scBasePath + "BasicTIFFImagesTest.PDF",selectivePageRange).first;
		if(status != eSuccess)
			break;

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

	}while(false);


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

	return status;

}
예제 #6
0
EStatusCode EmptyFileTest::Run()
{
	PDFWriter pdfWriter;
	LogConfiguration logConfiguration(true,true,"C:\\PDFLibTests\\EmptyFileLog.txt");
	EStatusCode status; 

	do
	{
		status = pdfWriter.StartPDF("C:\\PDFLibTests\\test.txt",ePDFVersion13,logConfiguration);
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed to start PDF\n";
			break;
		}	
		
		status = pdfWriter.EndPDF();
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed in end PDF\n";
			break;
		}
	}while(false);
	return status;
}
예제 #7
0
EStatusCode AppendPagesTest::Run(const TestConfiguration& inTestConfiguration)
{
	EStatusCode status;

	do
	{
	 	PDFWriter pdfWriter;

		status = pdfWriter.StartPDF(RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"AppendPagesTest.PDF"),ePDFVersion13,LogConfiguration(true,true,RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"AppendPagesTestLog.txt")));
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed to start PDF\n";
			break;
		}	

		EStatusCodeAndObjectIDTypeList result;
		
		result = pdfWriter.AppendPDFPagesFromPDF(RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TestMaterials/Original.pdf"),PDFPageRange());
		if(result.first != PDFHummus::eSuccess)
		{
			cout<<"failed to append pages from Original.PDF\n";
			status = result.first;
			break;
		}
		result = pdfWriter.AppendPDFPagesFromPDF(RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TestMaterials/XObjectContent.PDF"),PDFPageRange());
		if(result.first != PDFHummus::eSuccess)
		{
			cout<<"failed to append pages from XObjectContent.pdf\n";
			status = result.first;
			break;
		}

		result = pdfWriter.AppendPDFPagesFromPDF(RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TestMaterials/BasicTIFFImagesTest.PDF"),PDFPageRange());
		if(result.first != PDFHummus::eSuccess)
		{
			cout<<"failed to append pages from BasicTIFFImagesTest.PDF\n";
			status = result.first;
			break;
		}
		status = pdfWriter.EndPDF();
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed in end PDF\n";
			break;
		}

	}while(false);

	return status;
}
예제 #8
0
EStatusCode AppendPagesTest::Run()
{
	EStatusCode status;

	do
	{
	 	PDFWriter pdfWriter;

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

		EStatusCodeAndObjectIDTypeList result;
		
		result = pdfWriter.AppendPDFPagesFromPDF("C:\\PDFLibTests\\TestMaterials\\Original.pdf",PDFPageRange());
		if(result.first != PDFHummus::eSuccess)
		{
			cout<<"failed to append pages from Original.PDF\n";
			status = result.first;
			break;
		}
		result = pdfWriter.AppendPDFPagesFromPDF("C:\\PDFLibTests\\TestMaterials\\XObjectContent.PDF",PDFPageRange());
		if(result.first != PDFHummus::eSuccess)
		{
			cout<<"failed to append pages from XObjectContent.pdf\n";
			status = result.first;
			break;
		}

		result = pdfWriter.AppendPDFPagesFromPDF("C:\\PDFLibTests\\TestMaterials\\BasicTIFFImagesTest.PDF",PDFPageRange());
		if(result.first != PDFHummus::eSuccess)
		{
			cout<<"failed to append pages from BasicTIFFImagesTest.PDF\n";
			status = result.first;
			break;
		}
		status = pdfWriter.EndPDF();
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed in end PDF\n";
			break;
		}

	}while(false);

	return status;
}
예제 #9
0
int main(int argc, char* argv[])
{
	PDFWriter pdfWriter;
	EStatusCode status;

	do
	{
		// Initial Setup for file,page and page content
		status = pdfWriter.StartPDF(scBasePath + "DrawingShapes.pdf",ePDFVersion13);
		if(status != eSuccess)
			break;

		PDFPage* pdfPage = new PDFPage();
		pdfPage->SetMediaBox(PDFRectangle(0,0,595,842));
		PageContentContext* pageContentContext = pdfWriter.StartPageContentContext(pdfPage);

		// Start adding content to page

		// Draw a Line, stroke
		pageContentContext->q();
		pageContentContext->w(2);
		pageContentContext->K(0,0,1,0);

		pageContentContext->m(10,500);
		pageContentContext->l(30,700);
		pageContentContext->s();

		pageContentContext->Q();

		// Draw a Polygon, stroke
		pageContentContext->q();
		pageContentContext->w(2);
		pageContentContext->K(0,1,0,0);

		pageContentContext->m(40,500);
		pageContentContext->l(60,700);
		pageContentContext->l(160,700);
		pageContentContext->l(140,500);
		pageContentContext->s();

		pageContentContext->Q();

		// Draw a Rectangle, fill
		pageContentContext->q();
		pageContentContext->k(0,1,0,0);

		pageContentContext->re(200,400,100,300);
		pageContentContext->f();

		pageContentContext->Q();

		// Pausing content context, to allow form definition
		pdfWriter.PausePageContentContext(pageContentContext);

		// Create a form with a triangle pattern, RGB colorspace, fill
		PDFFormXObject* formXObject = pdfWriter.StartFormXObject(PDFRectangle(0,0,400,400));
		XObjectContentContext* xobjectContent = formXObject->GetContentContext();

		xobjectContent->rg(1,0,0);
		xobjectContent->m(0,0);
		xobjectContent->l(200,400);
		xobjectContent->l(400,0);
		xobjectContent->f();

		ObjectIDType formObjectID = formXObject->GetObjectID();
		status = pdfWriter.EndFormXObjectAndRelease(formXObject);
		if(status != eSuccess)
			break;

		// Place the form in multiple locations in the page
		string formNameInPage = pdfPage->GetResourcesDictionary().AddFormXObjectMapping(formObjectID);

		pageContentContext->q();
		pageContentContext->cm(0.5,0,0,0.5,120,100);
		pageContentContext->Do(formNameInPage);
		pageContentContext->Q();

		pageContentContext->q();
		pageContentContext->cm(0.2,0,0,0.2,350,100);
		pageContentContext->Do(formNameInPage);
		pageContentContext->Q();

		// End adding content to page

		// end page content, write page object and finalize PDF
		status = pdfWriter.EndPageContentContext(pageContentContext);
		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;
}
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;
}
예제 #11
0
EStatusCode TiffSpecialsTest::CreateBiLevelGrayScales(const TestConfiguration& inTestConfiguration,PDFWriter& inpdfWriter)
{
	EStatusCode status = PDFHummus::eSuccess;
	TIFFUsageParameters TIFFParameters;
    
    string scWJim = RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TestMaterials/images/tiff/jim___cg.tif");

	do
	{

		// GrayScale regular
		PDFFormXObject* imageGrayScale = inpdfWriter.CreateFormXObjectFromTIFFFile(scWJim);
		if(!imageGrayScale)
		{
			cout<<"failed to create image form XObject from file, grayscale for file "<<scWJim;
			status = PDFHummus::eFailure;
			break;
		}

		// GrayScale Green
		TIFFParameters.GrayscaleTreatment.AsColorMap = true;
		TIFFParameters.GrayscaleTreatment.OneColor = CMYKRGBColor(0,255,0);
		TIFFParameters.GrayscaleTreatment.ZeroColor = CMYKRGBColor(255,255,255);
		PDFFormXObject* imageGrayScaleGreen = inpdfWriter.CreateFormXObjectFromTIFFFile(scWJim,TIFFParameters);
		if(!imageGrayScaleGreen)
		{
			cout<<"failed to create image form XObject from file, green n white for file "<<scWJim;
			status = PDFHummus::eFailure;
			break;
		}


		// grayscale cyan magenta
		TIFFParameters.GrayscaleTreatment.AsColorMap = true;
		TIFFParameters.GrayscaleTreatment.OneColor = CMYKRGBColor(255,255,0,0);
		TIFFParameters.GrayscaleTreatment.ZeroColor = CMYKRGBColor(0,0,0,0);
		PDFFormXObject* imageGrayScaleCyanMagenta = inpdfWriter.CreateFormXObjectFromTIFFFile(scWJim,TIFFParameters);
		if(!imageGrayScaleCyanMagenta)
		{
			cout<<"failed to create image form XObject from file, cyan magenta n white for file "<<scWJim;
			status = PDFHummus::eFailure;
			break;
		}

		// grayscale green vs red
		TIFFParameters.GrayscaleTreatment.AsColorMap = true;
		TIFFParameters.GrayscaleTreatment.OneColor = CMYKRGBColor(0,255,0);
		TIFFParameters.GrayscaleTreatment.ZeroColor = CMYKRGBColor(255,0,0);
		PDFFormXObject* imageGrayScaleGreenVSRed = inpdfWriter.CreateFormXObjectFromTIFFFile(scWJim,TIFFParameters);
		if(!imageGrayScaleGreenVSRed)
		{
			cout<<"failed to create image form XObject from file, green n red for file "<<scWJim;
			status = PDFHummus::eFailure;
			break;
		}

		// grayscale cyan vs magenta
		TIFFParameters.GrayscaleTreatment.AsColorMap = true;
		TIFFParameters.GrayscaleTreatment.OneColor = CMYKRGBColor(255,0,0,0);
		TIFFParameters.GrayscaleTreatment.ZeroColor = CMYKRGBColor(0,255,0,0);
		PDFFormXObject* imageGrayScaleCyanVSMagenta = inpdfWriter.CreateFormXObjectFromTIFFFile(scWJim,TIFFParameters);
		if(!imageGrayScaleCyanVSMagenta)
		{
			cout<<"failed to create image form XObject from file, cyan n magenta for file "<<scWJim;
			status = PDFHummus::eFailure;
			break;
		}

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

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

		pageContentContext->q();
		pageContentContext->cm(1,0,0,1,0,842 - 195.12);
		pageContentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(imageGrayScale->GetObjectID()));
		pageContentContext->Q();

		pageContentContext->q();
		pageContentContext->cm(1,0,0,1,159.36,842 - 195.12);
		pageContentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(imageGrayScaleGreen->GetObjectID()));
		pageContentContext->Q();

		pageContentContext->q();
		pageContentContext->cm(1,0,0,1,159.36*2,842 - 195.12);
		pageContentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(imageGrayScaleCyanMagenta->GetObjectID()));
		pageContentContext->Q();

		pageContentContext->q();
		pageContentContext->cm(1,0,0,1,0,842 - 195.12*2);
		pageContentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(imageGrayScaleGreenVSRed->GetObjectID()));
		pageContentContext->Q();

		pageContentContext->q();
		pageContentContext->cm(1,0,0,1,159.36,842 - 195.12*2);
		pageContentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(imageGrayScaleCyanVSMagenta->GetObjectID()));
		pageContentContext->Q();

		delete imageGrayScale;
		delete imageGrayScaleGreen;
		delete imageGrayScaleCyanMagenta;
		delete imageGrayScaleGreenVSRed;
		delete imageGrayScaleCyanVSMagenta;

		status = inpdfWriter.EndPageContentContext(pageContentContext);
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed to end page content context, for bilevel grayscale images\n";
			break;
		}

		status = inpdfWriter.WritePageAndRelease(page);
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed to write page, for bilevel grayscale images\n";
			break;
		}
	}while(false);

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

	do
	{
		status = pdfWriter.StartPDF(RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TextMeasurementsTest.PDF"),
                                    ePDFVersion13,
                                    LogConfiguration(true,true,
                                                     RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TextMeasurementsTest.log")));
		if(status != eSuccess)
		{
			cout<<"Failed to start file\n";
			break;
		}

		PDFPage* page = new PDFPage();
		page->SetMediaBox(PDFRectangle(0,0,595,842));
		
		PageContentContext* cxt = pdfWriter.StartPageContentContext(page);
		PDFUsedFont* arialFont = pdfWriter.GetFontForFile(
                                                     RelativeURLToLocalPath(
                                                                            inTestConfiguration.mSampleFileBase,
                                                                            "TestMaterials/fonts/arial.ttf"));
		if(!arialFont)
		{
			status = PDFHummus::eFailure;
			cout<<"Failed to create font for arial font\n";
			break;
		}

		AbstractContentContext::GraphicOptions pathStrokeOptions(AbstractContentContext::eStroke,
																AbstractContentContext::eRGB,
																AbstractContentContext::ColorValueForName("DarkMagenta"),
																4);
		AbstractContentContext::TextOptions textOptions(arialFont,
														14,
														AbstractContentContext::eGray,
														0);

		PDFUsedFont::TextMeasures textDimensions = arialFont->CalculateTextDimensions("Hello World",14);

		cxt->WriteText(10,100,"Hello World",textOptions);
		DoubleAndDoublePairList pathPoints;
		pathPoints.push_back(DoubleAndDoublePair(10+textDimensions.xMin,98+textDimensions.yMin));
		pathPoints.push_back(DoubleAndDoublePair(10+textDimensions.xMax,98+textDimensions.yMin));
		cxt->DrawPath(pathPoints,pathStrokeOptions);
		pathPoints.clear();
		pathPoints.push_back(DoubleAndDoublePair(10+textDimensions.xMin,102+textDimensions.yMax));
		pathPoints.push_back(DoubleAndDoublePair(10+textDimensions.xMax,102+textDimensions.yMax));
		cxt->DrawPath(pathPoints,pathStrokeOptions);

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

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


		status = pdfWriter.EndPDF();
		if(status != eSuccess)
		{
			status = PDFHummus::eFailure;
			cout<<"Failed to end pdf\n";
			break;
		}

	}while(false);


	return status;
}
예제 #13
0
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 SimpleContentPageTest::Run(const TestConfiguration& inTestConfiguration)
{
	PDFWriter pdfWriter;
	EStatusCode status; 

	do
	{
		status = pdfWriter.StartPDF(RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"SimpleContent.PDF"),ePDFVersion13);
		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;
		}

		// draw a 100X100 points cyan square
		contentContext->q();
		contentContext->k(100,0,0,0);
		contentContext->re(100,500,100,100);
		contentContext->f();
		contentContext->Q();

		// force stream change
		status = pdfWriter.PausePageContentContext(contentContext);
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed to pause page content context\n";
			break;
		}

		// draw a 200X100 points red rectangle
		contentContext->q();
		contentContext->k(0,100,100,0);
		contentContext->re(200,600,200,100);
		contentContext->f();
		contentContext->Q();

		// draw a gray line
		contentContext->q();
		contentContext->G(0.5);
		contentContext->w(3);
		contentContext->m(200,600);
		contentContext->l(400,400);
		contentContext->S();
		contentContext->Q();
		
		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;
}
예제 #15
0
EStatusCode DCTDecodeFilterTest::Run(const TestConfiguration& inTestConfiguration)
{
    EStatusCode status = eSuccess;
    
    /*
        what we're going to do here is this:
     
        1. create a PDF file using a jpg image. just like the regular jpg image test
        2. open the file for modification
        3. the jpg image should be using DCT decoder. make sure
        4. create a modified image object with the DCT decoding decompressed. 
            4.1 start a new stream
            4.2 copy all but length and decoders details from the original image dictionary
            4.3 create a stream reader for the old image that will decompress the image
            4.4 write it as is to the new image object
        5. now you should have a PDF that has the image decompressed. if it's showing fine...then
           you got a working DCT decoder
     */
    
    do
    {
        string testFileName = "DCTTest.pdf";
        
        // ceate file
        status = CreateFileWithJPGImage(inTestConfiguration,testFileName);
        if(status != eSuccess)
        {
            cout<<"Failed to create jpg file\n";
            break;
        }
        
       
        // open file for modification
        PDFWriter pdfWriter;
        
        status = pdfWriter.ModifyPDF(RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,testFileName),ePDFVersion13,RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,string("mod") + testFileName));
		if(status != PDFHummus::eSuccess)
		{
			cout<<"Failed to start PDF for modification\n";
			break;
		}
        
        ObjectIDType imageObject = FindDCTDecodedImageObject(&pdfWriter.GetModifiedFileParser());
        
        if(imageObject == 0)
        {
            status = eFailure;
            cout<<"Image object not found\n";
            break;
        }
        
        status = ModifyImageObject(&pdfWriter,imageObject);
        
        if(status != eSuccess)
        {
            cout<<"Failed to modify PDF\n";
            break;
        }
        
        status = pdfWriter.EndPDF();
        if(status != eSuccess)
        {
            cout<<"Failed to end PDF\n";
            break;
            
        }
    }
    while (false);
    
    return status;
}
EStatusCode AppendSpecialPagesTest::Run(const TestConfiguration& inTestConfiguration)
{
	EStatusCode status;
	PDFWriter pdfWriter;

	do
	{

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

		EStatusCodeAndObjectIDTypeList result;

		result = pdfWriter.AppendPDFPagesFromPDF(RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TestMaterials/Protected.pdf"),PDFPageRange());
		if(result.first == PDFHummus::eSuccess)
		{
			cout<<"failted to NOT ALLOW embedding of protected documents without providing pasword\n";
			status = PDFHummus::eFailure;
			break;
		}

		result = pdfWriter.AppendPDFPagesFromPDF(RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TestMaterials/ObjectStreamsModified.pdf"),PDFPageRange());
		if(result.first != PDFHummus::eSuccess)
		{
			cout<<"failed to append pages from ObjectStreamsModified.pdf\n";
			status = result.first;
			break;
		}

		result = pdfWriter.AppendPDFPagesFromPDF(RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TestMaterials/ObjectStreams.pdf"),PDFPageRange());
		if(result.first != PDFHummus::eSuccess)
		{
			cout<<"failed to append pages from ObjectStreams.pdf\n";
			status = result.first;
			break;
		}

		
		result = pdfWriter.AppendPDFPagesFromPDF(RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TestMaterials/AddedItem.pdf"),PDFPageRange());
		if(result.first != PDFHummus::eSuccess)
		{
			cout<<"failed to append pages from AddedItem.pdf\n";
			status = result.first;
			break;
		}

		result = pdfWriter.AppendPDFPagesFromPDF(RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TestMaterials/AddedPage.pdf"),PDFPageRange());
		if(result.first != PDFHummus::eSuccess)
		{
			cout<<"failed to append pages from AddedPage.pdf\n";
			status = result.first;
			break;
		}


		result = pdfWriter.AppendPDFPagesFromPDF(RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TestMaterials/MultipleChange.pdf"),PDFPageRange());
		if(result.first != PDFHummus::eSuccess)
		{
			cout<<"failed to append pages from MultipleChange.pdf\n";
			status = result.first;
			break;
		}

		result = pdfWriter.AppendPDFPagesFromPDF(RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TestMaterials/RemovedItem.pdf"),PDFPageRange());
		if(result.first != PDFHummus::eSuccess)
		{
			cout<<"failed to append pages from RemovedItem.pdf\n";
			status = result.first;
			break;
		}


		result = pdfWriter.AppendPDFPagesFromPDF(RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TestMaterials/Linearized.pdf"),PDFPageRange());
		if(result.first != PDFHummus::eSuccess)
		{
			cout<<"failed to append pages from RemovedItem.pdf\n";
			status = result.first;
			break;
		}

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

	}while(false);

	return status;
}
예제 #17
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;
}
예제 #18
0
EStatusCode MergeToPDFForm::Run(const TestConfiguration& inTestConfiguration)
{
	PDFWriter pdfWriter;
	EStatusCode status;
    PDFDocumentCopyingContext* copyingContext = NULL;
    
	do
	{
		status = pdfWriter.StartPDF(RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"MergeToPDFForm.pdf"),
                                    ePDFVersion13,
                                    LogConfiguration(true,true,RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"MergeToPDFForm.txt")));
		if(status != PDFHummus::eSuccess)
			break;
        
        
        // in this test we will merge 2 pages into a PDF form, and place it twice, forming a 2X2 design. amazing.
        
		PDFPage* page = new PDFPage();
		page->SetMediaBox(PDFRectangle(0,0,595,842));
        
        
        copyingContext = pdfWriter.CreatePDFCopyingContext(RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TestMaterials/Linearized.pdf"));
        if(status != PDFHummus::eSuccess)
            break;
        
        // create form for two pages.
        PDFFormXObject* newFormXObject = pdfWriter.StartFormXObject(PDFRectangle(0,0,297.5,842));
        
		XObjectContentContext* xobjectContentContext = newFormXObject->GetContentContext();
        
        xobjectContentContext->q();
        xobjectContentContext->cm(0.5,0,0,0.5,0,0);
        status = copyingContext->MergePDFPageToFormXObject(newFormXObject,1);
        if(status != eSuccess)
            break;
        xobjectContentContext->Q();
        
        xobjectContentContext->q();
        xobjectContentContext->cm(0.5,0,0,0.5,0,421);
        status = copyingContext->MergePDFPageToFormXObject(newFormXObject,0);
        if(status != eSuccess)
            break;
        xobjectContentContext->Q();
        
        ObjectIDType formID = newFormXObject->GetObjectID();
        status = pdfWriter.EndFormXObjectAndRelease(newFormXObject);
        if(status != eSuccess)
            break;
        
        // now place it in the page
        PageContentContext* pageContentContext = pdfWriter.StartPageContentContext(page);
        
        
        string formName = page->GetResourcesDictionary().AddFormXObjectMapping(formID);
  
        pageContentContext->q();
        pageContentContext->Do(formName);
        pageContentContext->cm(1,0,0,1,297.5,0);
        pageContentContext->Do(formName);
        pageContentContext->Q();
        
        status = pdfWriter.EndPageContentContext(pageContentContext);
        if(status != eSuccess)
            break;
        
		status = pdfWriter.WritePageAndRelease(page);
		if(status != PDFHummus::eSuccess)
			break;
        
		status = pdfWriter.EndPDF();
		if(status != PDFHummus::eSuccess)
			break;
	}while(false);
    
    delete copyingContext;
	
	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;

}
EStatusCode AppendSpecialPagesTest::Run()
{
	EStatusCode status;
	PDFWriter pdfWriter;

	do
	{

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

		EStatusCodeAndObjectIDTypeList result;

		result = pdfWriter.AppendPDFPagesFromPDF("C:\\PDFLibTests\\TestMaterials\\Protected.pdf",PDFPageRange());
		if(result.first == PDFHummus::eSuccess)
		{
			cout<<"failted to NOT ALLOW embedding of protected documents\n";
			status = PDFHummus::eFailure;
			break;
		}

		result = pdfWriter.AppendPDFPagesFromPDF("C:\\PDFLibTests\\TestMaterials\\ObjectStreamsModified.pdf",PDFPageRange());
		if(result.first != PDFHummus::eSuccess)
		{
			cout<<"failed to append pages from ObjectStreamsModified.pdf\n";
			status = result.first;
			break;
		}

		result = pdfWriter.AppendPDFPagesFromPDF("C:\\PDFLibTests\\TestMaterials\\ObjectStreams.pdf",PDFPageRange());
		if(result.first != PDFHummus::eSuccess)
		{
			cout<<"failed to append pages from ObjectStreams.pdf\n";
			status = result.first;
			break;
		}

		
		result = pdfWriter.AppendPDFPagesFromPDF("C:\\PDFLibTests\\TestMaterials\\AddedItem.pdf",PDFPageRange());
		if(result.first != PDFHummus::eSuccess)
		{
			cout<<"failed to append pages from AddedItem.pdf\n";
			status = result.first;
			break;
		}

		result = pdfWriter.AppendPDFPagesFromPDF("C:\\PDFLibTests\\TestMaterials\\AddedPage.pdf",PDFPageRange());
		if(result.first != PDFHummus::eSuccess)
		{
			cout<<"failed to append pages from AddedPage.pdf\n";
			status = result.first;
			break;
		}


		result = pdfWriter.AppendPDFPagesFromPDF("C:\\PDFLibTests\\TestMaterials\\MultipleChange.pdf",PDFPageRange());
		if(result.first != PDFHummus::eSuccess)
		{
			cout<<"failed to append pages from MultipleChange.pdf\n";
			status = result.first;
			break;
		}

		result = pdfWriter.AppendPDFPagesFromPDF("C:\\PDFLibTests\\TestMaterials\\RemovedItem.pdf",PDFPageRange());
		if(result.first != PDFHummus::eSuccess)
		{
			cout<<"failed to append pages from RemovedItem.pdf\n";
			status = result.first;
			break;
		}


		result = pdfWriter.AppendPDFPagesFromPDF("C:\\PDFLibTests\\TestMaterials\\Linearized.pdf",PDFPageRange());
		if(result.first != PDFHummus::eSuccess)
		{
			cout<<"failed to append pages from RemovedItem.pdf\n";
			status = result.first;
			break;
		}

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

	}while(false);

	return status;
}
EStatusCode InputImagesAsStreamsTest::Run()
{
    // A minimal test to see if images as streams work. i'm using regular file streams, just to show the point
    // obviously this is quite a trivial case.

    PDFWriter pdfWriter;
    EStatusCode status;

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

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

        // JPG image

        InputFile jpgImage;

        status = jpgImage.OpenFile("C:\\PDFLibTests\\TestMaterials\\images\\otherStage.JPG");
        if(status != PDFHummus::eSuccess)
        {
            cout<<"failed to open JPG image in"<<"C:\\PDFLibTests\\TestMaterials\\images\\otherStage.JPG"<<"\n";
            break;
        }


        PDFFormXObject*  formXObject = pdfWriter.CreateFormXObjectFromJPGStream(jpgImage.GetInputStream());
        if(!formXObject)
        {
            cout<<"failed to create form XObject from file\n";
            status = PDFHummus::eFailure;
            break;
        }

        jpgImage.CloseFile();

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

        pageContentContext->q();
        pageContentContext->cm(1,0,0,1,0,400);
        pageContentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(formXObject->GetObjectID()));
        pageContentContext->Q();

        delete formXObject;

        status = pdfWriter.EndPageContentContext(pageContentContext);
        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;
        }

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

        InputFile tiffFile;
        status = tiffFile.OpenFile("C:\\PDFLibTests\\TestMaterials\\images\\tiff\\FLAG_T24.TIF");
        if(status != PDFHummus::eSuccess)
        {
            cout<<"failed to open TIFF image in"<<"C:\\PDFLibTests\\TestMaterials\\images\\tiff\\FLAG_T24.TIF"<<"\n";
            break;
        }

        formXObject = pdfWriter.CreateFormXObjectFromTIFFStream(tiffFile.GetInputStream());
        if(!formXObject)
        {
            cout<<"failed to create image form XObject for TIFF\n";
            status = PDFHummus::eFailure;
            break;
        }

        tiffFile.CloseFile();

        pageContentContext = pdfWriter.StartPageContentContext(page);
        if(NULL == pageContentContext)
        {
            status = PDFHummus::eFailure;
            cout<<"failed to create content context for page with TIFF image\n";
        }

        // continue page drawing, place the image in 0,0 (playing...could avoid CM at all)
        pageContentContext->q();
        pageContentContext->cm(1,0,0,1,0,0);
        pageContentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(formXObject->GetObjectID()));
        pageContentContext->Q();

        delete formXObject;

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

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

        // PDF

        InputFile pdfFile;

        status = pdfFile.OpenFile("C:\\PDFLibTests\\TestMaterials\\Original.pdf");
        if(status != PDFHummus::eSuccess)
        {
            cout<<"failed to open PDF file in"<<"C:\\PDFLibTests\\TestMaterials\\Original.pdf"<<"\n";
            break;
        }

        status = pdfWriter.AppendPDFPagesFromPDF(pdfFile.GetInputStream(),PDFPageRange()).first;
        if(status != PDFHummus::eSuccess)
        {
            cout<<"failed to append pages from Original.PDF\n";
            break;
        }

        pdfFile.CloseFile();

        status = pdfWriter.EndPDF();
        if(status != PDFHummus::eSuccess)
        {
            cout<<"failed in end PDF\n";
            break;
        }
    } while(false);
    return status;
}
예제 #22
0
EStatusCode CustomLogTest::Run()
{
	// Place log in a compressed stream, for a non-file PDF
	EStatusCode status;
	OutputFlateEncodeStream flateEncodeStream;
	OutputFlateDecodeStream flateDecodeStream;

	do
	{
		PDFWriter pdfWriter;
		OutputFile compressedLogFile;
		OutputStringBufferStream pdfStream;
	
		// setup log file with compression
		status = compressedLogFile.OpenFile("c:\\PDFLibTests\\CustomLogEncrypted.txt");
		if(status != PDFHummus::eSuccess)
			break;
		flateEncodeStream.Assign(compressedLogFile.GetOutputStream());
		
		// generate PDF
		TRACE_LOG("Starting PDF File Writing");
		status = pdfWriter.StartPDFForStream(&pdfStream,ePDFVersion13,LogConfiguration(true,&flateEncodeStream));
		if(status != PDFHummus::eSuccess)
			break;
		TRACE_LOG("Now will add an empty page");
		PDFPage* page = new PDFPage();

		page->SetMediaBox(PDFRectangle(0,0,400,400));
		
		status = pdfWriter.WritePageAndRelease(page);
		if(status != PDFHummus::eSuccess)
			break;

		TRACE_LOG("Added page, now will close");

		status = pdfWriter.EndPDFForStream();
		if(status != PDFHummus::eSuccess)
			break;

		// since log was started by starting PDF...the ending resets it. so let's now begin again
		Singleton<Trace>::GetInstance()->SetLogSettings(&flateEncodeStream,true);
		TRACE_LOG("Finished PDF!!!1");

		// dump PDF to a file, so we can review it
		OutputFile pdfFile;
		status = pdfFile.OpenFile("c:\\PDFLibTests\\DumpPDFFile.pdf");
		if(status != PDFHummus::eSuccess)
			break;

		string pdfString = pdfStream.ToString();
		pdfFile.GetOutputStream()->Write((const Byte*)pdfString.c_str(),pdfString.size());
		pdfFile.CloseFile();

		TRACE_LOG("PDF stream dumped");
		
		// now finalize trace compressed file
		flateEncodeStream.Assign(NULL);
		compressedLogFile.CloseFile();

		// Finish log
		Singleton<Trace>::Reset();


		// now open a new file and decompress the log into it.
		OutputFile decryptedLogFile;

		status = decryptedLogFile.OpenFile("c:\\PDFLibTests\\CustomLogDecrypted.txt");
		if(status != PDFHummus::eSuccess)
			break;


		// place an initial bom (cause the compressed content is unicode)
		unsigned short bom = (0xFE<<8) + 0xFF;
		decryptedLogFile.GetOutputStream()->Write((const Byte*)&bom,2);	

		flateDecodeStream.Assign(decryptedLogFile.GetOutputStream());
		OutputStreamTraits traits(&flateDecodeStream);

		InputFile compressedLogFileInput;
		status = compressedLogFileInput.OpenFile("c:\\PDFLibTests\\CustomLogEncrypted.txt");
		if(status != PDFHummus::eSuccess)
			break;

		status = traits.CopyToOutputStream(compressedLogFileInput.GetInputStream());
		if(status != PDFHummus::eSuccess)
			break;

		compressedLogFileInput.CloseFile();
		flateDecodeStream.Assign(NULL);
		decryptedLogFile.CloseFile();
		
	}while(false);

	if(status != PDFHummus::eSuccess)
	{
		// cancel ownership of subsstreams
		flateDecodeStream.Assign(NULL);
		flateEncodeStream.Assign(NULL);
	}

	return status;
}
예제 #23
0
EStatusCode DCTDecodeFilterTest::CreateFileWithJPGImage(const TestConfiguration& inTestConfiguration,
                                                        const string& inTestFileName)
{
	PDFWriter pdfWriter;
	EStatusCode status;
    
	do
	{
		status = pdfWriter.StartPDF(RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,inTestFileName),ePDFVersion13);
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed to start PDF\n";
			break;
		}
        
		PDFPage* page = new PDFPage();
		page->SetMediaBox(PDFRectangle(0,0,595,842));
        
		PageContentContext* pageContentContext = pdfWriter.StartPageContentContext(page);
		if(NULL == pageContentContext)
		{
			status = PDFHummus::eFailure;
			cout<<"failed to create content context for page\n";
		}
        
		// draw a rectangle
		pageContentContext->q();
		pageContentContext->k(100,0,0,0);
		pageContentContext->re(500,0,100,100);
		pageContentContext->f();
		pageContentContext->Q();
        
		// pause stream to start writing the image
		status = pdfWriter.PausePageContentContext(pageContentContext);
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed to pause page content context\n";
			break;
		}
        
		// Create image xobject from
		PDFImageXObject* imageXObject  = pdfWriter.CreateImageXObjectFromJPGFile(
                                                                                 RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TestMaterials/images/otherStage.JPG"));
		if(!imageXObject)
		{
			cout<<"failed to create image XObject from file\n";
			status = PDFHummus::eFailure;
			break;
		}
        
		// continue page drawing size the image to 500,400
		pageContentContext->q();
		pageContentContext->cm(500,0,0,400,0,0);
		pageContentContext->Do(page->GetResourcesDictionary().AddImageXObjectMapping(imageXObject));
		pageContentContext->Q();
        
		delete imageXObject;
        
		status = pdfWriter.EndPageContentContext(pageContentContext);
		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;
}
예제 #24
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 ImagesAndFormsForwardReferenceTest::Run(const TestConfiguration& inTestConfiguration)
{
	PDFWriter pdfWriter;
	EStatusCode status; 

	do
	{

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

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

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



		// continue page drawing size the image to 500,400
		pageContentContext->q();
		pageContentContext->cm(500,0,0,400,0,0);
		
		ObjectIDType imageXObjectID = pdfWriter.GetObjectsContext().GetInDirectObjectsRegistry().AllocateNewObjectID();
		pageContentContext->Do(page->GetResourcesDictionary().AddImageXObjectMapping(imageXObjectID));

		// optionally i can also add the necessary PDF Procsets. i'll just add all that might be relevant
		page->GetResourcesDictionary().AddProcsetResource(KProcsetImageB);
		page->GetResourcesDictionary().AddProcsetResource(KProcsetImageC);
		page->GetResourcesDictionary().AddProcsetResource(KProcsetImageI);

		pageContentContext->Q();

		// continue page drawing size the image to 500,400
		pageContentContext->q();
		pageContentContext->cm(1,0,0,1,0,400);
		ObjectIDType formXObjectID = pdfWriter.GetObjectsContext().GetInDirectObjectsRegistry().AllocateNewObjectID();
		pageContentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(formXObjectID));
		pageContentContext->Q();

#ifndef NO_TIFF
		pageContentContext->q();
		ObjectIDType tiffFormXObjectID = pdfWriter.GetObjectsContext().GetInDirectObjectsRegistry().AllocateNewObjectID();
		pageContentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(tiffFormXObjectID));
		pageContentContext->Q();
#endif
        
		pageContentContext->q();
		pageContentContext->cm(1,0,0,1,100,500);
		ObjectIDType simpleFormXObjectID = pdfWriter.GetObjectsContext().GetInDirectObjectsRegistry().AllocateNewObjectID();
		pageContentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(simpleFormXObjectID));
		pageContentContext->Q();

		status = pdfWriter.EndPageContentContext(pageContentContext);
		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;
		}


		// Create image xobject  
		PDFImageXObject* imageXObject  = pdfWriter.CreateImageXObjectFromJPGFile(RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TestMaterials/images/otherStage.JPG"),imageXObjectID);
		if(!imageXObject)
		{
			cout<<"failed to create image XObject from file\n";
			status = PDFHummus::eFailure;
			break;
		}

		// now create form xobject
		PDFFormXObject*  formXObject = pdfWriter.CreateFormXObjectFromJPGFile(
            RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TestMaterials/images/otherStage.JPG"),formXObjectID);
		if(!formXObject)
		{
			cout<<"failed to create form XObject from file\n";
			status = PDFHummus::eFailure;
			break;
		}

#ifndef NO_TIFF
		PDFFormXObject* tiffFormXObject = pdfWriter.CreateFormXObjectFromTIFFFile(
            RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TestMaterials/images/tiff/jim___ah.tif"),tiffFormXObjectID);
		if(!tiffFormXObject)
		{
			cout<<"failed to create image form XObject from file, for file\n";
			status = PDFHummus::eFailure;
			break;
		}
		delete tiffFormXObject;
#endif

		delete imageXObject;
		delete formXObject;


		// define an xobject form to draw a 200X100 points red rectangle
		PDFFormXObject* xobjectForm = pdfWriter.StartFormXObject(PDFRectangle(0,0,200,100),simpleFormXObjectID);

		XObjectContentContext* xobjectContentContext = xobjectForm->GetContentContext();
		xobjectContentContext->q();
		xobjectContentContext->k(0,100,100,0);
		xobjectContentContext->re(0,0,200,100);
		xobjectContentContext->f();
		xobjectContentContext->Q();

		status = pdfWriter.EndFormXObjectAndRelease(xobjectForm);
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed to write XObject form\n";
			break;
		}


		status = pdfWriter.EndPDF();
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed in end PDF\n";
			break;
		}
	}while(false);
	return status;		
}
예제 #26
0
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;
}
예제 #27
0
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;	
}
예제 #28
0
EStatusCode TiffSpecialsTest::CreateBlackAndWhiteMaskImage(const TestConfiguration& inTestConfiguration,PDFWriter& inpdfWriter)
{
    string scJimBW = RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TestMaterials/images/tiff/jim___ah.tif");

	EStatusCode status = PDFHummus::eSuccess;
	TIFFUsageParameters TIFFParameters;

	do
	{
		PDFFormXObject* imageBW = inpdfWriter.CreateFormXObjectFromTIFFFile(scJimBW);
		if(!imageBW)
		{
			cout<<"failed to create image BW, for file "<<scJimBW<<"\n";
			status = PDFHummus::eFailure;
			break;
		}

		TIFFParameters.BWTreatment.AsImageMask = true;
		TIFFParameters.BWTreatment.OneColor = CMYKRGBColor(255,128,0);
		PDFFormXObject* imageBWMask = inpdfWriter.CreateFormXObjectFromTIFFFile(scJimBW,TIFFParameters);
		if(!imageBWMask)
		{
			cout<<"failed to create image mask BW, for file "<<scJimBW<<"\n";
			status = PDFHummus::eFailure;
			break;
		}

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

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

		pageContentContext->q();
		pageContentContext->cm(1,0,0,1,0,842 - 195.12);
		pageContentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(imageBW->GetObjectID()));
		pageContentContext->Q();

		pageContentContext->q();
		pageContentContext->cm(1,0,0,1,159.36,842 - 195.12);
		pageContentContext->rg(0,0,1);
		pageContentContext->re(0,0,159.36,195.12);
		pageContentContext->f();
		pageContentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(imageBWMask->GetObjectID()));
		pageContentContext->Q();

		delete imageBW;
		delete imageBWMask;

		status = inpdfWriter.EndPageContentContext(pageContentContext);
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed to end page content context, for Image BWs test\n";
			break;
		}

		status = inpdfWriter.WritePageAndRelease(page);
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed to write page, for image BWs test\n";
			break;
		}
	}while(false);

	return status;
}
예제 #29
0
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;
}
EStatusCode HighLevelContentContext::Run(const TestConfiguration& inTestConfiguration)
{
	EStatusCode status = eSuccess;
	PDFWriter pdfWriter;

	do
	{
		status = pdfWriter.StartPDF(RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"HighLevelContentContext.PDF"),
                                    ePDFVersion13,
                                    LogConfiguration(true,true,
                                                     RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"HighLevelContentContext.log")));
		if(status != eSuccess)
		{
			cout<<"Failed to start file\n";
			break;
		}

		PDFPage* page = new PDFPage();
		page->SetMediaBox(PDFRectangle(0,0,595,842));
		
		PageContentContext* cxt = pdfWriter.StartPageContentContext(page);

		AbstractContentContext::TextOptions textOptions(pdfWriter.GetFontForFile(
																			RelativeURLToLocalPath(
                                                                            inTestConfiguration.mSampleFileBase,
                                                                            "TestMaterials/fonts/arial.ttf")),
																			14,
																			AbstractContentContext::eGray,
																			0);
		AbstractContentContext::GraphicOptions pathFillOptions(AbstractContentContext::eFill,
																AbstractContentContext::eCMYK,
																0xFF000000);
		AbstractContentContext::GraphicOptions pathStrokeOptions(AbstractContentContext::eStroke,
																AbstractContentContext::eRGB,
																AbstractContentContext::ColorValueForName("DarkMagenta"),
																4);

		DoubleAndDoublePairList pathPoints;

		// draw path
		pathPoints.push_back(DoubleAndDoublePair(75,640));
		pathPoints.push_back(DoubleAndDoublePair(149,800));
		pathPoints.push_back(DoubleAndDoublePair(225,640));
		cxt->DrawPath(pathPoints,pathFillOptions);
		pathPoints.clear();
		pathPoints.push_back(DoubleAndDoublePair(75,540));
		pathPoints.push_back(DoubleAndDoublePair(110,440));
		pathPoints.push_back(DoubleAndDoublePair(149,540));
		pathPoints.push_back(DoubleAndDoublePair(188,440));
		pathPoints.push_back(DoubleAndDoublePair(223,540));
		cxt->DrawPath(pathPoints,pathStrokeOptions);

		// draw square
		cxt->DrawSquare(375,640,120,pathFillOptions);
		cxt->DrawSquare(375,440,120,pathStrokeOptions);

		// draw rectangle
		cxt->DrawRectangle(375,220,50,160,pathFillOptions);
		cxt->DrawRectangle(375,10,50,160,pathStrokeOptions);

		// draw circle
		cxt->DrawCircle(149,300,80,pathFillOptions);
		cxt->DrawCircle(149,90,80,pathStrokeOptions);

		// wrote text (writing labels for each of the shapes)
		cxt->WriteText(75,805,"Paths",textOptions);
		cxt->WriteText(375,805,"Squares",textOptions);
		cxt->WriteText(375,400,"Rectangles",textOptions);
		cxt->WriteText(75,400,"Circles",textOptions);

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

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


		status = pdfWriter.EndPDF();
		if(status != eSuccess)
		{
			status = PDFHummus::eFailure;
			cout<<"Failed to end pdf\n";
			break;
		}

	}while(false);


	return status;
}