Help:Конвертування

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
This page is a translated version of a page Help:Converting and the translation is 5% complete. Changes to the translation template, respectively the source language can be submitted through Help:Converting and have to be approved by a translation administrator.
Outdated translations are marked like this.

Конвертування документу з одного формату в інший для Вікісховища може бути корисним для створення більш доступних похідних творів.

  • Хоча PDF-документи приймаються на Вікісховищі, отримати доступ до них, все ж, порівняно складно.

Converting PDF to DJVU

  • Конвертування в SVG:
    • Використовуйте [$pdf2svg pdf2svg] (Linux: [$pdf2svg-l pdf2svg]) для конвертування в SVG, якщо весь PDF-файл слід використати як зображення, напр., якщо він є діаграмою, створеною якоюсь програмою.

Extracting text from PDF

  • Видобування тексту:
    • Якщо PDF-файл містить текст у формі, з якої легко видобувати, скористайтеся або елементом «Edit» / «Text extract...» у GSview, або «Save as text» в переглядачіAdobe Acrobat, в іншому разі:
    • Виконайте пораду, подану в розділі «Видобування зображень» вище, а потім — пораду щодо «Конвертування з різних форматів зображень у текст» нижче.

Converting DjVu

Converting DjVu to other formats is useful because someone might not have a DjVu viewer installed, and other formats can be readily viewed in browser.

Converting DjVu to PDF

Converting DjVu to images

Use DjVuLibre command line utilities ddjvu (DjVu decoder) or djvups (to convert to PostScript).

Extracting text from DjVu

WinDjView can do that or DjVuLibre command line tool djvutxt.

Converting images

Конвертування з форматів зображень у GIF, JPEG, PNG або TIFF

  • Скористайтесь умовно безкоштовними (вільними для персонального використання) програмами IrfanView або XnView, і jpegcrop для складніших трансформацій
  • Скористайтесь вільною програмою ImageMagick

Processing images obtained from scanner

Images obtained from scanner usually require some processing before making a PDF or DJVU out of them: cropping, turning, splitting, reducing the size, converting to TIFF etc. The open-source application ScanTailor-Universal is designed for this purpose. It can be downloaded from the project's releases page.

Creating PDF from images

  • img2pdf, an open-source command line program, is designed to convert images losslessly to PDF. It can also set metadata (such as the title and author) and how the resulting PDF file should be presented by a PDF viewing program.

The following command will take all files in the current folder and convert them into a single PDF named test.pdf with title and author metadata:

img2pdf --title "My First PDF" --author "Jack Example" --output test.pdf *

Note that this assumes the current directory does not contain non-image files or sub-folders. If all your source files are of a single type, such as JPEGs, you can specify *.jpg as the input instead. You can also specify multiple input files individually.

See img2pdf --help for everything img2pdf can do.

img2pdf is available from the Python Package Index and is also included in the repositories of many Linux distributions. A Windows executable is also available via the project's Appveyor.

The following command will use ImageMagick's mogrify tool to convert all JPEG files to individual PDF files and place them in a subfolder named "pdf":

mogrify -format pdf -path pdf/ *.jpg

On some Linux distributions, the default ImageMagick security policy will block the program from handling PDF files. See this StackOverflow question for how to change the security policy.

Creating PDF from bitonal images

Bitonal images (ie. images that only contain a single shade of black and white) are a very efficient way of storing scanned documents that only contain text or other simple elements that only need two colors to be clearly represented. A high-quality bitonal text page is commonly only tens of kilobytes in size.

There are two bitonal compression methods used in PDF files, namely the CCITT Group 4 Fax compression and the JBIG2 compression. The latter is more efficient but has some perceived patent issues associated with it, resulting in JBIG2 encoding functionality often being missing or disabled in PDF creation software. However, it is sometimes possible to enable such functionality by installing the encoder yourself.

There are a number of tools for converting images to use bitonal compression. ScanTailor-Universal is an open-source tool for processing scanned pages that can output bitonal images. ImageMagick and GraphicsMagick are also able to do this with the -threshold option.

The following ImageMagick command converts all .jpg files in a folder into bitonal TIF files using Group 4 compression and places them into a folder named "bitonal":

mogrify -format tif -compress Group4 -path bitonal/ -threshold 50% *.jpg

Play around with the value of -threshold to find one that produces good results with your content.

JBIG2 conversion

OCRmyPDF is an open-source command line program mainly designed to add an OCR text layer to scanned PDF files. One of its additional features is its ability to optimize PDF files, which includes the conversion of other bitonal image formats to JBIG2. This requires the installation of the jbig2enc encoder. Compilation and installation instructions for Linux users are available here, and a third-party Windows executable is available here. The MacOS version packaged in Homebrew already includes jbig2enc.

See here for how to install OCRmyPDF on Windows. Many Linux distributions come with an OCRmyPDF package included in the repositories, though this may be outdated. OCRmyPDF is also available on pip.

The following command uses OCRmyPDF to add an OCR text layer to a PDF and arranges the PDF in a way that allows a web browser to start displaying it before it has been fully downloaded:

ocrmypdf --output-type pdf --fast-web-view 0 test.pdf test-OCR.pdf

OCRmyPDF by default losslessly optimizes the PDF, so bitonal images are automatically converted to JBIG2 if jbig2enc is installed.

If you want to skip the OCR process because you don't need to OCR the PDF, use --tesseract-timeout 0 to skip OCR altogether.

See OCRmyPDF's documentation for further usage examples.

Creating DjVu from images

Use DjVuLibre command line tools c44 (for color images) and cjb2 (for bitonal images) to convert images to single-page DjVu files, then join them with djvm.

Example c44 command line:

c44 [options] pnm-or-jpeg-file [djvufile]
The important options are -slice, -dpi and -mask. -slice sets the number of "slices" in each "chuck" (which are some tricky DjVu terms). Giving three numbers means there will be three "chunks", and four numbers will result in four chunks. These numbers seriously affect quality and size - experiment and check the documentation.
c44 -slice -slice 74+13+10 -dpi 150 pnm-or-jpeg-file [djvufile]


From the cjb2 bitonal encoder's self-explaining help:

Usage: cjb2 [options] <input-pbm-or-tiff> <output-djvu>
Options are:
 -verbose        Display additional messages.
 -dpi <n>        Specify image resolution (default 300).
 -clean          Cleanup image by removing small flyspecks.
 -lossy          Lossy compression (implies -clean as well)
 -losslevel <n>  Loss factor (implies -lossy, default 100)
Encoding is lossless unless a lossy options is selected.

In many cases, -losslevel can be harmlessly set as low as 50.

For details, see DjVuLibre documentation.

Minidjvu allows to convert black & white single-page and multi-page TIFF, BMP and PBM to DjVu and reverse. It has a simple graphical shell. Its support for multi-page TIFF files is a notable advantage over DjVuLibre tools.

minidjvu 0.8 - encode/decode bitonal DjVu files
Usage:
single page encoding/decoding:
    minidjvu [options] <input file> <output file>
multiple pages encoding:
    minidjvu [options] <input file> ... <output file>
Formats supported:
    DjVu (single-page bitonal), PBM, Windows BMP, TIFF.
Options:
    -A, --Averaging:               compute "average" representatives
    -a <n>, --aggression <n>:      set aggression level (default 100)
    -c, --clean                    remove small black pieces
    -d <n> --dpi <n>:              set resolution in dots per inch
    -e, --erosion                  sacrifice quality to gain in size
    -i, --indirect:                generate an indirect multipage document
    -l, --lossy:                   use all lossy options (-s -c -m -e -A)
    -m, --match:                   match and substitute patterns
    -n, --no-prototypes:           do not search for prototypes
    -p <n>, --pages-per-dict <n>:  pages per dictionary (default 10)
    -r, --report:                  report multipage coding progress
    -s, --smooth:                  remove some badly looking pixels

Конвертування з форматів зображення у текст

gImageReader

  • gImageReader is an open-source application for extracting text from images and image-based PDF documents. It's able to automatically detect the layout of text and post-process the recognized text, including spell checking and removal of line breaks. It uses Tesseract for text recognition, and as such it supports any language that Tesseract does.

IrfanView

  • виберіть плагін «Start OCR» (OCR — це Оптичне розпізнавання символів) в меню опцій в IrfanView, щоб видобути інформацію у формі тексту. Станом на 20-02-2010 плагін KADMOS OCR для Irfanview обмежений до близько шести сторінок, залежно від вільної пам'яті Вашого комп'ютера (на 10 сторінок потрібно близько одного гігабайта пам'яті). Можливо, Вам треба буде виконувати конвертацію частинами. Вам треба буде виправити згенерований текст вручну, оскільки конвертація неідеальна.

Pdf X-Change Viewer

Tesseract engine

  • або скористайтесь вільною програмою з відкритим кодом Tesseract (працює на Linux, Mac OS X, та Windows):
  • завантажте пакунки «Tesseract» і «Tessdata» мовами, відповідними тим, що перелічені в зісканованому документі, і розпакуйте їх в одну папку; для файлу .exe на Windows немає потреби в жодному встановленні;
  • отримайте скан з якомога вищою роздільністю, і якщо необхідно, збільште зображення зі скану (використовуйте швидке масштабування, уникайте фільтрів передискретизації) доки cимволи не досягнуть понад 20 пікселів у висоту (експериментуйте, щоб отримати якнайкращий результат) і збережіть його як некомпресований файл TIFF (для цього скористайтесь ImageMagick або IrfanView); Вам потрібно буде чимало місця на диску;
  • спершу випробуйте невеликі фрагменти, оскільки розпізнавання може займати по декілька хвилин на сторінку;
  • програма Tesseract може аварійно завершити роботу, якщо введені фрагменти становлять понад 12 сторінок;
  • використовуйте команду «tesseract.exe input.tif output».

eScriptorium

  • Use the free Open Source software eScriptorium with Kraken. The server component can be installed on Linux, macOS or Windows (with WSL). The client side is a web application which works in any modern web browser. It allows segmentation of text regions and lines and recognition of printed text and handwriting. Both segmentation and recognition can be trained.

Google

In all cases, you may need to convert in sections. You will need to manually correct the generated text because the conversion is not perfect.

Converting video

Further help

You can ask for help at the Commons:Help desk.

Див. також