Skip to content

Commit

Permalink
complement simple pdf to form method with input form id and implement…
Browse files Browse the repository at this point in the history
… drawImage with it. less error prone
  • Loading branch information
galkahana committed Oct 6, 2017
1 parent 31dc6a7 commit 3430e3b
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 91 deletions.
53 changes: 16 additions & 37 deletions PDFWriter/DocumentContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1356,9 +1356,10 @@ EStatusCodeAndObjectIDTypeList DocumentContext::CreateFormXObjectsFromPDF(const
const PDFPageRange& inPageRange,
EPDFPageBox inPageBoxToUseAsFormBox,
const double* inTransformationMatrix,
const ObjectIDTypeList& inCopyAdditionalObjects)
const ObjectIDTypeList& inCopyAdditionalObjects,
const ObjectIDTypeList& inPredefinedFormIDs)
{
return mPDFDocumentHandler.CreateFormXObjectsFromPDF(inPDFFilePath,inParsingOptions,inPageRange,inPageBoxToUseAsFormBox,inTransformationMatrix,inCopyAdditionalObjects);
return mPDFDocumentHandler.CreateFormXObjectsFromPDF(inPDFFilePath,inParsingOptions,inPageRange,inPageBoxToUseAsFormBox,inTransformationMatrix,inCopyAdditionalObjects,inPredefinedFormIDs);

}

Expand All @@ -1367,9 +1368,10 @@ EStatusCodeAndObjectIDTypeList DocumentContext::CreateFormXObjectsFromPDF(const
const PDFPageRange& inPageRange,
const PDFRectangle& inCropBox,
const double* inTransformationMatrix,
const ObjectIDTypeList& inCopyAdditionalObjects)
const ObjectIDTypeList& inCopyAdditionalObjects,
const ObjectIDTypeList& inPredefinedFormIDs)
{
return mPDFDocumentHandler.CreateFormXObjectsFromPDF(inPDFFilePath,inParsingOptions,inPageRange,inCropBox,inTransformationMatrix,inCopyAdditionalObjects);
return mPDFDocumentHandler.CreateFormXObjectsFromPDF(inPDFFilePath,inParsingOptions,inPageRange,inCropBox,inTransformationMatrix,inCopyAdditionalObjects, inPredefinedFormIDs);

}
EStatusCodeAndObjectIDTypeList DocumentContext::AppendPDFPagesFromPDF(const std::string& inPDFFilePath,
Expand Down Expand Up @@ -2014,19 +2016,21 @@ EStatusCodeAndObjectIDTypeList DocumentContext::CreateFormXObjectsFromPDF(IByteR
const PDFPageRange& inPageRange,
EPDFPageBox inPageBoxToUseAsFormBox,
const double* inTransformationMatrix,
const ObjectIDTypeList& inCopyAdditionalObjects)
const ObjectIDTypeList& inCopyAdditionalObjects,
const ObjectIDTypeList& inPredefinedFormIDs)
{
return mPDFDocumentHandler.CreateFormXObjectsFromPDF(inPDFStream, inParsingOptions,inPageRange,inPageBoxToUseAsFormBox,inTransformationMatrix,inCopyAdditionalObjects);
return mPDFDocumentHandler.CreateFormXObjectsFromPDF(inPDFStream, inParsingOptions,inPageRange,inPageBoxToUseAsFormBox,inTransformationMatrix,inCopyAdditionalObjects, inPredefinedFormIDs);
}

EStatusCodeAndObjectIDTypeList DocumentContext::CreateFormXObjectsFromPDF(IByteReaderWithPosition* inPDFStream,
const PDFParsingOptions& inParsingOptions,
const PDFPageRange& inPageRange,
const PDFRectangle& inCropBox,
const double* inTransformationMatrix,
const ObjectIDTypeList& inCopyAdditionalObjects)
const ObjectIDTypeList& inCopyAdditionalObjects,
const ObjectIDTypeList& inPredefinedFormIDs)
{
return mPDFDocumentHandler.CreateFormXObjectsFromPDF(inPDFStream,inParsingOptions,inPageRange,inCropBox,inTransformationMatrix,inCopyAdditionalObjects);
return mPDFDocumentHandler.CreateFormXObjectsFromPDF(inPDFStream,inParsingOptions,inPageRange,inCropBox,inTransformationMatrix,inCopyAdditionalObjects, inPredefinedFormIDs);
}

EStatusCodeAndObjectIDTypeList DocumentContext::AppendPDFPagesFromPDF(IByteReaderWithPosition* inPDFStream,
Expand Down Expand Up @@ -2935,36 +2939,11 @@ EStatusCode DocumentContext::WriteFormForImage(
{
case ePDF:
{
PDFDocumentCopyingContext* copyingContext = NULL;
PDFFormXObject* formXObject = NULL;
do {
// hmm...pdf merging doesn't have an innate method to force an object id. so i'll create a form, and merge into it
copyingContext = CreatePDFCopyingContext(inImagePath, inParsingOptions);
if(!copyingContext)
{
status = eFailure;
break;
}

PDFPageInput pageInput(copyingContext->GetSourceDocumentParser(),
copyingContext->GetSourceDocumentParser()->ParsePage(inImageIndex));

formXObject = StartFormXObject(pageInput.GetMediaBox(),inObjectID);
if(!formXObject)
{
status = eFailure;
break;
}

status = copyingContext->MergePDFPageToFormXObject(formXObject,inImageIndex);
if(status != eSuccess)
break;

status = EndFormXObject(formXObject);
}while(false);
PDFPageRange singlePageRange;
singlePageRange.mType = PDFPageRange::eRangeTypeSpecific;
singlePageRange.mSpecificRanges.push_back(ULongAndULong(inImageIndex, inImageIndex));

delete formXObject;
delete copyingContext;
status = CreateFormXObjectsFromPDF(inImagePath, inParsingOptions, singlePageRange, ePDFPageBoxMediaBox, NULL, ObjectIDTypeList(), ObjectIDTypeList(1, inObjectID)).first;
break;
}
case eJPG:
Expand Down
14 changes: 9 additions & 5 deletions PDFWriter/DocumentContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,35 +218,39 @@ namespace PDFHummus

// PDF
// CreateFormXObjectsFromPDF is for using input PDF pages as objects in one page or more. you can used the returned IDs to place the
// created form xobjects
// created form xobjects (note that you can provide your own as the inPredefinedFormIds...just make sure the list is same size as pages list)
EStatusCodeAndObjectIDTypeList CreateFormXObjectsFromPDF(const std::string& inPDFFilePath,
const PDFParsingOptions& inParsingOptions,
const PDFPageRange& inPageRange,
EPDFPageBox inPageBoxToUseAsFormBox,
const double* inTransformationMatrix = NULL,
const ObjectIDTypeList& inCopyAdditionalObjects = ObjectIDTypeList());
const ObjectIDTypeList& inCopyAdditionalObjects = ObjectIDTypeList(),
const ObjectIDTypeList& inPredefinedFormIDs = ObjectIDTypeList());

EStatusCodeAndObjectIDTypeList CreateFormXObjectsFromPDF(IByteReaderWithPosition* inPDFStream,
const PDFParsingOptions& inParsingOptions,
const PDFPageRange& inPageRange,
EPDFPageBox inPageBoxToUseAsFormBox,
const double* inTransformationMatrix = NULL,
const ObjectIDTypeList& inCopyAdditionalObjects = ObjectIDTypeList());
const ObjectIDTypeList& inCopyAdditionalObjects = ObjectIDTypeList(),
const ObjectIDTypeList& inPredefinedFormIDs = ObjectIDTypeList());

// CreateFormXObjectsFromPDF is an override to allow you to determine a custom crop for the page embed
EStatusCodeAndObjectIDTypeList CreateFormXObjectsFromPDF(const std::string& inPDFFilePath,
const PDFParsingOptions& inParsingOptions,
const PDFPageRange& inPageRange,
const PDFRectangle& inCropBox,
const double* inTransformationMatrix = NULL,
const ObjectIDTypeList& inCopyAdditionalObjects = ObjectIDTypeList());
const ObjectIDTypeList& inCopyAdditionalObjects = ObjectIDTypeList(),
const ObjectIDTypeList& inPredefinedFormIDs = ObjectIDTypeList());

EStatusCodeAndObjectIDTypeList CreateFormXObjectsFromPDF(IByteReaderWithPosition* inPDFStream,
const PDFParsingOptions& inParsingOptions,
const PDFPageRange& inPageRange,
const PDFRectangle& inCropBox,
const double* inTransformationMatrix = NULL,
const ObjectIDTypeList& inCopyAdditionalObjects = ObjectIDTypeList());
const ObjectIDTypeList& inCopyAdditionalObjects = ObjectIDTypeList(),
const ObjectIDTypeList& inPredefinedFormIDs = ObjectIDTypeList());

// AppendPDFPagesFromPDF is for simple appending of the input PDF pages
EStatusCodeAndObjectIDTypeList AppendPDFPagesFromPDF(const std::string& inPDFFilePath,
Expand Down
10 changes: 6 additions & 4 deletions PDFWriter/PDFDocumentCopyingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,18 @@ PDFHummus::EStatusCode PDFDocumentCopyingContext::Start(PDFParser* inPDFParser,

EStatusCodeAndObjectIDType PDFDocumentCopyingContext::CreateFormXObjectFromPDFPage(unsigned long inPageIndex,
EPDFPageBox inPageBoxToUseAsFormBox,
const double* inTransformationMatrix)
const double* inTransformationMatrix,
ObjectIDType inPredefinedFormId)
{
return mDocumentHandler.CreateFormXObjectFromPDFPage(inPageIndex,inPageBoxToUseAsFormBox,inTransformationMatrix);
return mDocumentHandler.CreateFormXObjectFromPDFPage(inPageIndex,inPageBoxToUseAsFormBox,inTransformationMatrix, inPredefinedFormId);
}

EStatusCodeAndObjectIDType PDFDocumentCopyingContext::CreateFormXObjectFromPDFPage(unsigned long inPageIndex,
const PDFRectangle& inCropBox,
const double* inTransformationMatrix)
const double* inTransformationMatrix,
ObjectIDType inPredefinedFormId)
{
return mDocumentHandler.CreateFormXObjectFromPDFPage(inPageIndex,inCropBox,inTransformationMatrix);
return mDocumentHandler.CreateFormXObjectFromPDFPage(inPageIndex,inCropBox,inTransformationMatrix, inPredefinedFormId);
}


Expand Down
8 changes: 5 additions & 3 deletions PDFWriter/PDFDocumentCopyingContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ class PDFDocumentCopyingContext

EStatusCodeAndObjectIDType CreateFormXObjectFromPDFPage(unsigned long inPageIndex,
EPDFPageBox inPageBoxToUseAsFormBox,
const double* inTransformationMatrix = NULL);
const double* inTransformationMatrix = NULL,
ObjectIDType inPredefinedFormId = 0);
EStatusCodeAndObjectIDType CreateFormXObjectFromPDFPage(unsigned long inPageIndex,
const PDFRectangle& inCropBox,
const double* inTransformationMatrix = NULL);
const PDFRectangle& inCropBox,
const double* inTransformationMatrix = NULL,
ObjectIDType inPredefinedFormId = 0);
EStatusCodeAndObjectIDType AppendPDFPageFromPDF(unsigned long inPageIndex);
PDFHummus::EStatusCode MergePDFPageToPage(PDFPage* inTargetPage,unsigned long inSourcePageIndex);

Expand Down
Loading

0 comments on commit 3430e3b

Please sign in to comment.