An EPUB file consists of multiple entries in a ZIP file. To extract the first chapter, you have to first determine how you know where the second chapter starts, as this doesn't have to coincide with an entry in the ZIP file.
Essentially what you need to do is:
- Extract and analyse "META-INF/container.xml" to determine where is the root content file of the document which can be in the root of the EPUB, but also in a subdirectory)
- Walk over the items in the content file to start building up the first chapter and accumulate data until you hit the second chapter.
- On the way there you might have to take care of included images, cross references and the like.
Once you have gathered this data, write out the first chapter into a new file. Care should be taken this is a valid EPUB file, that adheres to the restrictions on EPUB entry sizes that some older readers impose (i.e. split the HTML for the first chapter in small enough chunks). Any language with a good XML library (including namespaces), HTML parsing and a handling zip files should do the job. I tend to use Python for that.