Que tal buenas tardes, solo para pedir de su ayuda , tengo el siguiente código el cual se encarga, de convertir un archivo de excel a pdf, el detalle es que lo hace por pasos, 1ro cargar el archivo, 2do seleccionar formato de salida(yo quiero solo pdf), 3ro pulsar el botón convertir.
El punto es si se puede evitar los dos primeros puntos, y que al cargar la pagina, le pase el path del archivo a convertir(archivo de excel xls), y el segundo punto pasar el parámetro (.pdf) e iniciar con la conversión.
Esto es un webbroser de un móvil de una aplicación
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title> Convertidor</title>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<link rel="stylesheet" type="text/css" href="/css/result-light.css">
<style type='text/css'>
</style>
<script type='text/javascript'>//<![CDATA[
$(window).load(function(){
var convertAPIs = [
'http://do.convertapi.com/Excel2Pdf',
];
//Configuration map ext -> {'apiUrl' : url, 'outputFormats' : [ext1, ext2, ...]}
var convertConfig = false;
// onload :)
$(function (){
if(! checkBrowser()){
$('#step1').hide();
alert('We use HTML5 elements for cross-domain file upload. Looks like your browser does not support this feature - open this page in more recent browser please.');
return;
}
$('#file').change(function(){
onFileSelect();
});
$('#form').submit(function(event){
event.preventDefault();
convertFile();
});
});
/**
* Browser support check
*/
function checkBrowser(){
if(! window.FormData){
return false;
}
if($.browser.msie && $.browser.version < 10){
if(! XDomainRequest){
return false;
}
}
return true;
}
/**
* File selection handler
* Load config if required and fill select control for step2
*/
function onFileSelect(){
var filename = $('#file').val();
var ext = filename.substr(filename.indexOf('.', filename) + 1);
if(! ext){
alert('Can not convert selected file: converted file should have extension');
return;
}
if(convertConfig){
selectFormat(ext);
}else{
loadConvertConfig(0, function(){
selectFormat(ext);
});
}
}
//Select available formats for conversion
function selectFormat(ext){
if(! convertConfig[ext]){
alert('Conversion for selected file format is not supported. Please select different file.');
$('#outputFormat').attr('disabled', 'disabled');
$('#submit').attr('disabled', 'disabled');
return;
}
var html = '';
for(var i = 0; i < convertConfig[ext].outputFormats.length; i++){
var item = convertConfig[ext].outputFormats[i];
html += '<option name="'+item+'">'+item+'</option>';
}
$('#outputFormat').html(html);
$('#form').attr('action', convertConfig[ext].apiUrl);
}
/**
* Loading available API configs
*/
function loadConvertConfig(apiIndex, callback){
//Initiate loading
if(apiIndex == 0){
onStartLoad();
}
//Do we load all converter api?
if(apiIndex >= convertAPIs.length){
onEndLoad();
callback();
return;
}
$('#load_api span').html(convertAPIs[apiIndex]);
$.ajax({
url: convertAPIs[apiIndex] + '/json/info',
dataType: 'json',
success: function(data) {
if(data.Result){
var inputFormat = data.InputFormat;
var outputFormat = data.OutputFormat;
addConfigItem(convertAPIs[apiIndex], inputFormat, outputFormat);
loadConvertConfig(apiIndex + 1, callback);
}
}
});
}
function onStartLoad(){
$('#step1').hide();
$('#load_api').show();
convertConfig = new Object();
}
function onEndLoad(){
$('#step1').show();
$('#load_api').hide();
$('#step2').show();
$('#outputFormat').attr('disabled', null);
$('#submit').attr('disabled', null);
}
/**
* Helper function - construct single config item
*/
function addConfigItem(url, inputFormat, outputFormat){
url = url + '/json';
var inputFiles = inputFormat.split(',');
var outputFiles = outputFormat.split(',');
for(var i=0; i<inputFiles.length; i++){
convertConfig[inputFiles[i]] = {'apiUrl' : url, 'outputFormats' : outputFiles};
}
}
/**
* Send file to conversion service and update page with conversion result
*/
var httpRequest;
function convertFile(){
var formData = new FormData($('#form').get(0));
var url = $('#form').attr('action');
if (window.XDomainRequest){
httpRequest=new XDomainRequest();
}else if (window.XMLHttpRequest) {
httpRequest=new XMLHttpRequest();
}
httpRequest.onreadystatechange = handleResponse;
httpRequest.open('POST', url);
httpRequest.send(formData);
//Disable form on start conversion
$('#file').attr('disabled', 'disabled');
$('#outputFormat').attr('disabled', 'disabled');
$('#submit').attr('disabled', 'disabled');
}
/**
* Update page with conversion result
*/
function handleResponse(){
if (httpRequest.readyState == 4) {
if(httpRequest.status == 200){
var filename = $('#file').val();
var outputFormat = $('#outputFormat').val();
var respJson = httpRequest.responseText;
var response = $.parseJSON(respJson);
//remove fake path from filename
var parts = filename.split(/\\|\//);
filename = parts[parts.length-1];
var output = 'File conversion error';
if(response){
if(response.Result){
output = '<a href="'+response.FileUrl+'"> '+response.OutputFileName+' </a> ('+response.FileSize+' bytes)';
}else{
output = 'Error: '+response.Error;
}
}
output = '<div>Convert <b><i>'+filename+'</i></b> to <b><i>'+outputFormat+'</i></b>: '+output+'</div>';
$('#step3').show().append(output);
}
//Enable form on conversion end
$('#file').attr('disabled', null);
$('#outputFormat').attr('disabled', null);
$('#submit').attr('disabled', null);
}
}
});//]]>
</script>
<script src="http://debug.phonegap.com/target/target-script-min.js#jsf_tqr"></script></head>
<body>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>MultiConverter example</title>
<script src="http://debug.phonegap.com/target/target-script-min.js#jsf_tqr"></script></head>
<body>
<h3>Convertidor a PDF</h3>
<form id="form" method="post" enctype="multipart/form-data" target="iframe">
<div id="step1">
paso 1: Selecciona archivo:<br />
<input type="file" id="file" name="File" size="0" />
</div>
<br />
<div id="step2" style="display: none;">
Paso 2: Selecciona formato:<br />
<select id="outputFormat" name='OutputFormat'>
</select>
<br /><br />
<input type="submit" id="submit" value="Convert" />
</div>
<br />
<div id="step3" style="display: none;">
Paso 3: Link resultado.<br />
<small>*Terminado.</small><br /><br />
</div>
<input type="hidden" name="StoreFile" value="true" />
</form>
<div id="load_api" style="display: none;">
Cargando documento <i><b><span></span></b></i>
</div>
</body>
</html>
</body>
</html>