2017-02-21 1 views
0

내가 업로드하고 HTML 파일을 업데이트하고 문자로 설정 용지 크기의 문서를 생성생성 Google 드라이브에 문서 및

include_once ROOT.'/google-api-php-client/vendor/autoload.php'; 

$client = new Google_Client(); 

$credentialsFile = ROOT.'/google-api-php-client/service_account.json'; 
if (!file_exists($credentialsFile)) { 
    throw new RuntimeException('Service account credentials Not Found!'); 
} 

$client->setAuthConfig($credentialsFile); 
$client->setScopes(Google_Service_Drive::DRIVE); 

$service = new Google_Service_Drive($client); 

/** 
    * Проверка существования папки для документов 
    */ 

$optParams = array(
    'q' => "name='Документы'" 
); 
$results = $service->files->listFiles($optParams); 
if (count($results->getFiles()) == 0) { 
exit('Нет папки для документов'); 
} else { 
    foreach ($results->getFiles() as $file) { 
$papka_doc = $file->getId(); 
    } 
} 
/** 
    * Обращение к шаблону 
    */ 

$optParams = array(
    'q' => "name='{$tpl_name}' " 
); 
$results = $service->files->listFiles($optParams); 
if (count($results->getFiles()) == 0) { 
exit('Нет шаблона'); 
} else { 
    foreach ($results->getFiles() as $file) { 
$sh_id = $file->getId(); 
    } 
} 
/** 
    * Получение контента из шаблона 
    */ 

$content = $service->files->export($sh_id, 'text/html', array(
'alt' => 'media')); 
$dd =$content->getBody(); 

$chto = array_keys ($replace); 
$chto= $this->translit($chto); 


$nachto =array_values ($replace); 
$nachto= $this->translit($nachto); 


$dd = str_replace($chto, $nachto, $dd); 



/** 
    * Создание основы для документа 
    */ 
$fileId = $sh_id; 
$doc_name = $tpl_name.'_'.date('dmY-Hi'); 
$fileMetadata = new Google_Service_Drive_DriveFile(array(
    'name' => $doc_name, 
    'parents' => array($papka_doc))); 
$file = $service->files->copy($fileId, $fileMetadata, array(
    'fields' => 'id')); 
$new_file_id = $file->id; 

/** 
    * Вставка контента в новый документ 
    */ 
$fileMetadata = array(
    'data' => $dd); 
$filenew = new Google_Service_Drive_DriveFile(); 
$file = $service->files->update($new_file_id, $filenew, $fileMetadata); 

기본 Google 문서로 변환하기 위해 PHP 라이브러리를 사용의 용지 크기를 변경 . 내 계정의 경우 기본값은 A4이며 새로 만든 문서를이 형식으로 만들려고합니다. 누구나 업로드 된 문서의 용지 크기를 설정하는 방법을 알고 있습니까?

피씨 : this 실을 봤지만 방법이 나타날 수 있습니까?

+0

문서를 검색했지만 불행히도 관련 예제를 찾지 못했습니다. [thread] (http://stackoverflow.com/questions/24183561/uploading-a-document-to-google-drive-and-setting-its-paper-size)에 명시된 바와 같이 아직 지원되지 않습니다. 그러나 이에 대한 [기능 요청] (https://productforums.google.com/forum/#!topic/drive/TESSj1GH1Xw)을 제출할 수 있습니다. – abielita

답변

0

Google 드라이브에는 file resource이라는 파일이 있습니다. 기본적으로 파일에 대한 정보의 메타 데이터 목록입니다. 이러한 필드 중 일부는 업데이트 할 수 없습니다. 내가 위에 링크 된 페이지의 상태를 기록하는 필드.

용지 크기에 대한 정보는 없습니다. 이는 드라이브가 로컬 컴퓨터가 파일을 인쇄 할 때 설정하는 용지 크기에 신경을 쓰지 않기 때문일 수 있습니다.

답변 : 구글에서 파일 없음 사용자가 설정 캔트 용지 크기

0

당신은 애플리케이션 스크립트와 함께 할 수있는 거리에 있습니다. 조금 해키지만 작동해야합니다. 문서 서비스를 사용하는 애플리케이션 스크립트 함수를 생성 (https://developers.google.com/apps-script/reference/documenthttps://developers.google.com/apps-script/reference/document/body#setPageHeight%28Number%29를 참조

  1. 이 될 수 있도록 게시 주어진 문서 ID
  2. 의 페이지 매개 변수를 조작하기 위해 해당 스크립트 https://developers.google.com/apps-script/guides/content을 - :에 당신은해야합니다 엔드 포인트로 불렀다. 당신은 당신이 현재하고있는 것처럼 파일을 가져온 후
  3. , G 드라이브는 $file에 새로 생성 된 파일의 ID를 반환합니다. 단계에서 엔드 포인트를 호출이 ID ($file->getId())를 사용 2.
+0

감사합니다. 시도해 보겠습니다. –

관련 문제