从 PDF 输入渲染到 TIFF 后的 Ecrion 保持文件在使用中

Ecrion after rendering from PDF input to TIFF keeps files in use

我正在使用 Web 服务使用 Ecrion Ultrascale 从 PDF 转换为 TIFF,一切正常,除了我刚刚注意到转换完成后输出文件(呈现的文件)仍在使用中,是吗有谁知道为什么会这样,我该如何解决这个问题?

[WebMethod]
    public void ConvertPDF2Tiff(string fileName, bool createFolder, string folderName)
    {
        string filename = Path.GetFileNameWithoutExtension(fileName);
        string path = Path.GetDirectoryName(fileName);
        String inFilePath = fileName;
        String outFilePath;
        if (createFolder)
        {
            outFilePath = Path.Combine(path, "temp", filename + ".tif");
        }
        else
        {
            outFilePath = Path.Combine(path, filename + ".tif");
        }
        Stream outStm = null;
        Directory.CreateDirectory(Path.Combine(path, "temp"));
        // Open the out stream
        outStm = new FileStream(outFilePath, FileMode.Create);

        // Initialize data source
        Stream sw = File.OpenRead(inFilePath);
        IDataSource input = new XmlDataSource(sw, Engine.InputFormat.PDF);

        // Initialize rendering parameters
        RenderingParameters p = new RenderingParameters();
        p.CompressionAlgorithm = Engine.CompressionAlgorithm.LZW;
        p.OutputFormat = Engine.OutputFormat.TIFF;

        // Render the TIFF
        Engine eng = new Engine();
        eng.Render(input, outStm, p);
        sw.Close();
        outStm.Close();
    }

提前致谢。

出于某种原因,[使用] 输出文件流的使用完成了这项工作。这是我使用的代码

public void ConvertPDF2Tiff(string fileName, bool createFolder, string folderName)
    {
        string filename = Path.GetFileNameWithoutExtension(fileName);
        string path = Path.GetDirectoryName(fileName);
        String inFilePath = fileName;
        String outFilePath;
        if (createFolder)
        {
            Directory.CreateDirectory(Path.Combine(path, "temp"));
            outFilePath = Path.Combine(path, "temp", filename + ".tif");
        }
        else
        {
            outFilePath = Path.Combine(path, filename + ".tif");
        }
        //Stream outStm = File.Create(outFilePath);

        // Open the out stream
        //outStm = new FileStream(outFilePath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite, 0, FileOptions.None);
        //outStm = File.Create(outFilePath);
        // Initialize data source
        Stream sw = File.OpenRead(inFilePath);
        IDataSource input = new XmlDataSource(sw, Engine.InputFormat.PDF);

        // Initialize rendering parameters
        RenderingParameters p = new RenderingParameters();
        p.OutputFormat = Engine.OutputFormat.TIFF;
        p.ImageErrorsHandlingMode = Engine.ImageErrorsHandlingMode.Ignore;
        p.CompressionAlgorithm = Engine.CompressionAlgorithm.LZW;


        // Render the TIFF
        Engine eng = new Engine();
        OutputInformation renderOutput = new OutputInformation();
        using (FileStream outStm = new FileStream(outFilePath, FileMode.Create))
        {
            eng.Render(input, outStm, p, ref renderOutput);
        }

        sw.Close();
        //outStm.Close();
    }

很可能您一直保持文件流处于打开状态,这反过来又将文件锁定在独占模式(意味着用于读取和写入)。 使用 (...) 相当于调用 outStm.close() 以释放底层系统文件句柄。