2014-12-15 2 views
0

PDFlib 블록이있는 PDF 파일이 있습니다. 이 블록들 중 어느 것도 채워지지 않았습니다. 그 블록을 다른 PDF 문서 세트에 복사해야합니다. 각 블록은 자체 컨텐트가 있습니다. 블록을 채울 필요는 없습니다.복사 PDFLib 블록 레이아웃

아이디어는 각 문서가 양식이지만 각각 약간 다릅니다. 양식 필드는 모두 같은 위치에 있으므로 레이아웃을 포함하여 블록을 복사하면됩니다. 나는 이미 새로운 (공백) 문서에 대한 블록이있는 단일 문서 인 것처럼 보이는 것으로 이것을 수행하는 것을 설명하는 this documentation page을 확인했습니다.

도움을 주시면 감사하겠습니다.

답변

0

이 문제를 처리하기 위해 PHP 스크립트를 작성했습니다. 아래 참조 :

try{ 
     # Create a new PDFLib instance 
     $pdf = new PDFlib(); 
     $pdf->set_option('errorpolicy=return'); 
     $pdf->set_option('stringformat=utf8'); 

     # Create the optput document 
     if(!($pdf->begin_document('',''))) 
      throw new Exception('Error: '.$pdf->get_errmsg()); 

     # Open the input document, in this case the block template file 
     $block_file = $pdf->open_pdi_document('block_template.pdf',''); 
     if($block_file == 0) throw new Exception('Error: '.$pdf->get_errmsg()); 

     # Also open the target file we need to copy blocks to 
     $target_file = $pdf->open_pdi_document('target_file.pdf',''); 
     if($target_file == 0) throw new Exception('Error: '.$pdf->get_errmsg()); 

     # Find the number of pages in the document 
     $pages = $pdf->pcos_get_number($block_file,'length:pages'); 

     # Loop over each page 
     for($page=0;$page<$pages;$page++){ 

      # Open the target file to clone its contents 
      $target_input_page = $pdf->open_pdi_page($target_file,1,''); 
      if($target_input_page == 0) throw new Exception('Error: '.$pdf->get_errmsg()); 

      # Create a blank PDF page with a dummy size 
      $pdf->begin_page_ext(10,10,''); 

      # Copy the contents of the input page to the new page. This also overrides the size set by the dummy page 
      $pdf->fit_pdi_page($target_input_page,0,0,'adjustpage'); 

      # Count the blocks on this template file page 
      $block_count = (int) $pdf->pcos_get_number($block_file, 'length:pages['.$page.']/blocks'); 

      # Loop over the blocks and copy them 
      for($i=0;$i<$block_count;$i++){ 
       $block_name = $pdf->pcos_get_string($block_file,'pages['.$page.']/blocks['.$i.'].key'); 

       if ($pdf->process_pdi($block_file,0,'action=copyblock block={pagenumber='.($page+1).' blockname={'.$block_name.'}}') == 0) 
        throw new Exception("Error: " . $pdf->get_errmsg()); 
      } 

      # End this page 
      $pdf->end_page_ext(''); 

      # Close the pdf page 
      $pdf->close_pdi_page($target_input_page); 
     } 

     # Close the PDF document 
     $pdf->close_pdi_document($block_file); 
     $pdf->close_pdi_document($target_file); 
     $pdf->end_document(''); 

     # Get the output buffer 
     $buffer = $pdf->get_buffer(); 

     # Write out the converted file 
     $output_file = fopen('output_file.pdf','w+'); 
     fwrite($output_file,$buffer); 
     fclose($output_file); 
    } 
    catch(PDFlibException $e){ 
     error_log("PDFlib exception occurred:\n" . 
      "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . 
      $e->get_errmsg() . "\n"); 
     exit(1); 
    } 
    catch(Exception $e){ 
     error_log($e); 
     exit(1); 
    } 
0

붙여 넣은 샘플에서 복사 한 블록을 배치하기 전에 대상 PDF를 가져 와서 페이지에 맞출 수 있습니다.

다른면에서 Acrobat Block Plugin을 사용하여 대화 형으로 리소스 PDF에서 대상 PDF로 복사 할 수 있습니다. 블럭 플러그인 내에서 이것을 할 때 이점은, 당신은이 작은 adjmustends를 직접 할 수 있습니다.

마지막 아이디어 :

  • 빈 PDF에 대한 모든 블록이있다.
  • 양식을 새 PDF로 가져 오기
  • 블록 템플릿을 가져오고, "blind"옵션을 가져옵니다. 따라서 블록을 처리 할 수는 있지만 시각적 인 내용은 없습니다.

이 기술은 block content below content으로도 사용됩니다.