Inserting chess diagrams and games to word

Discussion of anything and everything relating to chess playing software and machines.

Moderator: Ras

Uri Blass
Posts: 10794
Joined: Thu Mar 09, 2006 12:37 am
Location: Tel-Aviv Israel

Inserting chess diagrams and games to word

Post by Uri Blass »

I would like to have a tool that allow me to insert a chess diagram to word document based on fen and also insert a game to a word document based on pgn and by a game I mean that I can view the game inside the document.

I wonder if there is a free tool to do it and if yes what is the most convenient tool.
jefk
Posts: 953
Joined: Sun Jul 25, 2010 10:07 pm
Location: the Netherlands
Full name: Jef Kaan

Re: Inserting chess diagrams and games to word

Post by jefk »

well you can do this with the online program Onlyoffice
https://api.onlyoffice.com/plugin/example/chess
and then if needed convert to Word
https://api.onlyoffice.com/editors/conversion
chesskobra
Posts: 349
Joined: Thu Jul 21, 2022 12:30 am
Full name: Chesskobra

Re: Inserting chess diagrams and games to word

Post by chesskobra »

I think the first part - inserting diagrams - is easy with latex. You can easily convert FEN to a diagram in latex. After that you will have to cut the diagrams and save as png or jpeg, and paste them in word. There may be simpler ways. But instead of all this, I would just go for LaTeX itself.

I don' t know about the second part - embedding a live board. I don't know anything about word, but if it is possible to embed html, then it may be possible.
Ferdy
Posts: 4846
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Inserting chess diagrams and games to word

Post by Ferdy »

Uri Blass wrote: Mon Nov 14, 2022 8:46 pm I would like to have a tool that allow me to insert a chess diagram to word document based on fen and also insert a game to a word document based on pgn and by a game I mean that I can view the game inside the document.

I wonder if there is a free tool to do it and if yes what is the most convenient tool.
Fortunately there is a python-docx package that can manipulate document. Together with python-chess and other python packages we can build a program to embed diagrams in the doc.

I make a cmd tool to generate a docx embedding the the given epd.

Code: Select all

python gen_doc.py --epd-file sts.epd --show-epd --show-bm --show-id --max-pos 2 --output-file sample.docx --header "Chess Positions" --randomize-epd --board-orientation side
Sample output:

Image

Image

If you need this, I will upload it in github.

Regarding the game, we can print all move/position diagram in the game, this way you are able to see all the positions in the game.
chesskobra
Posts: 349
Joined: Thu Jul 21, 2022 12:30 am
Full name: Chesskobra

Re: Inserting chess diagrams and games to word

Post by chesskobra »

Hi Ferdy, I am not the OP but would greatly appreciate if you uploaded it on github. I do look at some of your chess repositories to learn from your code. Thank you.
Ferdy
Posts: 4846
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Inserting chess diagrams and games to word

Post by Ferdy »

chesskobra wrote: Wed Nov 16, 2022 11:06 am Hi Ferdy, I am not the OP but would greatly appreciate if you uploaded it on github. I do look at some of your chess repositories to learn from your code. Thank you.
It is in github repo.
User avatar
hgm
Posts: 28353
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Inserting chess diagrams and games to word

Post by hgm »

I don't understand the problem. But that is perhaps because I haven't user Word for nearly 30 years. But you can embed arbitrary images with the text, right? So pasting the FEN in any GUI you happen to like, taking a screenshot, and importing it in the document would do it. That seems so trivial that it can hardly be what the OP was asking.

Does Word support 'animated graphics'? If so, what programming language is used to animate those? If it understands HTML and JavaScript you could just paste PGNviewer or an Interactive Diagram in it.
User avatar
phhnguyen
Posts: 1524
Joined: Wed Apr 21, 2010 4:58 am
Location: Australia
Full name: Nguyen Hong Pham

Re: Inserting chess diagrams and games to word

Post by phhnguyen »

hgm wrote: Thu Nov 17, 2022 11:19 pm I don't understand the problem. But that is perhaps because I haven't user Word for nearly 30 years. But you can embed arbitrary images with the text, right? So pasting the FEN in any GUI you happen to like, taking a screenshot, and importing it in the document would do it. That seems so trivial that it can hardly be what the OP was asking.

Does Word support 'animated graphics'? If so, what programming language is used to animate those? If it understands HTML and JavaScript you could just paste PGNviewer or an Interactive Diagram in it.
I don't know the tech the above programs/links are using. But for me, the right tech is to use OLE objects.

MS Word supports those objects. You may understand an OLE object as an embedded program in a Word document, somewhat it is comparable to a Java applet. To use, users just need a copy and paste the object from that program to the doc. The program will control how to display inside the doc, in this case, the chess game. You may show a chessboard from a given move as well as all moves too. If you want, you can show the result, names of players, the event, etc... in a specific format/colors chosen by users/developers. If the user doubles click on the board, the program will be called and run inside the doc and allow the user to interact, say, select other moves for displaying the board, edit players' names, modify the whole game or even play a game.

It is much more convenient, compared with copying/pasting a chessboard image and the game text into the document. For using the board image, if you want to display the board at another given move, you need to copy/paste the image again. But using OLE is also more complicated, and harder for developing.

I used to develop a chess GUI that supported OLE. However, similar to you, I have moved to another world than Windows for a long time and rarely use both MS Word and Windows.
https://banksiagui.com
The most features chess GUI, based on opensource Banksia - the chess tournament manager
Uri Blass
Posts: 10794
Joined: Thu Mar 09, 2006 12:37 am
Location: Tel-Aviv Israel

Re: Inserting chess diagrams and games to word

Post by Uri Blass »

In the past I copied diagrams to a word document by some site but I did not do it for some years so I do not remember the exact site.

I found the following way to copy diagrams to chess word document without moves

1)Choose a fen for your diagram
for example 3r4/1p5p/p3qp1k/6p1/P3p1P1/Q3N3/5PK1/8 w - - 1 1

2)copy http://www.fen-to-image.com/image/ as the start of you link

3)add the fen so you get
http://www.fen-to-image.com/image/3r4/1 ... 3N3/5PK1/8 w - - 1 1

This link already show me a diagram

4)click on the diagram with the right part of the mouse and choose copy picture with the left part of the mouse(I see the words "copy picture" in hebrew in my computer so I guess that other people see these words in english or a different language that their computer is designed to show)
5)go to a word document and choose ctrl+V that is paste

I get the diagram inside the document in this way with nothing else.

The question is if I can get a game inside the document in some way(I would like to be able to see a game from a specific position when I read a document in the same way that I can see it in this forum inside a document that I save in my computer) and of course I prefer a simpler way.
best is simply some software that I insert to it pgn or fen and the software show me directly a picture that I can use copy and paste for it.
Uri Blass
Posts: 10794
Joined: Thu Mar 09, 2006 12:37 am
Location: Tel-Aviv Israel

Re: Inserting chess diagrams and games to word

Post by Uri Blass »

Uri Blass wrote: Fri Nov 18, 2022 4:37 am In the past I copied diagrams to a word document by some site but I did not do it for some years so I do not remember the exact site.

I found the following way to copy diagrams to chess word document without moves

1)Choose a fen for your diagram
for example 3r4/1p5p/p3qp1k/6p1/P3p1P1/Q3N3/5PK1/8 w - - 1 1

2)copy http://www.fen-to-image.com/image/ as the start of you link

3)add the fen so you get
http://www.fen-to-image.com/image/3r4/1 ... 3N3/5PK1/8 w - - 1 1

This link already show me a diagram

4)click on the diagram with the right part of the mouse and choose copy picture with the left part of the mouse(I see the words "copy picture" in hebrew in my computer so I guess that other people see these words in english or a different language that their computer is designed to show)
5)go to a word document and choose ctrl+V that is paste

I get the diagram inside the document in this way with nothing else.

The question is if I can get a game inside the document in some way(I would like to be able to see a game from a specific position when I read a document in the same way that I can see it in this forum inside a document that I save in my computer) and of course I prefer a simpler way.
best is simply some software that I insert to it pgn or fen and the software show me directly a picture that I can use copy and paste for it.
For step 4 maybe the words that you see are copy image and not copy picture(I am not sure about the exact words that other see and I simply translated the words that I see in hebrew to english).