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; }
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 UseAsXObjects() { PDFWriter pdfWriter; EStatusCode status; do { status = pdfWriter.StartPDF(scBasePath + "UseAsXObjects.PDF",ePDFVersion13); if(status != eSuccess) break; // creating XObjects for all pages of XObjectContent.pdf (2 pages) EStatusCodeAndObjectIDTypeList result = pdfWriter.CreateFormXObjectsFromPDF(scBasePath + "XObjectContent.PDF",PDFPageRange(),ePDFPageBoxMediaBox); if(result.first != eSuccess) { status = eFailure; break; } // determine page IDs ObjectIDTypeList::iterator it = result.second.begin(); ObjectIDType firstPageID = *it; ++it; ObjectIDType secondPageID = *it; // create a page using both xobjects PDFPage* page = new PDFPage(); page->SetMediaBox(PDFRectangle(0,0,595,842)); PageContentContext* contentContext = pdfWriter.StartPageContentContext(page); // place the first page in the top left corner of the document contentContext->q(); contentContext->cm(0.5,0,0,0.5,0,421); contentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(firstPageID)); contentContext->Q(); // draw a rectangle around the page bounds contentContext->G(0); contentContext->w(1); contentContext->re(0,421,297.5,421); contentContext->S(); // place the second page in the bottom right corner of the document contentContext->q(); contentContext->cm(0.5,0,0,0.5,297.5,0); contentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(secondPageID)); contentContext->Q(); // draw a rectangle around the page bounds contentContext->G(0); contentContext->w(1); contentContext->re(297.5,0,297.5,421); contentContext->S(); status = pdfWriter.EndPageContentContext(contentContext); if(status != eSuccess) break; status = pdfWriter.WritePageAndRelease(page); if(status != eSuccess) break; // appending pages 0,1,2,3 of BasicTIFFImagesTest.PDF PDFPageRange selectivePageRange; selectivePageRange.mType = PDFPageRange::eRangeTypeSpecific; selectivePageRange.mSpecificRanges.push_back(ULongAndULong(0,3)); result = pdfWriter.CreateFormXObjectsFromPDF(scBasePath + "BasicTIFFImagesTest.PDF",selectivePageRange,ePDFPageBoxMediaBox); if(result.first != eSuccess) { status = eFailure; break; } page = new PDFPage(); page->SetMediaBox(PDFRectangle(0,0,595,842)); contentContext = pdfWriter.StartPageContentContext(page); // placing them in all 4 corners of the 2nd page [going left right, top bottom] it = result.second.begin(); contentContext->q(); contentContext->cm(0.5,0,0,0.5,0,421); contentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(*it)); contentContext->Q(); ++it; contentContext->q(); contentContext->cm(0.5,0,0,0.5,297.5,421); contentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(*it)); contentContext->Q(); ++it; contentContext->q(); contentContext->cm(0.5,0,0,0.5,0,0); contentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(*it)); contentContext->Q(); ++it; contentContext->q(); contentContext->cm(0.5,0,0,0.5,297.5,0); contentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(*it)); contentContext->Q(); status = pdfWriter.EndPageContentContext(contentContext); if(status != eSuccess) break; status = pdfWriter.WritePageAndRelease(page); if(status != eSuccess) break; status = pdfWriter.EndPDF(); if(status != eSuccess) break; }while(false); if(eSuccess == status) cout<<"Succeeded in creating UseAsXObjects.PDF file\n"; else cout<<"Failed in creating UseAsXObjects.PDF file\n"; return status; }
EStatusCode PDFEmbedTest::Run(const TestConfiguration& inTestConfiguration) { EStatusCode status; PDFWriter pdfWriter; do { status = pdfWriter.StartPDF(RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"PDFEmbedTest.pdf"),ePDFVersion13); if(status != PDFHummus::eSuccess) { cout<<"failed to start PDF\n"; break; } // Create XObjects from PDF to embed EStatusCodeAndObjectIDTypeList result = pdfWriter.CreateFormXObjectsFromPDF( RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TestMaterials/XObjectContent.PDF"),PDFPageRange(),ePDFPageBoxMediaBox); if(result.first != PDFHummus::eSuccess) { cout<<"failed to create PDF XObjects from PDF file\n"; status = result.first; break; } PDFPage* page = new PDFPage(); page->SetMediaBox(PDFRectangle(0,0,595,842)); PageContentContext* contentContext = pdfWriter.StartPageContentContext(page); // place the first page in the top left corner of the document contentContext->q(); contentContext->cm(0.5,0,0,0.5,0,421); contentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(result.second.front())); contentContext->Q(); contentContext->G(0); contentContext->w(1); contentContext->re(0,421,297.5,421); contentContext->S(); // place the second page in the bottom right corner of the document contentContext->q(); contentContext->cm(0.5,0,0,0.5,297.5,0); contentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(result.second.back())); contentContext->Q(); contentContext->G(0); contentContext->w(1); contentContext->re(297.5,0,297.5,421); contentContext->S(); status = pdfWriter.EndPageContentContext(contentContext); if(status != PDFHummus::eSuccess) { cout<<"failed to end page content context\n"; break; } status = pdfWriter.WritePageAndRelease(page); if(status != PDFHummus::eSuccess) { cout<<"failed to write page\n"; break; } status = pdfWriter.EndPDF(); if(status != PDFHummus::eSuccess) { cout<<"failed in end PDF\n"; break; } }while(false); return status; }