Skip to content
James Bower
James Bower

Quantitative AI Security

  • Tools
  • Audit
  • Guides
  • Courses
  • Newsletter
James Bower

Quantitative AI Security

How to Convert Threat Intelligence PDF into Text

James Bower, September 2, 2009April 21, 2023

Here’s your guide to effortlessly convert threat intelligence from cumbersome PDFs (blah to work with), into easily accessible text, streamlining your cybersecurity analysis and response like never before! I’m sure like me you’ve been struggling to convert threat intelligence PDFs into text? Well I hear you friend. As you know my Python isn’t the greatest so this has taken me awhile to figure out. But all those lonely nights have paid off. Continue reading for how I did it.

The PDF that I’m using is a threat assessment from the Senate Select Committee on Intelligence. Why? Because it sounds cool of course! And if I’m going to work on a project I at least want to feel like Ja

The PDF that I’m using is a threat assessment from the Senate Select Committee on Intelligence. Why? Because it sounds cool of course! And if I’m going to work on a project I at least want to feel like James Bond doing it! I put it up on Dropbox so you can grab it yourself. I put it up on Dropbox so you can grab it yourself.

https://bit.ly/41pNT2C

Let’s look at a paragraph from the second page as our example for comparison. It’s pretty straight forward as far as text goes. It gets a lot more difficult when dealing with tables and images. But we’ll discuss that in another blog post.

Here is the code I used and I pinned the version of pdfminer to help prevent any issues. I also did this in Python 2.5

easy_install pip
pip install 'pdfminer==20080407'
import sys
import urllib
from pdfminer.pdfparser import PDFParser
from pdfminer.pdfdocument import PDFDocument
from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
from pdfminer.converter import TextConverter
from pdfminer.layout import LAParams
from pdfminer.pdfpage import PDFPage
from cStringIO import StringIO
def download_pdf(url, file_name):
    urllib.urlretrieve(url, file_name)
def convert_pdf_to_txt(file_path):
    rsrcmgr = PDFResourceManager()
    retstr = StringIO()
    codec = 'utf-8'
    laparams = LAParams()
    device = TextConverter(rsrcmgr, retstr, codec=codec, laparams=laparams)
    fp = open(file_path, 'rb')
    parser = PDFParser(fp)
    doc = PDFDocument(parser)
    interpreter = PDFPageInterpreter(rsrcmgr, device)
    for page in PDFPage.create_pages(doc):
        interpreter.process_page(page)
    fp.close()
    device.close()
    text = retstr.getvalue()
    retstr.close()
    return text
pdf_url = "https://www.dropbox.com/s/e7ho2tentz3fns4/2009_threat_assessment_intelligence_subcommittee.pdf?dl=0"
input_pdf = "input.pdf"
output_txt = "output.txt"
download_pdf(pdf_url, input_pdf)
with open(output_txt, "w") as output_file:
    output_file.write(convert_pdf_to_txt(input_pdf))

Here’s what it should look like now. You can we have some new line and spacing issues. Also some slight formatting issues. But overall I would say it looks pretty darn good and is definitely something we can work with moving forward.

And there you have it! And here is the link to our new “text” file.

https://www.dropbox.com/s/gsk1gieyihg3od0/threat_assessment.txt?dl=0

I hope you have found this useful. This is something I’ve been wanting to figure out for some time now. Also make sure to keep coming back to my blog as I’m going to be putting out more threat intelligence posts here:

https://www.jamesbower.com/category/threat-intelligence/

And as always, thank you for taking the time to read this. If you have any comments, questions, or critiques, please reach out to me on our FREE ML Security Discord Server – HERE

Text Analytics Threat Intelligence NLTKpdfminer

Post navigation

Previous post
Next post

Related Posts

Threat Intelligence

Threat Profile: Killer Swag

June 13, 2017April 21, 2023

Introduction I’ve been monitoring an interesting threat for the past several days, a group I’m referring to as “Killer Swag”. Mainly because the initial dropper is called “Swag.sh” and “Killer Swag” just sounds cool. In another life I think I would have been a marketing genius, but I digress. This…

Read More
Security Tools

DNS Enumeration Uncut: The Best Guide for Hackers

April 17, 2016April 21, 2023

DNS enumeration and DNS reconnaissance is a critical threat intelligence skill to learn. In literally every aspect of threat intel you will end up running into malicious domains. For me this most often occurs when working with threat intel from my honeynet. An example would be when I come across a…

Read More
Entity Recognition

Unlock the Potential of Text Analytics with Python NLTK

March 1, 2016April 21, 2023

Introduction Let’s start at the beginning. As businesses and organizations collect more data than ever, it’s essential to make sense of it so we can drive informed decision-making. Text Analytics is a subfield of Natural Language Processing (NLP) that analyzes unstructured or semi-structured text data. What is Text Analytics? Text…

Read More
  • Twitter
  • GitHub
  • YouTube
  • LinkedIn

Videos

https://www.youtube.com/watch?v=FEb8KZoEyzI&t=1291s

Categories

  • Active Defense
  • Anomaly Detection
  • AWS
  • Books
  • Business
  • CTF
  • Decision Intelligence
  • Deep Learning
  • Detection Engineering
  • EDA
  • Entity Recognition
  • Health
  • Linux
  • LLM
  • Machine Learning
  • Memory Forensics
  • NIDS
  • NLG
  • NLP
  • Operating Systems
  • Productivity
  • Python
  • Quantitative Security
  • Security Tools
  • Sentiment Analysis
  • Tech
  • Text Analytics
  • Threat Hunting
  • Threat Intelligence
  • Topic Modeling
  • UEBA

Recent Posts

  • Detection Rule Staleness: How AI Can Solve This Now
  • How to Think About Low-Latency Development with Python
  • Managing Noise In AI Security Machine Learning
  • Dimensionality Reduction: Find the Best Method for Your Data
  • Improved Anomaly Detection in Cybersecurity using Model Cascading

Tags

Apache BERT Boot2Root classification Conda Data Augmentation ddos Diet Dirb Ensemble ETL featured Firewall FreeBSD GPT-3 Hacking Hacking Challenge Htop Kioptrix LiME LLM low-latency Miniconda Mod_jk Monitoring NetworkMiner Nikto NLP NLTK Nmap Nokia 770 OpenAI OpenBSD PCAP pdfminer Peak Performance PF recon Security SSM Tomcat Volatility VSCode Word2Vec xgboost

Archives

  • April 2026
  • November 2024
  • October 2024
  • June 2024
  • October 2023
  • September 2023
  • August 2023
  • May 2023
  • April 2023
  • February 2023
  • March 2020
  • June 2019
  • July 2018
  • May 2018
  • August 2017
  • June 2017
  • February 2017
  • November 2016
  • October 2016
  • September 2016
  • April 2016
  • March 2016
  • November 2015
  • August 2015
  • June 2015
  • February 2015
  • September 2014
  • August 2014
  • July 2014
  • January 2014
  • June 2013
  • January 2012
  • September 2009
  • August 2009
  • September 2008
  • September 2006
©2026 James Bower | WordPress Theme by SuperbThemes