Search code examples
.netecrion

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


I'm using a webservice to convert from PDF to TIFF using Ecrion Ultrascale, everything works fine except that I've just noticed that the output file(the rendered file) is still in use after conversion is completed, does anyone knows why this is happening and how can I resolve this issue?

[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();
    }

Thanks in advance.


Solution

  • Most likely you were keeping the files stream open, which in turn locked the file in exclusive mode (meaning both for reading and for writing). using (...) is equivalent to calling outStm.close() in order to release the underlying system file handle.