# Join/Split PDF based on Size

**URL:** <https://forum.uipath.com/t/join-split-pdf-based-on-size/193092>\
**Category:** Help\
**Tags:** question, pdf, activities\
**Created:** [February 11, 2020, 4:04pm UTC](https://forum.uipath.com/t/join-split-pdf-based-on-size/193092 "2020-02-11T16:04:26Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anshuman\_Malik](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/anshuman_malik/32/59503_2.png) [@Anshuman\_Malik](https://forum.uipath.com/u/Anshuman_Malik)\
**Post date:** [February 11, 2020, 4:04pm UTC](https://forum.uipath.com/t/join-split-pdf-based-on-size/193092/1 "2020-02-11T16:04:26Z")

</div>

Hi I have PDF files in a folder that I want to join first based on the criteria on (10MB each).  
What I am trying to achieve is if the file size reaches 10mb then it should create another file with the same name but add a counter to it? Please can anyone help? or if you have a sample workflow that would work for me too.

Eg: of filename -  
1.) abc.pdf  
2.)abc\_v1.pdf  
Note: Some of my pdf files have attachments so I can not use merge pdf activity.

---

<div class="post-metadata">

**Author:** ![Palaniyappan](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/palaniyappan/32/524095_2.png) [@Palaniyappan](https://forum.uipath.com/u/Palaniyappan)\
**Post date:** [February 12, 2020, 10:17am UTC](https://forum.uipath.com/t/join-split-pdf-based-on-size/193092/2 "2020-02-12T10:17:30Z")

</div>

Hi  
First let’s get the filepath of all files in a folder  
—now use a ASSIGN activity like this  
**arr\_filepath = Directory.GetFiles(“yourfolderpath”)**

Where arr\_filepath is a variable of type array of string

—now use a FOR EACH activity and pass the above variable as input and change the type argument as string

—inside the loop use a IF condition like this  
**New System.IO.FilePath(item.ToStrings).Length \> 10000000**

If true it will go to THEN part where we can use Copy File activity and mention the filepath with the name we want in destination property

Cheers @Anshuman_Malik

---

<div class="post-metadata">

**Author:** ![Anshuman\_Malik](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/anshuman_malik/32/59503_2.png) [@Anshuman\_Malik](https://forum.uipath.com/u/Anshuman_Malik)\
**Post date:** [February 12, 2020, 4:22pm UTC](https://forum.uipath.com/t/join-split-pdf-based-on-size/193092/3 "2020-02-12T16:22:05Z")

</div>

Hi @Palaniyappan,

Thank you for that, however my task is a bit different. See screenshot attached. Based on the file size I trying to join all the pdf’s together which are less than 10mb (i.e file number 1, 2 and 3) and then have another file (file 4 in my case) since it is almost 10mb.

I have to upload these files to a portal in batches and the limitation is 10mb per file.

 ![image](https://global.discourse-cdn.com/uipath/original/3X/c/4/c415681491f017228b0e0beafed37425f049e08f.png)

---

<div class="post-metadata">

**Author:** ![Anshuman\_Malik](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/anshuman_malik/32/59503_2.png) [@Anshuman\_Malik](https://forum.uipath.com/u/Anshuman_Malik)\
**Post date:** [February 14, 2020, 8:21pm UTC](https://forum.uipath.com/t/join-split-pdf-based-on-size/193092/4 "2020-02-14T20:21:30Z")

</div>

@Palaniyappan

---

<div class="post-metadata">

**Author:** ![Anshuman\_Malik](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/anshuman_malik/32/59503_2.png) [@Anshuman\_Malik](https://forum.uipath.com/u/Anshuman_Malik)\
**Post date:** [February 14, 2020, 8:23pm UTC](https://forum.uipath.com/t/join-split-pdf-based-on-size/193092/5 "2020-02-14T20:23:31Z")

</div>

@ClaytonM

---

<div class="post-metadata">

**Author:** ![ClaytonM](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/claytonm/32/555957_2.png) [@ClaytonM](https://forum.uipath.com/u/ClaytonM)\
**Post date:** [February 14, 2020, 8:38pm UTC](https://forum.uipath.com/t/join-split-pdf-based-on-size/193092/6 "2020-02-14T20:38:08Z")

</div>

I am actually doing the same thing today, with a limit of 50MB.

I can get back to you how to do this when I have time.

Regards.

---

<div class="post-metadata">

**Author:** ![Anshuman\_Malik](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/anshuman_malik/32/59503_2.png) [@Anshuman\_Malik](https://forum.uipath.com/u/Anshuman_Malik)\
**Post date:** [February 14, 2020, 8:42pm UTC](https://forum.uipath.com/t/join-split-pdf-based-on-size/193092/7 "2020-02-14T20:42:24Z")

</div>

THanks @ClaytonM, I am stuck at this loop and I have to get this done by Tuesday if you get a chance please attach your workfile.

---

<div class="post-metadata">

**Author:** ![bcorrea](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/bcorrea/32/103778_2.png) [@bcorrea](https://forum.uipath.com/u/bcorrea)\
**Post date:** [February 14, 2020, 8:51pm UTC](https://forum.uipath.com/t/join-split-pdf-based-on-size/193092/8 "2020-02-14T20:51:30Z")

</div>

but do you want to put the PDFs together in like a zip file or really join to have only one PDF with the content of others until you have groups of 10MB?

---

<div class="post-metadata">

**Author:** ![ClaytonM](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/claytonm/32/555957_2.png) [@ClaytonM](https://forum.uipath.com/u/ClaytonM)\
**Post date:** [February 14, 2020, 9:05pm UTC](https://forum.uipath.com/t/join-split-pdf-based-on-size/193092/9 "2020-02-14T21:05:20Z")

</div>

I’m assuming he just needs to loop the upload process in groups. Like there is probably an add button to select file(s). He would just need to make an array of the files grouped by file size, then run that with the ForEach to call the upload part inside the loop.

---

<div class="post-metadata">

**Author:** ![ClaytonM](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/claytonm/32/555957_2.png) [@ClaytonM](https://forum.uipath.com/u/ClaytonM)\
**Post date:** [February 14, 2020, 9:08pm UTC](https://forum.uipath.com/t/join-split-pdf-based-on-size/193092/10 "2020-02-14T21:08:19Z")

</div>

But, if he wants to merge the groups to a pdf, then he would need to do the same thing, but would just need to either merge or zip the groups of files.

---

<div class="post-metadata">

**Author:** ![bcorrea](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/bcorrea/32/103778_2.png) [@bcorrea](https://forum.uipath.com/u/bcorrea)\
**Post date:** [February 14, 2020, 9:09pm UTC](https://forum.uipath.com/t/join-split-pdf-based-on-size/193092/11 "2020-02-14T21:09:36Z")

</div>

i guess i dont have so much creativity to understand some topics 🙂 but that would be kind of easy to do creating a string list and adding file by file checking total size until reachs around 10MB…

---

<div class="post-metadata">

**Author:** ![Anshuman\_Malik](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/anshuman_malik/32/59503_2.png) [@Anshuman\_Malik](https://forum.uipath.com/u/Anshuman_Malik)\
**Post date:** [February 14, 2020, 9:51pm UTC](https://forum.uipath.com/t/join-split-pdf-based-on-size/193092/12 "2020-02-14T21:51:59Z")

</div>

@ClaytonM: you are absolutely correct. This is exactly what I want but instead of uploading I want to join those files.

The portion I am stuck with is building that logic/loop to identify the group of files.

@bcorrea: You are also correct it your logic. Fact being I am stuck on that logic building part.

---

<div class="post-metadata">

**Author:** ![alin.c.mihalea](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/alin.c.mihalea/32/133577_2.png) [@alin.c.mihalea](https://forum.uipath.com/u/alin.c.mihalea)\
**Post date:** [February 14, 2020, 10:29pm UTC](https://forum.uipath.com/t/join-split-pdf-based-on-size/193092/13 "2020-02-14T22:29:40Z")

</div>

Hey @Anshuman_Malik

Maybe you can make use of the C# code from this post - invoke in UiPath or by using the corresponding activities:

> <https://stackoverflow.com/questions/4632322/finding-all-possible-combinations-of-numbers-to-reach-a-given-sum/4633515#4633515>

It will output the combinations from the array that sum to a predefined target. The array may store pdf file sizes, in your case, and the target - 10mb.

Then loop by decreasing the target - not very likely to reach exactly 10 mb.

---

<div class="post-metadata">

**Author:** ![Anshuman\_Malik](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/anshuman_malik/32/59503_2.png) [@Anshuman\_Malik](https://forum.uipath.com/u/Anshuman_Malik)\
**Post date:** [February 14, 2020, 10:36pm UTC](https://forum.uipath.com/t/join-split-pdf-based-on-size/193092/14 "2020-02-14T22:36:12Z")

</div>

thank you @alin.c.mihalea but this makes combinations of files but I need unique files. So does not help me much. Also, I am not well versed with coding.

---

<div class="post-metadata">

**Author:** ![alin.c.mihalea](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/alin.c.mihalea/32/133577_2.png) [@alin.c.mihalea](https://forum.uipath.com/u/alin.c.mihalea)\
**Post date:** [February 14, 2020, 10:41pm UTC](https://forum.uipath.com/t/join-split-pdf-based-on-size/193092/15 "2020-02-14T22:41:19Z")

</div>

Another idea:

1. Store file sizes in an array

2. Implement a function to compute every possible sum of combinations from that array

For example:  
{1,2,3} =\> sums: 1, 2, 3, 1+2, 1+3, 2+3, 1+2+3

1. Check which sum is closest to 10mb and join those files. (Compute difference: 10mb - sum)

2. Recreate the array without the files from Step 3.

3. Step 2 again.

And so on.

---

<div class="post-metadata">

**Author:** ![Anshuman\_Malik](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/anshuman_malik/32/59503_2.png) [@Anshuman\_Malik](https://forum.uipath.com/u/Anshuman_Malik)\
**Post date:** [February 14, 2020, 10:45pm UTC](https://forum.uipath.com/t/join-split-pdf-based-on-size/193092/16 "2020-02-14T22:45:48Z")

</div>

THank you let me see if this works for me or not.

---

<div class="post-metadata">

**Author:** ![Anshuman\_Malik](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/anshuman_malik/32/59503_2.png) [@Anshuman\_Malik](https://forum.uipath.com/u/Anshuman_Malik)\
**Post date:** [February 15, 2020, 7:56pm UTC](https://forum.uipath.com/t/join-split-pdf-based-on-size/193092/17 "2020-02-15T19:56:12Z")

</div>

@ClaytonM @Palaniyappanany any luck?

---

<div class="post-metadata">

**Author:** ![Anshuman\_Malik](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/anshuman_malik/32/59503_2.png) [@Anshuman\_Malik](https://forum.uipath.com/u/Anshuman_Malik)\
**Post date:** [February 15, 2020, 10:24pm UTC](https://forum.uipath.com/t/join-split-pdf-based-on-size/193092/18 "2020-02-15T22:24:25Z")

</div>

@aksh1yadav please can you help?

---

<div class="post-metadata">

**Author:** ![bcorrea](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/bcorrea/32/103778_2.png) [@bcorrea](https://forum.uipath.com/u/bcorrea)\
**Post date:** [February 17, 2020, 1:21pm UTC](https://forum.uipath.com/t/join-split-pdf-based-on-size/193092/19 "2020-02-17T13:21:16Z")

</div>

Can you be more specific in what do you need to do when you find files that sum 10MB? is it to zip them together or what?

---

<div class="post-metadata">

**Author:** ![Anshuman\_Malik](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/anshuman_malik/32/59503_2.png) [@Anshuman\_Malik](https://forum.uipath.com/u/Anshuman_Malik)\
**Post date:** [February 17, 2020, 4:13pm UTC](https://forum.uipath.com/t/join-split-pdf-based-on-size/193092/20 "2020-02-17T16:13:08Z")

</div>

get all the file names in a string which I can then pass to Join PDF activity. I am not able to figure out this part

[Next page](https://forum.uipath.com/t/join-split-pdf-based-on-size/193092.md?page=2)
