Prepared a fifty page document in Krita, can't export to PDF

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?

Thanks.

Hello and welcome to the forum :slight_smile:

GIMP claims to export to pdf with a ‘layers as pages’ option.

You can use .png out from krita and import into GIMP.

Thank you for that idea.

That leaves the text I’ve written (and it’s a lot of it) as an image file and not text, though. i.e, once in PDF, it can’t be highlighted.

For complex ‘mixed media’ documents, Scribus (it’s free) is often recommended to be used from the start but would take time to learn.

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.

Hi

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:

  1. Start to work with another software
  2. 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.

Grum999

1 Like

Problem with this solution will be text, that is not text anymore but bitmap…

Grum999

2 Likes

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.

You can extract text as SVG files.

A kra file is a zip file.

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.

Grum999

Thanks. I see that now. Very neat!

There’s about 500+ layers with text in them spread about across fifty documents so doing that by hand will take a while.

Extract can be made with a script.
Import might done manually…

Grum999

I see that maindoc.xml appears to order the layers, i.e,

 <layers>
    <layer locked="0" filename="layer2" intimeline="1" nodetype="grouplayer" name="Text Explanations" visible="1" channelflags="" passthrough="0" compositeop="normal" collapsed="0" opacity="255" uuid="{7408fe05-953f-4488-99ec-66f17b2051ca}" colorlabel="0" x="0" y="0">

What determines the order these layers draw in? Is it sequential?
A shape layer is pure SVG which is straight-forward.

What is the format of a paintlayer?

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.

Do tell us how you solved this problem.

1 Like

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…

Grum999

Ooh thanks
Currently I started to understand file format, doing reverse engineering… this will facilitate my work :slight_smile:

Grum999

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.

1 Like

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 :sweat_smile:

But for scripting, you can go here, you’ll find a really documentation to start to learn it:
https://scripting.krita.org/lessons/introduction

And after, if you have specific questions, you can ask :wink:

Grum999

1 Like

if the pages are not in animation, I will say to “flatten picture” on all pages, then save it instead of .kra as .jpg, then make it a PDF file.

Wolthera wrote a python script to extract all of the SVG files for me.

2 Likes