EStatusCode JPGImageTest::Run(const TestConfiguration& inTestConfiguration) { PDFWriter pdfWriter; EStatusCode status; do { status = pdfWriter.StartPDF(RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"BasicJPGImagesTest.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"; } // 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; // now do the same with a form xobject // pause stream to start writing the image status = pdfWriter.PausePageContentContext(pageContentContext); if(status != PDFHummus::eSuccess) { cout<<"failed to pause page content context ||\n"; break; } PDFFormXObject* formXObject = pdfWriter.CreateFormXObjectFromJPGFile(RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TestMaterials/images/otherStage.JPG")); if(!formXObject) { cout<<"failed to create form XObject from file\n"; status = PDFHummus::eFailure; break; } // continue page drawing size the image to 500,400 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; } status = pdfWriter.EndPDF(); if(status != PDFHummus::eSuccess) { cout<<"failed in end PDF\n"; break; } }while(false); 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; }
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; }