Could you please help me How to merge two pdf files which are coming from two flow files into one pdf file in Nifi.
I'm trying to merge two files (invoice file and QR File) from two flowfiles and used mergecontent processor but only single file(first file from 2 input files but not merged file) coming as merged file, with the combined file size.
for the first flow file updateattribute maintained fragment.index=0 and second flowfile udpateattribute maintained fragment.index=1 and for combined flowfile updateattribute Before merge processor given fragment.count=2
the problem you have with the merge is that your property "Merge Strategy" needs to be set to "Defragment" after that it should work if both flowfiles also have the same fragment.identifier set.
To merge those pdfs Im not 100% sure how it can be easily done, but one solution would be to set also the property "Merge Format" to tar/zip of your MergeContent processor and do it later via script unpack and merge together.
NiFi is designed to be data agnostic. So content that NiFi ingested is preserved in binary format wrapped in a NIFi FlowFile. It then becomes the responsibility of an individual processor that needs to operate against the content to understand the content type.
The mergeContent processor does not care about the content type. This processor numerous merge strategies: - Binary concatenation simply writes the binary data from one FlowFile to the end of the binary data from another. There is no specific handling based on the content type. So combining two PDF files in this manor is going to leave you with unreadable data which explains why even with the larger content type of the merged FlowFile, you still only see the first PDF in the merged binary. - Tar and zip combines multiple pieces of content in to a single tar file. You can then later untar or unzip this to extract the multiple separate pieces of content it contains. So would preserve both independent PDF files. - FlowFile stream is unique to NiFi and merges multiple NiFi FLowFiles (A FlowFile consist of content and FlowFile metadata. This strategy is only used to preserve that NiFi metadata with the content for future access by another NiFi. - Avro expects the content being merged is already of Avro format. This will properly merge Avro type data in to single new Avro content.
So the question here is first, how would you accomplish the merging of two PDF outside of NiFi. Then investigate how to accomplish the same within NiFi, if possible. TAR and ZIP will work to get you one output file; however, if your use case is to produce 1 new PDF form 2 original PDFs, mergeContent is not going to do that.
If you found that the provided solution(s) assisted you with your query, please take a moment to login and click Accept as Solution below each response that helped.