Why does a surface term have to vanish for an operator to be Hermitian? In section $1.10$ of Shankar's Principles of Quantum Mechanics, it is stated that an operator $K$ satisfying $\langle x \vert K \vert x' \rangle = \langle x' \vert K \vert x \rangle ^*$ is not  enough to guarantee that $\langle g \vert K \vert f \rangle = \langle f \vert K \vert g \rangle ^*$, and thus that $K$ is Hermitian. An explicit computation is given when $K = -iD$, in which it is found that the surface term $$ig^*(x) f(x) \bigg\vert_{a}^{b}$$ must vanish for $K$ to be Hermitian. I'm able to follow the derivation, however, I'm still not sure why said surface term has to vanish, since it seems to me I can show that without assuming such thing. Below is a sketch of what I mean:
Writing down $\vert f \rangle$ and $\vert g \rangle$ in my basis,
\begin{align} 
\vert f \rangle &= \int_{a}^{b} dx' \, f(x') \, \vert x' \rangle \, ; \\
\vert g \rangle &= \int_{a}^{b} dx \, g(x) \, \vert x \rangle \, . 
\end{align}
Then we have,
\begin{align} 
\langle g \vert K \vert f \rangle &= \int_{a}^{b} \int_{a}^{b} dx \, dx' \, g^*(x) \, f(x') \, \langle x \vert K \vert x' \rangle \\ 
&= \int_{a}^{b} \int_{a}^{b} dx \, dx' \, g^*(x) \, f(x') \, \langle x' \vert K \vert x \rangle ^* \\ 
&= \left(\int_{a}^{b} \int_{a}^{b} dx \, dx' \, g(x) \, f^*(x') \, \langle x' \vert K \vert x \rangle \right)^*
= \langle f \vert K \vert g \rangle ^*.
\end{align}
I guess my question is the following: is my derivation correct, and if it is, where am I  assuming that such a surface term vanishes?
 A: You are assuming that $\langle x|K|x'\rangle$ is a simple number which can be straightforwardly complex conjugated.  Indeed, if $\langle x|K|x'\rangle = K_{xx'}$ is a $\mathbb C$-number such that $K_{xx'} = K_{x'x}^*$, then it is indeed Hermitian as you have shown (I will not consider the distinction between Hermitian and self-adjoint operators here).
However, this is generally not the case - in particular, we might take your example that that $K = iD$ (with $D$ the differentiation operator).  In that case, $K_{xx'} = i\delta(x-x') \frac{d}{dx}$, and it is by no means obvious how we might take the complex conjugate of such an object.  Inserting that into your calculation above will result in $\langle f|K|g\rangle$ and $\langle g|K|f\rangle$ differing by precisely the surface term you're asking about.
Ultimately this subtlety arises because we are making use of the position basis $|x\rangle$, which (while useful) comes with a host of technical subtleties related to the fact that the generalized position eigenstates are not actually elements of the Hilbert space, and so $|x\rangle$ is not a true basis in the conventional sense.  If we choose a genuine (countable, orthonormal) basis of the Hilbert space $|\phi_i\rangle$, then the fact that $K_{ij} \equiv \langle \phi_i|K|\phi_j\rangle$ satisfies $K_{ij}=K^*_{ji}$ is indeed sufficient to show that $K$ is Hermitian, because all of the $K_{ij}$'s are simply $\mathbb C$-numbers and so
$$|f\rangle = \sum_i \alpha_i |\phi_i\rangle \qquad |g\rangle = \sum_i \beta_i |\phi_i\rangle$$
$$\langle f|K|g\rangle = \sum_i \sum_j \alpha^*_i \beta_j  K_{ij} =\bigg(\sum_i \sum_j \beta_i \alpha_j^* K_{ij}\bigg)^* = \langle g|K|f\rangle^*$$

As a concrete example, we might consider the differentiation operator $D$ defined on the ring, corresponding to the Hilbert space $L^2([0,1])$ with periodic boundary conditions (as before, I won't concern myself with domain issues).  Noting that $D_{xx'} = \delta(x-x') \frac{d}{dx}$, we observe that there are no $i$'s to flip.  However, in the eigenbasis of the Hamiltonian operator $H:= -\frac{1}{2} \frac{d^2}{dx^2}$ defined with periodic boundary conditions, we have that
$$\phi_n(x) = e^{2\pi i n x}, n\in \mathbb Z$$
$$D_{n,m} = \langle \phi_n|D|\phi_m\rangle = \int_0^1 \mathrm dx \big(e^{2\pi i n x}\big)^*\big(2\pi i m e^{2\pi i m x}\big)$$
$$=2\pi i m \delta_{nm}$$
So we see - even though $D_{xx'} = \delta(x-x') \frac{d}{dx}$ has no visible $i$'s in it, the matrix elements of $D$ in a proper basis are $D_{nm} = 2\pi i m \delta_{nm}$, which immediately implies that $D$ is not Hermitian (in fact, $D^\dagger = -D$).
