Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagevb
themeEmacs
titleimport.asp
linenumberstrue
<%@ CodePage=65001 Language=VBScript %>
<% Option Explicit %>
<%
    On Error Resume Next 
    Dim CONVERTER, FONTS, WORK, UPLOAD_PATH
    CONVERTER = "C:\workspace\seimporter\sedocConverter\sedocConverter.exe"
    FONTS = "C:\workspace\seimporter\fonts"
    WORK = "C:\workspace\seimporter\tmp"
    UPLOAD_PATH = "C:\inetpub\wwwroot\upload"
  
    
    Dim filePath, outputPath, uuid, relativeOutputPath


    Dim Upload
    '업로드를 처리할 오브젝트를 생성합니다.
    Set Upload = Server.CreateObject("TABSUpload4.Upload")
    Upload.CodePage = 65001

    '업로드를 시작합니다.
    Upload.Start "C:\TEMP"
    Upload.Save UPLOAD_PATH, False

    '저장된 파일 경로
    filePath = Upload.Form("file").SaveName

    'UUID 생성 (unique path)
    uuid = CreateGUID()

    outputPath = "C:\inetpub\wwwroot\output\" & uuid
    relativeOutputPath = "/output/" & uuid

    '문서변환
    Dim wshShell, strCmd, result
    'Set wshShell = CreateObject( "WScript.Shell" )
    strCmd = CONVERTER & " -pz -f " & FONTS & " """ & filePath & """ " & outputPath & " " & WORK 
    'result = wshShell.Run(strCmd, 0, true)
    result = Exec(strCmd, 1)

    If Not result = 0 Then
        Response.write "Error : " & result
    Else
        '변환이 완료되면 원본문서 삭제
        DeleteExistFile(filePath)
    End If

    Set wshShell = nothing
    Set Upload = Nothing


    'document.word.pb 파일을 serialized해서 전달
    Dim bin
    bin = ReadBinaryFile(outputPath & "\" & "document.word.pb")

    'pb파일은 읽어들인 후 삭제
    DeleteExistFile(outputPath & "\" & "document.word.pb")
    
    '결과를 json 형태로 반환
    Response.ContentType = "application/json"
    Response.write("{""importPath"":""" & relativeOutputPath & """, ""serializedData"":" & BinaryToString(bin) & "}")

    Function Exec(c, t)
        Dim s, e : Set s = CreateObject("WScript.Shell") : Set e = s.Exec(c)
        Do While e.Status = 0
            Call s.Run("waitfor /t 130 OneSecondThirtySeconds", 0, True)
            t = t - 1
            If 0 >= t Then
            Call s.Run("taskkill /t /f /pid " & e.ProcessId, 0, True)
            Exit Do
            End If
        Loop
        Set Exec = e
    End Function

    'UUID 생성
    Function CreateGUID()
        Dim tmpTemp
        tmpTemp = Right(String(4,48) & Year(Now()),4)
        tmpTemp = tmpTemp & Right(String(4,48) & Month(Now()),2)
        tmpTemp = tmpTemp & Right(String(4,48) & Day(Now()),2)
        tmpTemp = tmpTemp & Right(String(4,48) & Hour(Now()),2)
        tmpTemp = tmpTemp & Right(String(4,48) & Minute(Now()),2)
        tmpTemp = tmpTemp & Right(String(4,48) & Second(Now()),2)
        CreateGUID = tmpTemp
    End Function

    Function DeleteExistFile(filePath) 
        Dim fso, result 
        Set fso = CreateObject("Scripting.FileSystemObject") 
        If fso.FileExists(filePath) Then 
            fso.DeleteFile(filePath) '파일이 존재하면 삭제합니다. 
            result = 1 
        Else 
            result = 0 
        End If 
        DeleteExistFile = result 
    End Function 

    Function ReadBinaryFile(FileName) 
        Const adTypeBinary = 1 
        
        'Stream object 생성
        Dim BinaryStream 
        Set BinaryStream = CreateObject("ADODB.Stream") 
        
        'Stream type 정의 
        BinaryStream.Type = adTypeBinary 

        '스트림 열기 
        BinaryStream.Open 
        
        BinaryStream.Position = 0 
        
        '파일을 스트림으로 열기
        BinaryStream.LoadFromFile FileName 
        

        '스트림 읽기
        ReadBinaryFile = BinaryStream.Read 
        
        BinaryStream.Close
        Set BinaryStream = Nothing
    End Function 

    
    Function BinaryToString(Binary)
        Dim I, S
        S = "["
        For I = 17 To LenB(Binary)
            S = S & CStr(AscB(MidB(Binary, I, 1)))
            If I < LenB(Binary) Then
                S = S & ","
            End If
        Next
        S = S & "]"
        BinaryToString = S
    End Function 
%>

...