At that time, in Beijing, the capital of the Qing Dynasty, opera performances were extremely prosperous. Kong Shangren devoted himself to opera creation in his spare time. In the 33rd year of Kangxi's reign (1694), "The Legend of Xiaohu Lei", a collaboration with Gu Cai, was performed at the Jingyun Department and was highly praised by the audience. In June of the thirty-eighth year of Kangxi (1699), the legendary drama "The Peach Blossom Fan", which he had painstakingly created for more than ten years, was completed. The play takes the love story of Hou Fangyu, a famous scholar from Fushe, and Li Xiangjun, a famous prostitute from Qinhuai, as the main line. It extensively and profoundly reflects the history of the demise of the Southern Ming Dynasty. many readers and viewers. Princes and dignitaries rushed to pass it on, and the Qing court and famous Kunqu opera troupes competed to perform it, causing a sensation in the capital. Emperor Kangxi sent someone to ask for the manuscript of "The Peach Blossom Fan". At that time, he and Hong Sheng, the author of "Eternal Life Palace", were known as "Southern Hong and Northern Kong". In the spring of the next year, he was dismissed from office because of a suspicious case.
In the twenty-fourth year of Kangxi (1685), Emperor Kangxi went to Qufu to worship Confucius when he returned from his southern tour to the north. Kong Shangren was praised for his lectures on "Speech" before the emperor and was appointed as a doctor of the Imperial College. So he embraced Confucian political ideals and began his career as an official. He also wrote an article "The Strange Numbers Out of the Mountain" to express his gratitude to the Qing Dynasty. But just a year later, when he was on a business trip to Huaiyang to dredge the mouth of the Yellow River, he came into contact with the dark social reality and gradually realized the corruption of officialdom. After returning to Beijing, although he succeeded him as a doctor of the Imperial College and other officials, he mainly filled his idle life with reading and collecting antiquities; he used opera and poetry creation to express his depressed mind. It was during this period that "The Peach Blossom Fan" was finally completed. "The Peach Blossom Fan" embodies Kong Shangren's lifelong energy. He said: "When I was not in office, every time I planned to write this legend, I was afraid that it would not be widely heard and seen, and I would not believe it. For the rest of the poem, I only drew its outline, but did not actually decorate it. Cai Ye. However, he always praised his close friends and said, "I have the legend of "Peach Blossom Fan", which is still in my pillow." When I went to Suomi Chang'an, I often had banquets with my colleagues." ("The Complete Story of Peach Blossom Fan") ) during the river management period, he lived in Taizhou and also worked on script creation. "Novel Branch Talk·Peach Blossom Fan" quotes "Yu Yu" and says: "Kong Dongtang was still working with Sun Sikong on the river dredging project in Fengkanli. He lived in the Xianyingbizaoyuan. At that time, the Peach Blossom Fan was not completed. The songs are sung, and every time they come out, Yingbi is always invited to give them a reward." He himself and his friends have the same record. At the same time, he got acquainted with survivors such as Mao Pijiang, Deng Xiaowei, Du Jun, Seng Shitao, etc., and obtained a lot of anecdotes and historical materials, making full preparations for the final draft of "The Peach Blossom Fan". After returning to Beijing, after ten years of bleak management and three revisions of manuscripts, the book was completed in the 38th year of Kangxi's reign. The following year, he was dismissed from office due to writing problems. Two years later, he left Beijing and returned to his hometown with attachment and anger. "We shed tears to reward our close friends, and we sang and asked God. I really dislike the filthy grass, but I don't believe in the beauty." ("Farewell to Mr. Ruan Ting, the King of Farewell"); "The poet is not a ruthless guest. He loves the palace and misses his hometown." ("Chu Zhangyi") "Gate"): This is a confession of his mood at that time. In his later years, he traveled several times, but the situation was quite depressed.
In addition to "The Peach Blossom Fan", Kong Shangren's drama works include the legendary "Little Hu Lei" co-written by Jia Jia and Gu Cai. Xiaohulei was a musical instrument in the palace of the Tang Dynasty. Duan Anjie's "Yuefu Miscellanies" records that Zheng Zhongcheng, a Tang palace maid who was good at playing Xiaohulei, died for disobeying the imperial decree and was rescued by Liang Houben, an old official of Prime Minister Quan Deyu. A legend for the couple. The legend of "Little Hu Lei" is based on this, and involves the lives of famous literati Bai Juyi, Liu Yuxi and others at that time. It describes the struggle between scribes and eunuchs. The theme structure is similar to "The Peach Blossom Fan", but its practical significance is different from that of "The Peach Blossom Fan". The artistic achievements are far inferior to "The Peach Blossom Fan".