[Tex/LaTex] PDF Bookmark hierarchy incorrect

bookmarkspdftable of contents

I'm having the same problem as that noted in This question: namely, the pdf bookmarks are incorrect, with some sections incorrectly subsumed under others. However, the code that I'm using is somewhat different, so I'm not sure if the same solution applies. The appearance in the actual document is exactly as I'd like it to be, but I'd like the bookmarks to be correct as well.

Below is a MWE. The problem is presumably due to the addcontentsline.

\documentclass{book}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage[hidelinks]{hyperref}


\begin{document}

\tableofcontents
\chapter{First}

\section{introduction}

\blindtext

\newpage 
\vspace*{\fill}

{ 
\addcontentsline{toc}{section}{\protect\numberline{}APPENDICES}
\Huge
\begin{center}  \textbf{APPENDICES}
\end{center}
}
\vspace*{\fill}
\newpage 
test
\subsection*{Appendix A}
\addcontentsline{toc}{subsection}{\protect\numberline{}APPENDIX A}
\blindtext

\subsection*{Appendix B}
\addcontentsline{toc}{subsection}{\protect\numberline{}APPENDIX B}
\blindtext
\chapter{Second}

\section{Introduction}

\blindtext

\end{document}

Best Answer

Manual additions to the ToC should be accompanied with \phantomsection before the sectioning command is issued, when used in conjunction with hyperref package.

\documentclass{book}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage[hidelinks,bookmarksopen=true]{hyperref}


\begin{document}

\tableofcontents
\chapter{First}

\section{Introduction}

\blindtext

\newpage 
\vspace*{\fill}

{ 
\phantomsection
\addcontentsline{toc}{section}{\protect\numberline{}APPENDICES}
\Huge
\begin{center}  \textbf{APPENDICES}
\end{center}
}
\vspace*{\fill}
\newpage 
test
\phantomsection
\subsection*{Appendix A}
\addcontentsline{toc}{subsection}{\protect\numberline{}APPENDIX A}
\blindtext

\phantomsection
\subsection*{Appendix B}
\addcontentsline{toc}{subsection}{\protect\numberline{}APPENDIX B}
\blindtext
\chapter{Second}

\section{Introduction}

\blindtext

\end{document}

enter image description here

Related Question