teleren/devto huggingface dataset:
Convert PDF to Excel or Word in Java
Tags: java, pdf, word, convert
Published: 2020-09-07 06:31:23

---
title: Convert PDF to Excel or Word in Java
published: true
description: This article introduces how to convert PDF to Excel or Word in Java
tags: java,pdf,word,convert
//cover_image: https://direct_url_to_image.jpg
---
Occasionally, you might be in a sitution where you need to extract table from a PDF document and save the table date either in a Word file or in an Excel worksheet, so that you can edit the date freely. In this article, I am going to show you how to convert a whole PDF document to Excel or Word by using [Spire.PDF for Java](https://www.e-iceblue.com/Introduce/pdf-for-java.html).

Below is a screenshot of the input file.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/pvaq35k1913o5udwtqxg.png)

##Install Spire.Pdf.jar

If you’re creating a Maven project, you can easily add the jar in your applciation using the following configurations. For non-Maven projects, download the jar file from [this link](https://www.e-iceblue.com/Download/pdf-for-java.html) and add it as a dependency in your applicaiton. 
```java
<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId> e-iceblue </groupId>
        <artifactId>spire.pdf</artifactId>
        <version>3.8.5</version>
    </dependency>
</dependencies>
```
##Convert PDF to Excel (XLS/XLSX)
```java
public class ConvertPdfToExcel {

    public static void main(String[] args) {

        //Create a PdfDocument instance
        PdfDocument pdf = new PdfDocument();
        
        //Load a PDF file
        pdf.loadFromFile("C:\\Users\\Administrator\\Desktop\\table.pdf");

        //Save as Excel file
        pdf.saveToFile("ToExcel.xlsx", FileForma.XLSX);
    }
}
```
Output
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ipq0kp0kuv1w0u4xhjxi.png)

##Convert PDF to Word (DOC/DOCX)
```java
public class ConvertPdfToWord {

    public static void main(String[] args) {

        //Create a PdfDocument instance
        PdfDocument pdf = new PdfDocument();

        //Load a PDF file
        pdf.loadFromFile("C:\\Users\\Administrator\\Desktop\\table.pdf");

        //Save as Word file
        pdf.saveToFile("ToWord.docx", FileFormat.DOCX);
    }
}
```
Output
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/qp9a93atk3r5rsi8lbuy.png)
VSCode on Google Colab
Tags: machinelearning, datascience, googlecolab, vscode
Published: 2020-09-07 06:27:56

I recently discovered a way to setup VSCode on Google Colab and use it as an editor to write code and run experiments on the Colab VM.  

With this setup, you can still prototype in the Colab Notebook while also using VSCode for all the advantages of an full-fledged code editor. Here is how you can replicate my setup.  

## Steps  
I have described the steps in details below. After going through all the steps, please use this [colab notebook](https://colab.research.google.com/drive/1yvUy5Gn9lPjmCQH6RjD_LvUO2NE0Z7RM?usp=sharing) to try it out directly. 

1. First, we will install the [code-server](https://github.com/cdr/code-server) package to run VSCode editor as a web app. Copy and run the following command on colab to install `code-server`.  

    ```
    !curl -fsSL https://code-server.dev/install.sh | sh
    ```

2. After the installation is complete, we will expose a random port `9000` to an external URL we can access using the `pyngrok` package. To install `pyngrok`, run  

    ```shell
    !pip install -qqq pyngrok
    ```

3. Then, run the following following command to get a public ngrok URL. This will be the URL we will use to access VSCode. 

    ```python
    from pyngrok import ngrok
    url = ngrok.connect(port=9000)
    print(url)
    ```

4. Now, we will start the VSCode server in the background at port 9000 without any authentication using the following command.

    ```
    !nohup code-server --port 9000 --auth none &
    ```

5. Now, you can access the VSCode interface at the URL you got from step 3. The interface and functionality is same as the desktop version of VSCode.  

![](https://amitness.com/images/colab-vscode.png)  

## Tips
- All the keyword shortcuts of regular VSCode works with this. For example, you can use `Ctrl + Shift + P` to open a popup for various actions.

![](https://amitness.com/images/vscode-ctrl-shift-p.png)  

- To open a terminal, you can use the shortcut ``Ctrl + Shift + ` ``.

![](https://amitness.com/images/vscode-terminal.png)  

- To get python code completions, you can install the Python(`ms-python`) extension from the extensions page on the left sidebar.

![](https://amitness.com/images/vscode-code-completions.png)  

- The Colab interface is still usable as a notebook and regular functions to upload and download files and mount with Google Drive. Thus, you get the benefits of both a notebook and a code editor.   

## References
- [Code-Server FAQs](https://github.com/cdr/code-server/blob/v3.5.0/doc/FAQ.md)
- [pyngrok - a Python wrapper for ngrok](https://pyngrok.readthedocs.io/en/latest/)

## Connect
If you enjoyed the blog post, feel free to connect with me on [Twitter](https://twitter.com/amitness) where I share new blog posts every week.
How to capture website screenshots using Node.js and Puppeteer
Published: 2020-09-07 06:09:36

Puppeteer is a Node.js library that provides an API for controlling Chrome and Chromium browsers. In this article, we’ll be using it to capture a screenshot of a website, but it can also be used to automate form submissions, perform UI testing, and help diagnose performance issues.

To get started with Puppeteer you’ll first need to have Node.js (v10.18.1+) installed.

With Node.js installed run the following terminal commands to create a project folder and install Puppeteer:

```
mkdir screenshot
cd screenshot
npm install puppeteer
```

This can take a little while to install as Puppeteer downloads Chromium which is around 120mb in size. Once installed we’ll setup the script to capture the screenshot in a new file called `screenshot.js` using Wikipedia as an example:

```
const puppeteer = require("puppeteer");
const capture = async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto("https://www.wikipedia.org/");
  await page.screenshot({ path: "./screenshot.png" });
  await browser.close();
};
capture();
```

As we’re using the `await` operator to wait for a Promise the code must be run inside an `async` function. This allows asynchronous, promise-based behavior to be written in a cleaner style, avoiding having to explicitly configure promise chains.

It’s now time to test the script out by running the following command:

```
node screenshot.js
```
f successful this will save an image named `screenshot.png` in the same folder as the script is located. By default, the screenshot will be 800×600 pixels but you can set a specific viewport size by adding the following with the required dimensions:

```
await page.setViewport({ width: 1024, height: 768 });
```

Alternatively entire pages can be captured by modifying page.screenshot as follows:

```
await page.screenshot({ path: 'screenshot.png', fullPage: true };
```
Up until now, the screenshot is being saved as a .png but it’s also possible to save as .pdf by replacing the `page.screenshot` line with the following:

```
await page.pdf({ path: 'screenshot.pdf', format: 'A4' });
```
Intro to React Router
Tags: react, webdev, tutorial
Published: 2020-09-07 05:47:37

React has a routing library (React Router) which allows us to link to specific URLs, and then show or hide components depending on which URL is displayed.  Here is a quick guide to dip your toes into using this handy tool.

##Install React Router

To install the React Router, run the following in the terminal: 

`npm install react-router-dom`


##Use React Router

To start implementing routes in our app, we need to import `BrowserRouter` and `Route` from `react-router-dom`.  Add the following line of code at the top of file where you will be using React Router: 

`import { BrowserRouter as Router, Route } from 'react-router-dom';`

*Note: It is common for `BrowserRouter` to be renamed as `Router`.  The above line of code is how you would create an alias.  Now, any time we see `Router`, it is referring to `BrowserRouter`.*

`Router` is the base component for our application's routing, and we declare in here how React Router is used.  

Nested within this component is the `Route` component, so it would look something like this:

```
ReactDOM.render((
  <Router>
    <Route path='/' component={Home} />
  </Router>),
  document.getElementById('root')
);
```

You will notice that the `Route` component has two props (properties): `path` and `component`.  What this line says is that when the URL matches the path ('/'), our app will render the specified component for `Home`. 


##Multiple Routes

More likely than not, we'll have multiple routes in our app.  It is important to note that the `Router` component can only have one child element, so in order to work around this, all of the `Route` components can be placed within a `<div>` or `<>` tag, ending up looking like this: 

```
ReactDOM.render((
  <Router>
    <div>
      <Route path='/' component={Home} />
      <Route exact path='/about' component={About} />
    </div>
  </Router>,
  document.getElementById('root')
);
```

As you can see, the Route for the `About` component uses `exact path` as opposed to just `path`.  This is pretty self-explanatory, but we use this to ensure that the component renders only when the path matches the the whole path, and not just part of it.  We may have an issue with our `Home` component rendering all the time, so in that case, we should make that an `exact path` as well. 

Now, if you change your URL path to '/', then you should see the `Home` component, and when the path is changed to match '/about', the `About` component should be rendering!

This is really just the very tip of the iceberg.  To delve deeper into React Router, [check out this awesome site.](https://reactrouter.com/web/example/basic)
HashWithIndifferentAccess in Rails
Tags: ruby, rails, class, hash
Published: 2020-09-07 05:46:03

When I found out how the `params` could be accessed using both `symbol` and `string` as keys, I dived deep to figure out about `ActiveSupport::HashWithIndifferentAccess` class in Rails.

In this blog for beginners, we will go through it’s implemention.

https://www.sandipmane.dev/hash-with-indifferent-access-in-rails
Need a way to build workflows
Tags: help
Published: 2020-09-07 05:15:45

I am looking for a workflow builder for my vue.js app, used to build chatbot flows and I honestly have no idea how to do it or what it is called.

I found this but it looks like it is half done
https://github.com/alyssaxuu/flowy

I found something called Node Red, but I am not even sure how to use this in my project - https://nodered.org/

Can someone help?

Here's what I am trying to achieve.
I am looking to build something like this https://alyssax.com/x/flowy/
Implement LRU Caching into your Repository | Androidbites 
Tags: kotlin, java, android, androidbites
Published: 2020-09-07 04:48:33

Hi Devs, Repository pattern is available in almost every codebase, people often design it pretty well but often miss out on the caching behavior from It and rely on retrofit caching or Live data for caching data or put on some hack in the android lifecycle to only get data once to save APIs calls.

follow up the following article and learn how to implement LRU cache in your repository in 5 easy steps.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/srrdbv6racueartnmfn4.png)

## 👉 [AndroidBites|cache-repository](https://chetangupta.net/cache-repository)

Hope to see you on the other side...

Until next time. Happy Hacking! 👩‍💻

Stalk Me 👀 :
[LinkedIn](https://bit.ly/ch8n-linkdIn) | [Medium](https://bit.ly/ch8n-medium-blog) | [Twitter](https://bit.ly/ch8n-twitter) | [StackOverflow](https://bit.ly/ch8n-stackOflow) | [CodeWars](https://bit.ly/ch8n-codewar) |[WorkX](https://bit.ly/ch8n-home) |[Github](https://bit.ly/ch8n-git) |[Instagram](https://bit.ly/ch8n-insta) |[Youtube](https://bit.ly/ch8n-youtube)
How to make application my javascript scriptable and excuteable with ElectronJS
Tags: electronjs, scriptable, excuteable
Published: 2020-09-07 04:46:30

Hi.
In C#, I can use ClearScript Library "https://github.com/Microsoft/ClearScript".

I am beginner about ElectronJS.
I want make application with ElectronJS can run my javascript scriptable.
You can suggest for me library?
Thank for read and suggest.
Common JavaScript Questions I Used to ask in Interview. ✍
Published: 2020-09-07 04:41:20

🎤 Common JavaScript Questions I Used to ask in Interview. 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/rl656qf9znm6s1hgqqhb.JPG)

Let's go 👇

Share your feedback & add what you think is missing. 

These questions have left even experienced developers stumped sometimes.

>Top questions about JavaScript that have left many developers stumped – even experienced JavaScript coders. 

there's always more to learn and discover in #javascript

1. What is prototypical inheritance and how useful is it?

2. How can JavaScript be used to improve accessibility on the web?

3. What is event bubbling and how is it different to event capturing?

4. How does event delegation improve code on sites with lots of interactive elements?

5. What are closures and how can they be useful in organizing code?

6. What does 'use strict' mean at the top of a block of code?

7. What does the term 'hoisting' mean in reference to JavaScript?

8. What is the difference between an arrow function and a regular function?

9. Where should you use the 'let' and 'const' keywords instead of 'var'?

10. What is functional programming and how is it different?

11. How can you use JS to improve the performance of the website?

12. How can you future-proof your JavaScript code?

I would say just one thing to overcome & give the answer to any questions in your future interviews.

Practice makes you perfect. 

Hope you like this 💙👍
Check if file modified in n minutes
Tags: bash, file
Published: 2020-09-07 04:22:31

Sometime we want to check if file modified in n minutes and do something with each file, we can easily use some commands.

Use test to check if condition, find with -mmin to check if older than n minutes, and for-do-done loop to enumerate each file in *.txt

Ok, let's put all together,

```
# check if file modified in 40 mins
for f in *.txt
do
  if ! test `find $f -mmin +40`
  then
    echo $f
  fi
done
```

for f in *.txt is to enumerate each file with txt extension file, and if ! is for check the false condition with find $f -mmin +40, i.e. $f not older than 40 minutes, also means $f is as new as modified in 40 minutes.

There is a example test code to check:

https://repl.it/@timhuangt/checkIfFileModified

Just create 3 files (with touch command) that modified in now, 30 minutes ago, 60 minutes ago, and with the modified date-time filename with each file. After the for-do-done loop, we can echo the file(s) name modified in 40 minutes.

Reference:
1. https://stackoverflow.com/questions/552724/how-do-i-check-in-bash-whether-a-file-was-created-more-than-x-time-ago
2. https://unix.stackexchange.com/questions/118577/changing-a-files-date-created-and-last-modified-attributes-to-another-file/250407
3. https://stackoverflow.com/questions/16142973/add-some-specific-time-while-using-the-linux-command-date
using Timezone package in flutter
Tags: flutter, timezones, dart, iana
Published: 2020-09-07 04:21:37

[Timezone](https://pub.dev/packages/timezone) package makes life a bit easier to deal with those pain in the neck issues related to timezone. However, I had a bunch of issues using that package, so documenting them here for someone else to save some time. 
+ Take a look at [Udit's](https://medium.com/flutter-community/working-with-timezones-in-flutter-1c304089dcf9) post. That helped me a lot.
+ Take a look at resources at [IANA].(https://www.iana.org/time-zones)
+ Download the timezone database.
```bash
git clone https://github.com/srawlins/timezone.git
cd timezone
flutter pub get
flutter pub run tool/get -s 2020a
cd lib/data
```
+ Add it to your codebase.
```bash
cp lib/data/2020a* <project_dir>/assets/timezone/
cd <project_dir>
git add->commit->push
```
Also, add it to your pubspec file under assets with the path you used above. 

+ Use it in your code. 
``` flutter
  Future<void> initTimezones() async {
    // get device timezone
    String dtz = await FlutterNativeTimezone.getLocalTimezone();

    // Load timezone data
    var byteData = await rootBundle.load('assets/timezone/2020a.tzf');
    tz.initializeDatabase(byteData.buffer.asUint8List());
    tz.initializeTimeZones();
    // set the local location.
    tz.setLocalLocation(tz.getLocation(dtz));

    // Iterate and use through the list of timezones.
    _locations = tz.timeZoneDatabase.locations;
    _locations.values.forEach((element) {
        print(element.name);
        print(element.currentTimeZone.abbr);
        print(element.currentTimeZone.offset);
        print(element.currentTimeZone.isDst);
        print(element.zones.length);
      });
  }
```
+ For timezone conversion, readme on the package provides great examples, so I will skip repetition.

Hope this helps someone.
Trying secrets (Python) to Generate Password
Tags: passwords, python, python3, cryptography
Published: 2020-12-31 14:26:14

---
title: Trying secrets (Python) to Generate Password
published: true
date: 2020-09-07 04:13:36 UTC
tags: passwords,python,python3,cryptography
canonical_url: https://medium.com/@bervianto.leo/trying-secrets-choice-python-to-generate-password-48f750ed36a5
---

#### How strong is it?

In my spare time, I want to explore more about Cyber Security. This time I will try how good _secrets_ module. I use _secrets.choice_ to generate my password. I use the recipe that is provided by Python documentation, [here](https://docs.python.org/3/library/secrets.html#recipes-and-best-practices).

![](https://cdn-images-1.medium.com/max/1024/0*1ZPEXg8zEbTWseqT)<figcaption>Photo by <a href="https://unsplash.com/@cdr6934?utm_source=medium&amp;utm_medium=referral">Chris Ried</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption>

I use small code to generate the list of my passwords and also small code to check the duplication. Here my python script to generate the code:

{% gist https://gist.github.com/berviantoleo/f8a356030ca268cc3f8231a94c85c070 %}

Here the code to check the password list:

{% gist https://gist.github.com/berviantoleo/b626a1f49f0fcaed579341d80d283d44 %}

I will try generate some numbers of password to check how strong the generated password. I think this naive method good for the first try how strong the module. If you not find any duplication in this method, doesn’t mean it is strong. You will need another method to check the strength. I will use 100, 1000, 100000, 1000000 and 1000000000 numbers of password. Let’s start!

![](https://cdn-images-1.medium.com/max/480/1*rGRM-hKatJu74d-Nh3RQVQ.png)<figcaption>100 passwords</figcaption>

You need to check the output, the output is **False**. It mean not have any duplication. I want to bring the execution time too, because it will bring long time for more numbers. It is also prove that I not get the wrong list when run _check-list.py_. Let’s check this out.

![](https://cdn-images-1.medium.com/max/501/1*kKpvenGWsFVnsoQKwARdzA.png)<figcaption>1000 passwords</figcaption>

Seems still good until 1000 password. Let’s check the another.

![](https://cdn-images-1.medium.com/max/474/1*DsP9o5q3QAMz7zbBVhfSlQ.png)<figcaption>100000 passwords</figcaption>

![](https://cdn-images-1.medium.com/max/471/1*t4GHIPZNr_xUxUjXvwGKcg.png)<figcaption>1000000 passwords</figcaption>

Great! 100000 and 10000000, the number that “enough” number to test, still not bring any duplication. Let’s check the bigger number!

The 1000000000, I can’t produce now. I need to improve my code to parallel or multi-thread things. The current implementation will very long time to achieve. :( I will give you an update if I can run that.

### Summary

I want to give “little” summary. We can assume that the _secret_ module strong enough. We still need more advance method to check the method. For many data generation will update soon. Thank you for read this.
WinHotKey  is seriously good!
Published: 2020-09-07 04:02:22

I've been trying to look for a real alternative to AutoKey on Linux that supports typing some predefined texts by hotkeys.

AutoHotkey on Windows is a bit overkill ._.

Then I've found this one: WinHotKey turns out do it job really good. It does support special combinations like Ctrl + Alt + * 

https://helpdeskgeek.com/how-to/create-custom-keyboard-shortcuts-for-anything-in-windows-10/
ER diagram of the risk exposure of a Covid-19 patient
Published: 2020-09-07 03:59:05

Since we live an unpredictable times there are a lot of things that you can do to protect yourself. By following this simple ER diagram you could eliminate a lot of the risk that you could be taking in your daily life. 
https://www.youtube.com/watch?v=QXIHRHYL1aY&feature=youtu.be&ab_channel=BeastMode
Lab 2: Covid-19 ER Diagram
Published: 2020-09-07 03:54:19

Hey everyone! Today, I was tasked with creating an entity relationship diagram for the COVID-19 outbreak. I included 6 entities in my diagram and included the relationships between entities and the attributes related to the entities. Here is the diagram that I made. 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/41u9xdbam50z2px8yu5i.jpg)

The entities that I chose were patient, geographic location, occupation, hospitals, behavior, and risk. The entities are represented by the rectangular boxes. The relationships between the entities that I chose are in the diamond shaped boxes. The attributes that each entity has are in the ovals. 

I decided to put the patient in the middle because the patient is the only entity that relates to all of the other entities that I included. The patient has attributes of a patient number, name, age, sex/gender, and race. The patient ID is the main attribute that is going to be used to differentiate between patients because it is a primary key. Primary keys are attributes that are unique to an entity that only one can exist. All the other attributes that the patient has are foreign keys, which means that multiple entities can share these keys in common. 

The other entities that I included in the diagram don't have any primary keys because they are more individualized for each person that is assessing their own unique situation. Each person that looks at the diagram for themselves could have different behaviors, occupations, hospitals, geographic locations, and risks associated with COVID-19 that they must fill out themselves. These traits that people have can overlap with other patients, making the attributes foreign keys, but help patients assess their risk with COVID-19. 

Each of the entities in the the diagram can also be placed in tuples. Calling them tuples is just a fancier way of saying ordered lists that relate all the attributes and entities together. All of the entities included in my diagram can be placed into tuples. I gave some examples of tuples below. 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/4pk54uped1xce1pxvylp.PNG)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/a6qu5ifma351a27owecg.PNG)

Lastly, I included something called cardinality in my diagram. If you look at my diagram you will see 1s and Ns in the arrows that join entities together. Cardinality is the number of elements in a set as a property of that grouping. For example, 1 occupation can be located in any number of geographical location, therefore there is a 1 close to occupation before the relationship and a N after the relationship closer to the geographical location box. I included the cardinality between all of the entities in my diagram as you can see above. 

{% youtube vNUyqyu4e9k %}