function openAndConvert(sourceFileName, destinationFile, varargin)
% openAndConvert - Opens a source MATLAB Rich Code file and convert file
%
%   openAndSave(sourceFileName, destinationFile) - open the source Live Code file
%   and convert to the destination file
%
%   Example:
%
%       matlab.internal.liveeditor.openAndConvert(liveCodeFileName, htmlFileName);

validateattributes(sourceFileName, {'char'}, {'nonempty'}, mfilename, 'sourceFileName', 1)

validateattributes(destinationFile, {'char'}, {'nonempty'}, mfilename, 'destinationFile', 2)

import matlab.internal.liveeditor.LiveEditorUtilities

% Opens the file in a headless mode
[javaRichDocument, cleanupObj, webwindow] = LiveEditorUtilities.open(sourceFileName); %#ok<ASGLU>

% g2181840 Resize the webwindow such that there is no scrollbar in document.
% This will ensure that any element whose screenshot needs to be taken for
% examples don't have scrollbars either. Using default BaT window size.
webwindow.Position = [0 0 1300 768];

% Saves the contents into the file
LiveEditorUtilities.saveas(javaRichDocument, destinationFile, varargin{:})
end
