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; }
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; }
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; }
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; }
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; }
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; }