program tip

PDF를 깨끗한 SVG로 변환 하시겠습니까?

radiobox 2020. 8. 9. 10:19
반응형

PDF를 깨끗한 SVG로 변환 하시겠습니까? [닫은]


PDF를 SVG로 변환하려고합니다. 그러나 내가 사용하는 것은 현재 모든 텍스트의 모든 문자에 대한 경로를 매핑합니다. 즉, 소스 파일의 텍스트를 변경하면보기 흉해 보입니다.

가장 깨끗한 PDF to SVG 변환기가 무엇인지 궁금합니다. 경로가없는 것은 단순히 필요하지 않은 텍스트 영역입니다. 아시다시피 PDF와 SVG는 상당히 유사하므로 좋은 변환기가 있다고 가정합니다.


Inkscape는 Wikipedia의 많은 사람들이 PDF를 SVG로 변환하는 데 사용합니다.

http://inkscape.org/

그렇게하는 방법에 대한 편리한 가이드도 있습니다!

http://en.wikipedia.org/wiki/Wikipedia:Graphic_Lab/Resources/PDF_conversion_to_SVG#Conversion_with_Inkscape


GUI를 열지 않고 명령 줄에서만 Inkscape를 사용할 수 있습니다. 이 시도:

inkscape \
  --without-gui \
  --file=input.pdf \
  --export-plain-svg=output.svg 

모든 명령 줄 옵션의 전체 목록을 보려면를 실행하십시오 inkscape --help.


현재 그래픽 출력을 잘 지원 하는 PDFBox사용하고 있습니다. 벡터 스트로크 추출 및 글꼴 관리에 대한 좋은 지원이 있습니다. 시험해볼 수있는 몇 가지 좋은 도구가 있습니다 (예 : PDFReader가 Java Graphics2D로 표시됨). Batik과 같은 SVG 도구를 사용하여 그래픽 도구를 가로 챌 수 있습니다 (이렇게하면 좋은 캡처를 제공합니다).

모든 PDF를 SVG로 변환하는 간단한 방법은 없습니다. PDF를 만드는 데 사용 된 전략과 도구에 따라 다릅니다. 일부 텍스트는 벡터로 변환되어 쉽게 재구성 할 수 없습니다. 벡터 글꼴을 설치하고 찾아보아야합니다.

업데이트 : 이제 더 이상 Batik을 사용하지 않는 패키지 PDF2SVG 로 개발했습니다 .

다양한 PDF에서 테스트되었습니다. 다음으로 구성된 SVG 출력을 생성합니다.

  • 문자 <svg:text>하나의 문자
  • 경로 <svg:path>
  • 이미지 <svg:image>

나중에 패키지는 (희망적으로) 문자를 실행 텍스트로 변환하고 경로를 더 높은 수준의 그래픽 객체로 변환합니다.

업데이트 : 이제 SVG 문자에서 실행중인 텍스트를 다시 만들 수 있습니다. 또한 다이어그램을 도메인 별 XML (예 : 화학 스펙트럼)으로 변환했습니다. https://bitbucket.org/petermr/svg2xml-dev를 참조 하십시오 . 아직 알파에 있지만 유용한 속도로 움직이고 있습니다. 누구나 참여할 수 있습니다!

최신 정보. (@Tim Kelty) 우리는 계속해서 PDF2SVG와 Java OCR을 수행하는 다운 스트림 도구와 더 높은 수준의 그래픽 프리미티브 (화살표, 상자 등) 생성 작업을 계속하고 있습니다. https://bitbucket.org/petermr/ 참조 imageanalysis https://bitbucket.org/petermr/diagramanalyzer https://bitbucket.org/petermr/normahttps://bitbucket.org/petermr/ami-core . 이것은 대부분이 PDF 인 과학 문헌 (contentmine.org)에서 1 억 개의 사실을 캡처하기위한 자금 지원 프로젝트입니다.


이 주제는 꽤 오래되었지만 여기 내가 찾은 편리한 솔루션이 있습니다.

http://www.cityinthesky.co.uk/opensource/pdf2svg/

일단 설치되면 명령 줄에서 정확히 작업을 수행하는 도구 pdf2png를 제공합니다. 비트 맵을 포함하여 지금까지 비난 할 수없는 결과로 테스트했습니다.

편집 : 내 실수,이 도구는 문자를 경로로 변환하므로 초기 질문을 해결하지 않습니다. 그러나 어쨌든 그것은 좋은 일을하고 svg 파일의 코드를 수정하지 않으려는 사람에게 유용 할 수 있으므로 게시물을 남겨 두겠습니다.


내가 사용한 과정은 다음과 같습니다. 내가 사용한 주요 도구는 텍스트를 잘 변환 할 수있는 Inkscape였습니다.

  • JavaScript와 함께 Adobe Acrobat Pro 작업을 사용하여 PDF 시트를 분할했습니다.
  • Windows Cmd에서 Inkscape Portable 0.48.5를 실행하여 SVG로 변환
  • Windows Cmd 및 Windows PowerShell을 사용하여 문제가있는 특정 SVG XML 특성을 수동으로 편집했습니다.

별도 페이지 : JavaScript가 포함 된 Adobe Acrobat Pro

Adobe Acrobat Pro 작업 (이전의 일괄 처리)을 사용하여 PDF 페이지를 별도의 파일로 분리하는 사용자 정의 작업을 만듭니다. 또는 GhostScript로 PDF를 분할 할 수 있습니다.

페이지를 분할하는 Acrobat JavaScript 작업

/* Extract Pages to Folder */

var re = /.*\/|\.pdf$/ig;
var filename = this.path.replace(re,"");

{
    for ( var i = 0;  i < this.numPages; i++ )
    this.extractPages
     ({
        nStart: i,
        nEnd: i,
        cPath : filename + "_s" + ("000000" + (i+1)).slice (-3) + ".pdf"
    });
};

PDF에서 SVG로 변환 : Windows CMD 배치 파일이있는 Inkscape

Windows Cmd를 사용하여 배치 파일을 생성하여 폴더의 모든 PDF 파일을 반복하고 SVG로 변환

현재 폴더에서 PDF를 SVG로 변환하는 배치 파일

:: ===== SETUP =====
@echo off
CLS
echo Starting SVG conversion...
echo.

:: setup working directory (if different)
REM set "_work_dir=%~dp0"
set "_work_dir=%CD%"

:: setup counter
set "count=1"

:: setup file search and save string
set "_work_x1=pdf"
set "_work_x2=svg"
set "_work_file_str=*.%_work_x1%"

:: setup inkscape commands
set "_inkscape_path=D:\InkscapePortable\App\Inkscape\"
set "_inkscape_cmd=%_inkscape_path%inkscape.exe"

:: ===== FIND FILES IN WORKING DIRECTORY =====
:: Output from DIR last element is single  carriage return character. 
:: Carriage return characters are directly removed after percent expansion, 
:: but not with delayed expansion.

pushd "%_work_dir%"
FOR /f "tokens=*" %%A IN ('DIR /A:-D /O:N /B %_work_file_str%') DO (
    CALL :subroutine "%%A"
)
popd

:: ===== CONVERT PDF TO SVG WITH INKSCAPE =====

:subroutine
echo.
IF NOT [%1]==[] (

    echo %count%:%1
    set /A count+=1

    start "" /D "%_work_dir%" /W "%_inkscape_cmd%" --without-gui --file="%~n1.%_work_x1%" --export-dpi=300 --export-plain-svg="%~n1.%_work_x2%"

) ELSE (
    echo End of output
)
echo.

GOTO :eof

:: ===== INKSCAPE REFERENCE =====

:: print inkscape help
REM "%_inkscape_cmd%" --help > "%~dp0\inkscape_help.txt"
REM "%_inkscape_cmd%" --verb-list > "%~dp0\inkscape_verb_list.txt"

정리 속성 : Windows Cmd 및 PowerShell

I realize it is not best practice to manually brute force edit SVG or XML tags or attributes due to potential variations and should use an XML parser instead. However I had a simple issue where the stroke width on one drawing was very small, and on another the font family was being incorrectly identified, so I basically modified the previous Windows Cmd batch script to do a simple find and replace. The only changes were to the search string definitions and changing to call a PowerShell command. The PowerShell command will perform a find and replace and save the modified file with an added suffix. I did find some other references that could be better used to parse or modify the resultant SVG files if some other minor cleanup is needed to be performed.

Modifications to manually find and replace SVG XML data

:: setup file search and save string
set "_work_x1=svg"
set "_work_x2=svg"
set "_work_s2=_mod"
set "_work_file_str=*.%_work_x1%"

powershell -Command "(Get-Content '%~n1.%_work_x1%') | ForEach-Object {$_ -replace 'stroke-width:0.06', 'stroke-width:1'} | ForEach-Object {$_ -replace 'font-family:Times Roman','font-family:Times New Roman'} | Set-Content '%~n1%_work_s2%.%_work_x2%'"

Hope this might help someone

References

Adobe Acrobat Pro Actions and JavaScript references to Separate Pages

GhostScript references to Separate Pages

Inkscape Command Line references for PDF to SVG Conversion

Windows Cmd Batch File Script references

XML tag/attribute replacement research


Bash script to convert each page of a PDF into its own SVG file.

#!/bin/bash
#
#  Make one PDF per page using PDF toolkit.
#  Convert this PDF to SVG using inkscape
#

inputPdf=$1

pageCnt=$(pdftk $inputPdf dump_data | grep NumberOfPages | cut -d " " -f 2)

for i in $(seq 1 $pageCnt); do
    echo "converting page $i..."
    pdftk ${inputPdf} cat $i output ${inputPdf%%.*}_${i}.pdf
    inkscape --without-gui "--file=${inputPdf%%.*}_${i}.pdf" "--export-plain-svg=${inputPdf%%.*}_${i}.svg"
done

To generate in png, use --export-png, etc...


If DVI to SVG is an option, you can also use dvisvgm to convert a DVI file to an SVG file. This works perfectly for instance for LaTeX formulas (with option --no-fonts):

dvisvgm --no-fonts input.dvi -o output.svg

There is also pdf2svg which uses poppler and Cairo to convert a pdf into SVG. When I tried this, the SVG was perfectly rendered in inkscape.


I found that xfig did an excellent job:

pstoedit -f fig foo.pdf foo.fig
xfig foo.fig

export to svg

It did much better job than inkscape. Actually it was probably pdtoedit that did it.


Here is the NodeJS REST api for two PDF render scripts. https://github.com/pumppi/pdf2images

Scripts are: pdf2svg and Imagemagicks convert

참고URL : https://stackoverflow.com/questions/10288065/convert-pdf-to-clean-svg

반응형