2017-07-17 118 views
0

代碼閱讀PDF文件,並從源PDF 返回新的文件副本時的NodeJS編譯 https://github.com/NitroPye/node-pdflib爲什麼PDF_begin_page_ext:功能不能被稱爲「對象」範圍

使用的NodeJS到PDFLIB

我得到了錯誤
const lib = require('../../pdf'); 
const pdflib = lib.pdflib; 
const PDFLIB = lib.DEFINES; 

const pdf = pdflib.PDF_new(); 

pdflib.PDF_set_option(pdf, "errorpolicy=exception"); 
pdflib.PDF_set_option(pdf, "hypertextencoding=host"); 
pdflib.PDF_set_info(pdf, "Creator", "quickreference_ios"); 
pdflib.PDF_set_info(pdf, "Author", "Thomas Merz"); 
pdflib.PDF_set_info(pdf, "Title", "mini imposition demo (Objective-C)"); 

const manual = pdflib.PDF_open_pdi_document(pdf,"ArtworkBlankApp.pdf",0,"") 
let row = 0 
let col = 0 

const endpage = parseInt(pdflib.PDF_pcos_get_number(pdf,manual, "length:pages")); 
const font = pdflib.PDF_load_font(pdf, "Helvetica-Bold", 0, "host", ""); 
for(let pageno = 1; pageno <= endpage; pageno++){ 
    pdflib.PDF_begin_page_ext(pdf, PDFLIB.a4_width, PDFLIB.a4_height, "topdown") 
    const page = pdflib.PDF_open_pdi_page(pdf, manual, pageno, ""); 
    pdflib.PDF_fit_pdi_page(pdf, page, 0 , PDFLIB.a4_height, "") 
    pdflib.PDF_close_pdi_page(pdf, page) 
    pdflin.PDF_end_page_ext("") 
} 
pdflib.PDF_end_document(pdf,"") 
pdflib.PDF_close_pdi_document(manual) 

我怎樣才能修復

回答

1

你需要調用PDFlib函數PDF_begin_document()中,然後才能創建輸出文檔中的任何內容。所以把下面的語句for循環之前會做的伎倆:

pdflib.PDF_begin_document(pdf, "out.pdf", 0, "") 

這將導致一個名爲「out.pdf」你的程序生成的PDF文件。