New to Krita. Decided to try out working on a concept guidebook for a project in it. Went pretty well.
Apparently “yes you can export to PDF” was only true until a couple of years ago.
Now I’ve got fifty pages I can’t export to PDF, just images, and the images are HUUUGE and the text is obviously not select-able if I take the images and put them in a PDF file.
I gotta submit this thing in the next few days… as a PDF under a hundred Mb. Can anyone think of a way for me to get my pages out of the .kra format and into something convertable into PDF?
Are the pages in separate kra files or are they group layers?
If they are separate kra files you can batch export them into png/jpg files which can then be processed further through imagemagick.
If they are on separate groups inside on Krita document, you can export group layers as separate png/jpg files through Layer menu --> Import/Export --> Save group layers. These exported png/jpg files can then be made into pdf via imagemagick or libreoffice Draw if you need a GUI.
You can use the Krita command line option to batch export the kra files or use external tools like zip to extract the image. You can read more about the command line options here - Linux Command Line — Krita Manual 4.4.0 documentation
Here is a quick script to batch process with external utilities
#!/bin/bash
export cwd="$PWD"
mkdir -p /tmp/kra-output
#start the loop for each file in cwd
for f in *.kra
do
echo "processing file - $f"
#unzip the merged png image inside kra file
unzip -j "$f" "mergedimage.png" -d "/tmp/kra-output/" > /dev/null 2>&1
chmod 664 /tmp/kra-output/mergedimage.png
convert /tmp/kra-output/mergedimage.png -colorspace sRGB -background white -alpha remove "$cwd"/output/hires/"${f%.*}"-hires.png
rm /tmp/kra-output/mergedimage.png
rm -rf /tmp/kra-output
done
echo "finished exporting"
Please be cautious and try with test files first. You should not run any script found on Internet.
After you have extracted the images with the above script. You can again run imagemgick or use scribus or other program to combine them in a pdf.
Wow…
I’m not sure to understand.
Use of Krita to write a 50pages guidebook with text??
What a strange idea… Raster softwares are not the best for this, you should use a software like Scribus for example, especially if you have texts and images.
Otherwise LibreOffice could also be a good choice too.
Now, having a kra file there’s not very much solutions:
Start to work with another software
Copy/Paste manually text from Krita to choosen software, page per page…
Another solution could be to write a plugin for this, but it will take some time to write something like this.
Yes any changes in text would need you to rerun the operation. It is better to create the background in Krita and embed these kra into scribus add your text inside it and save as pdf directly.
Yes, they are separate files labelled sequentially.
Thanks for that snippet. It was interesting to learn that krita files have a merged png inside of them. I am curious about their contents now. Cheers.
I will try a bit more to see if I can extract that text. Not being able to search it or copy-paste from the pdf will be problematic for the people reading it later.
If you unzip file, you’ll find a directory (name can vary) and inside this directory, a layers sub-directory
In the layers sub-directory, you’ll find sub-directories /layerXX.shapelayer (one per vector layer)
And each of this sub-directories contains a file content.svg
SVG files can be imported in LibreOffice or Scribus.
Here is some detail about the Kra file format. The document is still in Merge request so it might change. But it might give you some insight. I don’t know how helpful it will be.
The <Layers> markup contains all child layer, listed in same order than one you can see in layer stack.
It’s a binary file…
Here some notes I made on my side (not official, it’s what I understood of paintlayer file format)
Tiles file is a binary file
-- Header --
'VERSION 2\n'
'TILEWIDTH <w>\n' # with <w> value for tile width (variable width)
'TILEHEIGHT <h>\n' # with <h> value for tile height (variable width)
'PIXELSIZE <v>\n' # with <s> value for pixel size (in bytes; variable width)
'DATA <t>\n' # with <t> value for number of tiles (can be 0 for empty layer; variable width)
# note: only tiles with data are defined in layer?
. Example:
b'VERSION 2\n'
b'TILEWIDTH 64\n'
b'TILEHEIGHT 64\n'
b'PIXELSIZE 4\n'
b'DATA 31\n'
=> 31 tiles of 64x64 pixels, 4bytes per pixels
-- for each tiles --
- tile header
'<x>,<y>,LZF,<length>\n' # with <x> value for tile X position (can be negative)
# with <y> value for tile Y position (can be negative)
# with <length> value for (compressed) data following header
. Example:
b'64,64,LZF,647\n'
=> tile position 64,64 is 647bytes
- tile data
Data is an array of bytes, for which size is defined in header (<length> value)
First byte can take the following value:
0x00 Uncompressed data; in this case the next <length>-1 bytes are raw pixels values
0x01 Compresssed data; in this case the next <length>-1 bytes are LZF compressed pixels values
Possible to decode and rebuild data from this, but faster to work with Scripting API than trying to read and rebuild content from this I think…
Great point. I wonder how to access the raster layers. Maybe that is not even necessary. Perhaps every vector layer can be set to visible=0, then export the png, then take the png and the stack of svgs and then bundle them all together.
Difficult to provide you all information about how to open document, work on layers, extract/merge what you need because it would be really time consuming to explain all steps