A Maryland man charged with rampaging through a newsroom in Annapolis with a pump-action shotgun and killing five people was denied bail on Friday after one of the deadliest attacks on journalists in U.S. history.

Jarrod Ramos, 38, from Laurel, 25 miles (40km) west of Annapolis, is not cooperating with investigators, authorities said, and did not speak as he appeared by video link from a detention facility for a brief court hearing at Anne Arundel County criminal court.

Ramos had a longstanding grudge against the newspaper that was targeted and unsuccessfully sued it for defamation in 2012 over an article that reported how he harassed a former high school classmate, court records showed.

He is accused of entering the Capital Gazette office on Thursday afternoon and opening fire through a glass door, hunting for victims and spraying the newsroom with gunfire as reporters hid under their desks and begged for help on social media. Prosecutors said he barricaded a back door to stop people from fleeing.

"The fellow was there to kill as many people as he could," Anne Arundel County Police Chief Timothy Altomare told a news conference, adding that the suspect was identified using facial-recognition technology.

Altomare said evidence found at the suspect's home showed he planned the attack, and that the pump-action 12 gauge shotgun used by the shooter was legally purchased about a year ago.

Rob Hiaasen, 59, Wendi Winters, 65, Rebecca Smith, 34, Gerald Fischman, 61, and John McNamara were shot and killed. All were journalists except for Smith who was a sales assistant, police said. Hiaasen was the brother of best-selling author Carl Hiaasen.

(from left) Rob Hiaasen, Wendi Winters, John McNamara, Rebecca Smith, and Gerald Fischman. - Capital Gazette/REUTERS
The Capital newspaper, part of the Gazette group, published an edition on Friday with photographs of each of the victims and a headline "5 shot dead at The Capital" on its front page.

The newspaper's editors left the editorial page blank with a note saying that they were speechless.

Photographs that were widely shared on social media showed newspaper staffers working on laptops in a parking garage to produce Friday's edition while they waited to learn the fate of colleagues after the shooting.

'LIKE A WAR ZONE'

Annapolis Mayor Gavin Buckley said he was so proud of the journalists who had "soldiered on."

"These guys, they don't make a lot of money. They do journalism because they love what they do. And they got a newspaper out today," Buckley told Fox News.

A vigil for the victims was planned for 8:00 p.m. EDT on Friday. Maryland Governor Larry Hogan ordered state flags to be lowered to half-staff.

Ramos brought a defamation lawsuit in 2012 against Eric Hartley, a former staff writer and columnist with Capital Gazette, and Thomas Marquardt, then its editor and publisher, a court filing showed.

Neither Hartley nor Marquardt is still employed by the paper or were at its office on Thursday.

An article by Hartley had contended that Ramos had harassed a woman on Facebook and that he had pleaded guilty to criminal harassment, according to a legal document.

The court agreed the article was accurate and based on public records, the document showed. In 2015 Maryland's second-highest court upheld the ruling, rejecting Ramos's suit.

Ramos tweeted at the time that he had set up a Twitter account to defend himself, and wrote in his biographical notes that he was suing people in Anne Arundel County and "making corpses of corrupt careers and corporate entities."

According to a WBAL-TV reporter who said she spoke with the woman who was harassed, Ramos became "fixated" with her for no apparent reason, causing her to move three times, change her name, and sleep with a gun.

Phil Davis, a Capital Gazette crime reporter, recounted how he was hiding under his desk along with other newspaper employees when the shooter stopped firing, the Capital Gazette reported on its website.

The newsroom looked "like a war zone," he told the Baltimore Sun. "I don't know why he stopped."

Authorities responded to the scene within a minute of the shooting, and Ramos was arrested while also hiding under a desk with the shotgun on the floor nearby, police said.

He will face either a preliminary court hearing or grand jury indictment within the next 30 days.

Capital Gazette runs several newspapers out of its Annapolis office. They include one of the oldest newspapers in the United States, The Gazette, which traces its origins back to 1727.