2015-01-13 6 views
0

내 앱 mobile cordova에서 원격 URL에서 다운로드 한 pdf 파일을 인쇄하고 싶습니다.
phonegap-print-plugincordova-plugin-printer과 같은 일부 플러그인을 제거했지만 텍스트 콘텐츠 또는 html 문서 만 인쇄 할 수 있습니다.
내 요청을 충족시킬 수있는 도구가 있습니까?cordova에 pdf 파일 인쇄

+0

나는 (곡예사 같은) 다른 응용 프로그램에서 PDF를 열고 제안하고 해당 응용 프로그램에서 인쇄 할 것입니다. fileOpener2 플러그인을 사용하여 연결된 앱과 함께 pdf를 열 수 있습니다. – QuickFix

+0

답변 해 주셔서 감사합니다. 내가 제안한 플러그인을 추가하고 PDF 파일을 비공개 디렉토리에 저장하십시오. 그런 다음 Acrobat Reader 또는 내 프린터 용으로 지정된 응용 프로그램을 통해 PDF 파일을 열어 인쇄 할 수있었습니다. –

답변

1

다른 응용 프로그램에서 먼저 열지 않아도 base64로 인코딩 된 문자열에서 pdf를 인쇄하는 cordova 플러그인을 작성했습니다. 당신은 이온 2/3에서 코르도바 - 플러그인 - 인쇄 PDF를 사용하려면

https://github.com/sarahgoldman/cordova-print-pdf-plugin

+0

Windows Mobile을 지원할 계획이 있습니까? –

+2

안녕하세요 sgoldman, 프로젝트를 확인하고 있는데 Github 가이드에 실제 base64 문자열을 사용하는 예를 넣을 수 있는지 궁금합니다. 정말로 감사 할 것입니다. 또한 다른 플러그인을 사용하여 base64로 변환 한 후 인쇄하는 다른 예가있을 수 있습니다! 모든 일에 감사드립니다! 좋은 플러그인! 또한 "type : file/data"라고하면 파일의 절대 경로가 필요하다는 것을 의미하며 데이터는 base64 문자열을 의미합니까?어쨌든, 당신이 문서에 지정할 수 있다면 그것은 놀라실 것입니다 !! – dherre3

+0

몇 가지 설치 지침이 좋겠지 만 작업에 대한 감사 Sarah – Shard

0

, 당신은 자바 스크립트로 타이프 세계에서 액세스 할 수 있어야합니다. 새로운 이온에는 많은 플러그인이 있습니다. 단서는 Npm에서 래퍼 파일을로드하는 것입니다. 래퍼를 찾지 못했습니다. 여기서는 발췌 문장입니다.

인쇄 기능 만 구현되었습니다.

이 모듈은 app.module.ts와 모듈에 추가해야합니다.이 모듈은 사용 계획이있는 모듈에서 사용해야합니다. 같은 방법으로 당신은 새로운 "모든"플러그인을 사용할 수 있습니다. 가능한 한 오류가 발생하면 디버그해야하며 Chrome의 개발자 콘솔에서 원격 디버그 할 수 있습니다. 여기에 원격 디버깅으로 안드로이드에서 자바 스크립트를 디버깅 할 때

/** 
 
* @constructor 
 
*/ 
 
var PrintPDF = function() { 
 
    this.METHOD = 'printDocument'; 
 
    this.IS_AVAILABLE_METHOD = 'isPrintingAvailable'; 
 
    this.DISMISS_METHOD = 'dismissPrintDialog'; 
 
    this.CLASS = 'PrintPDF'; 
 
}; 
 

 
PrintPDF.prototype.print = function(options) { 
 

 
    options = options || {}; 
 

 
    var data = options.data; // print data, base64 string (required) 
 

 
    var type = options.type || 'Data'; // type of document 
 

 
    var title = options.title || 'Print Document'; // title of document 
 

 
    var dialogX = options.dialogX || -1; // if a dialog coord is not set, default to -1. 
 
    // the iOS method will fall back to center on the 
 
    var dialogY = options.dialogY || -1; // screen if it gets a dialog coord less than 0. 
 

 
    // make sure callbacks are functions or reset to null 
 
    var successCallback = (options.success && typeof(options.success) === 'function') ? options.success : this.defaultCallback; 
 

 
    var errorCallback = (options.error && typeof(options.error) === 'function') ? options.error : this.defaultCallback; 
 

 
    // make sure data is set 
 
    if (!data) { 
 
    if (errorCallback) { 
 
     errorCallback({ 
 
     success: false, 
 
     error: "Parameter 'data' is required." 
 
     }); 
 
    } 
 
    return false; 
 
    } 
 

 
    var args = [data]; 
 

 
    if (device.platform === "iOS") { 
 
    args.push(type); 
 
    args.push(dialogX); 
 
    args.push(dialogY); 
 

 
    } else { 
 
    args.push(type); 
 
    args.push(title); 
 

 
    } 
 

 
    // make the call 
 
    cordova.exec(successCallback, errorCallback, this.CLASS, this.METHOD, args); 
 

 
}; 
 

 
PrintPDF.prototype.isPrintingAvailable = function (callback) { 
 

 
    // make sure callbacks are functions or reset to null 
 
    var successCallback = (callback && typeof(callback) === 'function') ? callback : this.defaultCallback; 
 

 
    cordova.exec(successCallback, null, this.CLASS, this.IS_AVAILABLE_METHOD, []); 
 

 
}; 
 

 
PrintPDF.prototype.dismiss = function() { 
 

 
    // Dismiss is only an iOS method because the dialog exists in the 
 
    // same context as the cordova activity. In Android, when the 
 
    // print activity starts, the cordova activity is paused. 
 

 
    if (device.platform === "iOS") { 
 

 
    cordova.exec(null, null, this.CLASS, this.DISMISS_METHOD, []); 
 

 
    } 
 

 
}; 
 

 
PrintPDF.prototype.defaultCallback = null; 
 

 
// Plug in to Cordova 
 
cordova.addConstructor(function() { 
 
    if (!window.Cordova) { 
 
    window.Cordova = cordova; 
 
    }; 
 

 
    if (!window.plugins) window.plugins = {}; 
 
    window.plugins.PrintPDF = new PrintPDF(); 
 
}); 
 
/** 
 
* @constructor 
 
*/ 
 
var PrintPDF = function() { 
 
    this.METHOD = 'printDocument'; 
 
    this.IS_AVAILABLE_METHOD = 'isPrintingAvailable'; 
 
    this.DISMISS_METHOD = 'dismissPrintDialog'; 
 
    this.CLASS = 'PrintPDF'; 
 
}; 
 

 
PrintPDF.prototype.print = function(options) { 
 

 
    options = options || {}; 
 

 
    var data = options.data; // print data, base64 string (required) 
 

 
    var type = options.type || 'Data'; // type of document 
 

 
    var title = options.title || 'Print Document'; // title of document 
 

 
    var dialogX = options.dialogX || -1; // if a dialog coord is not set, default to -1. 
 
    // the iOS method will fall back to center on the 
 
    var dialogY = options.dialogY || -1; // screen if it gets a dialog coord less than 0. 
 

 
    // make sure callbacks are functions or reset to null 
 
    var successCallback = (options.success && typeof(options.success) === 'function') ? options.success : this.defaultCallback; 
 

 
    var errorCallback = (options.error && typeof(options.error) === 'function') ? options.error : this.defaultCallback; 
 

 
    // make sure data is set 
 
    if (!data) { 
 
    if (errorCallback) { 
 
     errorCallback({ 
 
     success: false, 
 
     error: "Parameter 'data' is required." 
 
     }); 
 
    } 
 
    return false; 
 
    } 
 

 
    var args = [data]; 
 

 
    if (device.platform === "iOS") { 
 
    args.push(type); 
 
    args.push(dialogX); 
 
    args.push(dialogY); 
 

 
    } else { 
 
    args.push(type); 
 
    args.push(title); 
 

 
    } 
 

 
    // make the call 
 
    cordova.exec(successCallback, errorCallback, this.CLASS, this.METHOD, args); 
 

 
}; 
 

 
PrintPDF.prototype.isPrintingAvailable = function (callback) { 
 

 
    // make sure callbacks are functions or reset to null 
 
    var successCallback = (callback && typeof(callback) === 'function') ? callback : this.defaultCallback; 
 

 
    cordova.exec(successCallback, null, this.CLASS, this.IS_AVAILABLE_METHOD, []); 
 

 
}; 
 

 
PrintPDF.prototype.dismiss = function() { 
 

 
    // Dismiss is only an iOS method because the dialog exists in the 
 
    // same context as the cordova activity. In Android, when the 
 
    // print activity starts, the cordova activity is paused. 
 

 
    if (device.platform === "iOS") { 
 

 
    cordova.exec(null, null, this.CLASS, this.DISMISS_METHOD, []); 
 

 
    } 
 

 
}; 
 

 
PrintPDF.prototype.defaultCallback = null; 
 

 
// Plug in to Cordova 
 
cordova.addConstructor(function() { 
 
    if (!window.Cordova) { 
 
    window.Cordova = cordova; 
 
    }; 
 

 
    if (!window.plugins) window.plugins = {}; 
 
    window.plugins.PrintPDF = new PrintPDF(); 
 
});

유용한 중단 점 cordova.js에 있습니다

기능 빌드 (모듈)
가를 확인하려면 모듈 - 모든 모듈, 플러그인뿐 아니라 어떤 모듈이로드되었는지 확인하십시오. 모듈이 없으면 오류 메시지는 없지만 이전에 비어있는 개체가 남아 있습니다. 반환 module.exports는 "modullist"에서 플러그인

onScriptLoadingComplete (moduleList, finishPluginLoading) 의 방법 모든 플러그인을 포함 포함되어 있습니다. 이것들은 "symbollist"에게 배정 될 것입니다. "symbollist"는 유형 (Clobber, Merge, Default, Run), PluginName 및 Clobber로 구성됩니다. 소지품은 기능이 모듈의 코드의 URL이 전달

exports.injectScript 일반적으로 창, 코르도바 또는 네비게이터를 해결하는에 "pluginRef"입니다. 이 URL이있는 태그가 HTML 요소 "document.head"에 추가됩니다.

CodeExample는 : https://github.com/alpinea310/ch.schb.rav.mobil