2013-12-18 4 views
0

지금 당분간이 문제가 발생했습니다. 내 "교정"스크립트의 끝 부분에서 InDesign에서 현재 열려있는 문서는 두 개의 다른 .pdf 파일로 내보내집니다. 첫 번째 암호는 암호로 보호되며 두 번째 암호는 암호로 보호되지 않습니다. 후자에 문제가있는 것 같지 않지만 전자는 종종 손상되어 Acrobat 자체를 비롯하여 모든 PDF 판독기에서 열 수 없습니다. 여기에 수출 수행하는 코드 블록이다 (이 BTW, 그 자체로 하지 실행 가능한 것입니다) :InDesign ExtendScript 스크립트가 내보내기 도중 손상된 PDF를 생성하는 경우가 있습니다.

/********** BEGIN PDF EXPORTING **********/ 

// First, let's create and set PDF export preferences. 
// This begins with creating a temporary preset if it doesn't already exist. 
// This preset will be used for both the Proof page and the Cover sheet. 
var tempPreset = app.pdfExportPresets.item("tempPreset"); 
try 
{ 
    tempPreset.name; 
} 
catch (eNoSuchPreset) 
{ 
    tempPreset = app.pdfExportPresets.add({name:"tempPreset"}); 
} 
with (tempPreset) 
{ 
    acrobatCompatibility = AcrobatCompatibility.ACROBAT_5; 
    bleedMarks = false; 
    colorBars = false; 
    colorBitmapCompression = BitmapCompression.AUTO_COMPRESSION; 
    colorBitmapQuality = CompressionQuality.MAXIMUM; 
    colorBitmapSampling = Sampling.BICUBIC_DOWNSAMPLE; 
    colorBitmapSamplingDPI = 300; 
    compressTextAndLineArt = true; 
    cropImagesToFrames = true; 
    cropMarks = false; 
    exportGuidesAndGrids = false; 
    exportNonprintingObjects = false; 
    exportReaderSpreads = false; 
    exportWhichLayers = ExportLayerOptions.EXPORT_VISIBLE_PRINTABLE_LAYERS; 
    generateThumbnails = false; 
    grayscaleBitmapCompression = BitmapCompression.AUTO_COMPRESSION; 
    grayscaleBitmapQuality = CompressionQuality.MAXIMUM; 
    grayscaleBitmapSampling = Sampling.BICUBIC_DOWNSAMPLE; 
    grayscaleBitmapSamplingDPI = 300; 
    includeBookmarks = false; 
    includeHyperlinks = false; 
    includeSlugArea = false; 
    includeStructure = true; 
    monochromeBitmapCompression = MonoBitmapCompression.CCIT4; 
    monochromeBitmapSampling = Sampling.BICUBIC_DOWNSAMPLE; 
    monochromeBitmapSamplingDPI = 1200; 
    omitBitmaps = false; 
    omitEPS = false; 
    omitPDF = false; 
    optimizePDF = true; 
    pageInformationMarks = false; 
    pageMarksOffset = 0.0833; 
    pdfMarkType = MarkTypes.DEFAULT_VALUE; 
    printerMarkWeight = PDFMarkWeight.P25PT; 
    registrationMarks = false; 
    standardsCompliance = PDFXStandards.NONE; 
    subsetFontsBelow = 100; 
    thresholdToCompressColor = 450; 
    thresholdToCompressGray = 450; 
    thresholdToCompressMonochrome = 1800; 
    useDocumentBleedWithPDF = false; 
} 
currentProcess.text = "PDF export preferences"; progressWin.show(); 
progressIndividual.value++; if (aProducts.length > 1) {progressOverall.value++;} 

// Now let's actually set the export preferences. These are for the proof page. 
with (app.pdfExportPreferences) 
{ 
    pageRange = proofRange; 
    useSecurity = true; 
    disallowChanging = true; 
    disallowCopying = false; 
    disallowDocumentAssembly = true; 
    disallowExtractionForAccessibility = false; 
    disallowFormFillIn = true; 
    disallowHiResPrinting = true; 
    disallowNotes = true; 
    disallowPlaintextMetadata = true; 
    disallowPrinting = false; 
    changeSecurityPassword = "sky"; 
    if (multiColor) 
    { 
     pageRange = colorTable.toString(); 
    } 
    if (currentProduct.pLabel != "") 
    { 
     pageRange += "," + labelPage.name; 
    } 
} 
currentProcess.text = "Exporting PDF proof page"; progressWin.show(); 
progressIndividual.value++; if (aProducts.length > 1) {progressOverall.value++;} 

// Before exporting the Proof page(s), hide the color bar on multicolor products. 
if (multiColor) {document.layers.item("COLOR BAR").visible = false;} 

// Then we save the proof page. 
document.exportFile(ExportFormat.PDF_TYPE, File(jobFolder.toString() + "/" + saveName + ".pdf"), false, tempPreset); 

그 동안 한 번 손상된 PDF를 생성 할 때, 나는 아마도 그것은이라고 생각 우리의 이상적이지 네트워크 구조 때문에 문제가 발생했기 때문에 대신 PDF 파일을 네트워크에 직접 연결하지 않고 로컬 하드 드라이브로 내보내고 파일을 네트워크로 옮겼습니다. 따라서 위 코드 블록의 마지막 줄은 다음과 같이 바뀌 었습니다.

// First, to the local HDD. 
document.exportFile(ExportFormat.PDF_TYPE, File("~/Documents/" + saveName + ".pdf"), false, tempPreset); 
$.sleep(1000); 
File("~/Documents/" + saveName + ".pdf").copy(File(jobFolder.toString() + "/" + saveName + ".pdf")); 
$.sleep(1000); 
File("~/Documents/" + saveName + ".pdf").remove(); 

심지어 1 초 지연으로 추가되었습니다. 슬프게도, 이것은 도움이되지 못했습니다. 나는 지금도 때때로 손상된 PDF를 받고있다. 손상된 파일에 패턴이있는 경우이를 식별 할 수 없었습니다. 누구든지 어떤 생각을 가지고 있습니까?

+0

내 생각은 : 부패는 어떻게 생겼습니까? 파일에 데이터가 남아 있습니까 (0이 아닌)? 데이터가있는 경우 파일 확장자를 ".txt"로 변경하고 TextWrangler에서 열면 어떻게됩니까? – CRGreen

+0

죄송합니다. 부패가 어떻게 보이는지에 대한 귀하의 제안을 본 적이 없었습니다. 대신 잠시 후에 게시 할 수있는 해결 방법을 만들었습니다. – Sturm

답변

0

결국 파일이 손상된 파일을 Acrobat에서 열 수 없으면 파일을 만든 후 테스트하지 않는 것이 좋을까요? 그래서 PDF 파일을 내보내고 Acrobat에서 열려고하는 루프를 만들었습니다. 파일이 잘 열리면 파일을 인쇄하고 닫아 "true"메시지를 반환합니다. 그렇게 할 수 없다면 스크립트에 "거짓"메시지를 반환합니다. 그런 다음 해당 메시지가 "거짓"인 동안 루프가 반복됩니다. 근본적인 원인 (그것이 무엇이든지간에)에 대한 중대한 수정은 아니지만 적어도 우리의 필요를 충족시킬 수있는 해결 방법입니다. Mac에서 작업하기 때문에 BridgeTalk를 사용하여 Acrobat과 직접 통신하는 대신 AppleScript로 메시지를 라우팅해야합니다.

가 여기에 PDF 검사 루프를 통과 주요 인디자인 스크립트의 코드 조각입니다 :

// Then we save the proof page. 
// The loop is to make sure that the file was saved properly. 
var validFile = false; // Flag that states whether or not the file is corrupted after saving. 
var rString; // String returned from Acrobat that should be either "true" or "false". 
var testAndPrintFile = File("~/Documents/testAndPrint.applescript"); // The applescript file that calls Acrobat and runs a folder-level script. 
var pdfFile; // A String of the filename & path that will be passed to through the applescript file to Acrobat. 
var pdfArray = new Array(4); // An array to send to Acrobat. [0] is the PDF filename as a String, 
          // [1] is duplex if true, [2] is the printer name, and [3] is to enable printing. 
if (multiTwoSided || twoPages) pdfArray[1] = "true"; 
    else pdfArray[1] = "false"; 
pdfArray[2] = localPrinter; 
pdfArray[3] = "true"; 
while (!validFile) 
{ 
    $.writeln("If this message is seen more than once, then the Proof PDF was corrupted."); 
    try 
    { 
     document.exportFile(ExportFormat.PDF_TYPE, File(jobFolder.toString() + "/" + saveName + ".pdf"), false, tempPreset); 
    } 
    catch (e) 
    { 
     alert("Could not save the Proof PDF. Please close any open copies of the Proof PDF, then save and print it manually."); 
    } 
    pdfFile = jobFolder.toString() + "/" + saveName + ".pdf"; 
    pdfArray[0] = pdfFile; 
    $.writeln("pdfArray contains: " + pdfArray); 
    try 
    { 
     rString = app.doScript(testAndPrintFile, ScriptLanguage.APPLESCRIPT_LANGUAGE, pdfArray); 
     validFile = rString == "true"; 
     // validFile = true; 
     $.writeln("validFile is " + validFile); 
     if (!validFile) 
     { 
      alert("It seems that the file " + unescape(pdfArray[0]) + " is corrupted. Will try to export it again."); 
     } 
    } 
    catch (e) 
    { 
     $.writeln("ERROR at line number " + e.line); 
     $.writeln(e.description); 
     throw new Error("ERROR at line number " + e.line + "\n" + e.description); 
    } 
} 

testAndPrint.applescript이 파일이이 루프 전화 :

set pdfFile to item 1 of arguments 
set duplexed to item 2 of arguments 
set printerName to item 3 of arguments 
set printEnabled to item 4 of arguments 
tell application "Adobe Acrobat Pro" 
    set result to do script ("testAndPrint(\"" & pdfFile & "\", \"" & duplexed & "\", \"" & printerName & "\", \"" & printEnabled & "\");") 
end tell 
return result 

그리고 마지막으로, Acrobat이 시작될 때 메모리에로드되는 폴더 수준의 Javascript 파일로 위의 AppleScript 파일에서 호출 할 함수를 준비합니다.

var testAndPrint = app.trustedFunction(function (fName, duplexed, sPrinterName, bEnablePrinting) 
{ 
    var success = true; 
    app.beginPriv(); 
    console.println("fName is " + unescape(fName)); 
    console.println("sPrinterName is " + sPrinterName); 
    try 
    { 
     var printDoc = app.openDoc(unescape(fName)); 
     var pp = printDoc.getPrintParams(); 
     if (duplexed == "true") pp.DuplexType = pp.constants.duplexTypes.DuplexFlipLongEdge; 
      else pp.DuplexType = pp.constants.duplexTypes.Simplex; 
     pp.printerName = sPrinterName; 
     pp.interactive = pp.constants.interactionLevel.silent; 
     pp.pageHandling = pp.constants.handling.none; 
     if (bEnablePrinting == "true") printDoc.print({bUI: false, bSilent: true, bShrinkToFit: false, printParams: pp}); 
     printDoc.closeDoc(true); 
    } 
    catch (e) 
    { 
     console.println("ERROR at line number " + e.lineNumber); 
     console.println(e.message); 
     success = false; 
    } 
    app.endPriv(); 
    console.println("success is " + success); 
    return success; 
}); 

아마도이 정보가 비슷한 문제가있는 다른 사용자에게 유용 할 수 있기를 바랍니다. 물론 예쁜 것은 아니지만 확실히 일을 끝내게됩니다.