本文整理汇总了C++中PDFPage类的典型用法代码示例。如果您正苦于以下问题:C++ PDFPage类的具体用法?C++ PDFPage怎么用?C++ PDFPage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PDFPage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: print_pdf
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();
}
示例2: PDFPage
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;
}
示例3: copy
void PDFSelection::copy()
{
if(d->textReply) {
d->textReply->close();
delete d->textReply;
d->textReply = 0;
}
PDFPage *page = d->currentPage;
if(!page) {
qDebug() << "Invalid page";
return;
}
QRectF geom = geometry();
geom.setLeft(geom.left() + d->documentOffset.x());
geom.setRight(geom.right() + d->documentOffset.x());
geom.setTop((geom.top() + d->documentOffset.y()) - page->positionInDocument() );
geom.setBottom((geom.bottom() + d->documentOffset.y()) - page->positionInDocument() );
QRectF sel(QPointF(geom.left() / page->width(), geom.top() / page->height()), QPointF(geom.right() / page->width(), geom.bottom() / page->height()));
QString arguments = QString("page=%1&top=%2&right=%3&bottom=%4&left=%5").arg(page->pageNumber()).arg(sel.top()).arg(sel.right()).arg(sel.bottom()).arg(sel.left());
d->textReply = d->document->networkManager()->get(d->document->buildRequest("text", arguments));
connect(d->textReply, SIGNAL(finished()), SLOT(textRequestFinished()));
}
示例4: PDFPage
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;
}
示例5: logConfiguration
EStatusCode RotatedPagesPDF::Run(const TestConfiguration& inTestConfiguration)
{
LogConfiguration logConfiguration(true,true,RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"RotatedPagesLog.txt"));
EStatusCode status;
do
{
// PDF Page rotation writing
PDFWriter pdfWriter;
status = pdfWriter.StartPDF(
RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"RotatedPages.pdf"),
ePDFVersion13,logConfiguration);
if(status != PDFHummus::eSuccess)
{
cout<<"failed to start RotatedPages.pdf\n";
break;
}
AbstractContentContext::TextOptions textOptions(pdfWriter.GetFontForFile(
RelativeURLToLocalPath(
inTestConfiguration.mSampleFileBase,
"TestMaterials/fonts/arial.ttf")),
14,
AbstractContentContext::eGray,
0);
for(int i=0;i<6 && PDFHummus::eSuccess == status;++i)
{
PDFPage page;
page.SetMediaBox(PDFRectangle(0,0,595,842));
page.SetRotate(33);
if ( page.GetRotate().second != 0 )
{
status = PDFHummus::eFailure;
cout<<"Failed to reject invalid rotation\n";
break;
}
page.SetRotate(i*90);
std::ostringstream s;
s << "Page rotated by " << i*90 << " degrees.";
PageContentContext* cxt = pdfWriter.StartPageContentContext(&page);
cxt->WriteText(75,805,s.str(),textOptions);
status = pdfWriter.EndPageContentContext(cxt);
if(status != eSuccess)
{
status = PDFHummus::eFailure;
cout<<"Failed to end content context\n";
break;
}
status = pdfWriter.WritePage(&page);
if(status != PDFHummus::eSuccess)
cout<<"failed to write page "<<i<<"\n";
}
status = pdfWriter.EndPDF();
if(status != PDFHummus::eSuccess)
{
cout<<"failed in end RotatedPages.pdf\n";
break;
}
// PDF page rotation copy
status = pdfWriter.StartPDF(
RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"RotatedPagesCopy.pdf"),
ePDFVersion13);
if(status != PDFHummus::eSuccess)
{
cout<<"failed to start RotatedPagesCopy.pdf\n";
break;
}
EStatusCodeAndObjectIDTypeList result;
// append pages
result = pdfWriter.AppendPDFPagesFromPDF(
RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"RotatedPages.pdf"),
PDFPageRange());
if(result.first != PDFHummus::eSuccess)
{
cout<<"failed to append pages from RotatedPages.pdf\n";
status = result.first;
break;
}
status = pdfWriter.EndPDF();
if(status != PDFHummus::eSuccess)
{
cout<<"failed in end RotatedPagesCopy.pdf\n";
//.........这里部分代码省略.........
示例6: PDFPage
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)
//.........这里部分代码省略.........
示例7: RelativeURLToLocalPath
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;
}
示例8: RelativeURLToLocalPath
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;
}
示例9: TRACE_LOG
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);
}
//.........这里部分代码省略.........
示例10: LogConfiguration
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;
}
示例11: wmain
int wmain(int argc, wchar_t* argv[])
{
PDFWriter pdfWriter;
EStatusCode status;
do
{
status = pdfWriter.StartPDF(scBasePath + L"MakingComments.pdf",ePDFVersion16);
if(status != eSuccess)
break;
// Create a new page
PDFPage* pdfPage = new PDFPage();
pdfPage->SetMediaBox(PDFRectangle(0,0,595,842));
// Create a content context for the page
PageContentContext* pageContentContext = pdfWriter.StartPageContentContext(pdfPage);
// just put some text
PDFUsedFont* arialTTF = pdfWriter.GetFontForFile(scSystemFontsPath + L"arial.ttf");
if(!arialTTF)
{
status = eFailure;
break;
}
pageContentContext->k(0,0,0,1);
pageContentContext->BT();
pageContentContext->Tf(arialTTF,1);
pageContentContext->Tm(20,0,0,20,40,822);
pageContentContext->Tj(L"Text placed and scaled with Tm");
pageContentContext->ET();
// End content context
status = pdfWriter.EndPageContentContext(pageContentContext);
if(status != eSuccess)
break;
// Now let's add some comments
PDFCommentWriter commentWriter(&pdfWriter);
PDFComment* aComment = new PDFComment();
aComment->Text = L"a very important comment";
aComment->CommentatorName = L"Someone";
aComment->FrameBoundings[0] = 100;
aComment->FrameBoundings[1] = 500;
aComment->FrameBoundings[2] = 200;
aComment->FrameBoundings[3] = 600;
aComment->Color = CMYKRGBColor(255,0,0);
status = commentWriter.AttachCommentToNextPage(aComment);
if(status != eSuccess)
break;
PDFComment* bComment = new PDFComment();
bComment->Text = L"I have nothing to say about this";
bComment->CommentatorName = L"Someone";
bComment->FrameBoundings[0] = 100;
bComment->FrameBoundings[1] = 100;
bComment->FrameBoundings[2] = 200;
bComment->FrameBoundings[3] = 200;
bComment->Color = CMYKRGBColor(255,0,0);
status = commentWriter.AttachCommentToNextPage(bComment);
if(status != eSuccess)
break;
PDFComment* cComment = new PDFComment();
cComment->Text = L"yeah. me too. it's just perfect";
cComment->CommentatorName = L"Someone Else";
cComment->FrameBoundings[0] = 150;
cComment->FrameBoundings[1] = 150;
cComment->FrameBoundings[2] = 250;
cComment->FrameBoundings[3] = 250;
cComment->Color = CMYKRGBColor(0,255,0);
cComment->ReplyTo = bComment;
status = commentWriter.AttachCommentToNextPage(cComment);
if(status != eSuccess)
break;
status = pdfWriter.WritePageAndRelease(pdfPage);
if(status != eSuccess)
break;
status = pdfWriter.EndPDF();
}while(false);
if(eSuccess == status)
cout<<"Succeeded in creating PDF file\n";
else
cout<<"Failed in creating PDF file\n";
return 0;
}
示例12: LogConfiguration
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;
}
示例13: LogConfiguration
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;
}
示例14: main
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;
}
示例15: main
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";
//.........这里部分代码省略.........