i tried to insert an image in my header. it's ok.
And now i want to center the picture but i'm just stuck.
$requests[] = new \Google_Service_Docs_Request(array(
'insertInlineImage' => array(
'uri' => 'https://myPicture.png',
'location' => array(
'segmentId' => $document->getDocumentStyle()->getDefaultHeaderId(),
'index' => 0
),
),
));
You want to insert an inline image at the center of the header in Google Document.
You want to achieve this using google-api-php-client with PHP.
You have already been able to get and put values for Google Document using Google Docs API.
If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.
Modification point:
In order to put the image at the center, please add UpdateParagraphStyleRequest to the request body of the batchUpdate, because InsertInlineImageRequest has no propaty of alignment.
Modified script:
$documentId = '###'; // Please set the Document ID.
$segmentId = $document->getDocumentStyle()->getDefaultHeaderId();
$service = new Google_Service_Docs($client);
$requests = [
new Google_Service_Docs_Request([
'insertInlineImage' => [
'location' => ['index' => 0, 'segmentId' => $segmentId],
'uri' => 'https://icir.int.demedicis.fr/img/logo/veolia.png'
]
]),
new Google_Service_Docs_Request([
'updateParagraphStyle' => [
'range' => ['startIndex' => 0, 'endIndex' => 1, 'segmentId' => $segmentId],
'paragraphStyle' => ['alignment' => 'CENTER'],
'fields' => 'alignment'
]
])
];
$batchUpdateRequest = new Google_Service_Docs_BatchUpdateDocumentRequest(['requests' => $requests]);
$result = $service->documents->batchUpdate($documentId, $batchUpdateRequest);
Note:
When $document->getDocumentStyle()->getDefaultHeaderId() cannot be used, please set the header ID like kix.### as the string value.
This is a simple modification. So please reflect this to your actual script.
References:
UpdateParagraphStyleRequest
InsertInlineImageRequest
If I misunderstood your question and this was not the direction you want, I apologize.
Related
I'm using the Docusign PHP SDK to create an envelope using a PDF with pre-existing form fields.
The fields are correctly being parsed by Docusign and show up on the resulting document.
However, I can't find a way to prefill some of those fields.
// Create document model
$document = new Document([
'document_base64' => $base64_content,
'name' => 'Document',
'file_extensions' => 'pdf',
'document_id' => 1, 'transform_pdf_fields' => true
]);
$signer = new Signer([
'email' => $args['client_email'],
'name' => $args['client_name'],
'recipient_id' => 1,
'routing_order' => 1,
'client_user_id' => $args['client_user_id']
]);
// This is the attempt to prefill the fields
// by using the same label as the PDF form.
// But it does nothing.
$text1 = new Text([
'tab_label' => 'field_one', 'value' => $args['client_coverage'],
]);
$text2 = new Text([
'tab_label' => 'field_two', 'value' => $args['client_term'],
]);
$signer->setTabs(new Tabs(['text_tabs' => [$text1, $text2]]));
$definition = new EnvelopeDefinition([
'email_subject' => "Please sign this document",
'documents' => [$document],
'recipients' => new Recipients(['signers' => [$signer]]),
'status' => 'sent',
]);
A call to the envelope tabs API shows the tabs in question with the exact tab label but the value is blank.
Any suggestions would be very appreciated! Thanks.
P.S. I can, after the envelope creation, get the document tabs, in order to get their IDs, and then make another request to update those.
So this is doable in 3 calls but I have a feeling that it should be possible to do in one - when the envelope is created initially.
#sdragnev, this can work if you use composite templates
$inline_template = new \DocuSign\eSign\Model\InlineTemplate([
'recipients' => new Recipients(['signers' => [$signer]]),
'sequence' => "1"
]);
$inline_templates = [$inline_template];
$composite_template = new \DocuSign\eSign\Model\CompositeTemplate([
'composite_template_id' => "1",
'document' => $document,
'inline_templates' => $inline_templates
]);
$composite_templates = [$composite_template];
$envelope_definition = new \DocuSign\eSign\Model\EnvelopeDefinition([
'composite_templates' => $composite_templates,
'email_subject' => "Agreement",
'status' => "sent"
]);
I am connected to my Google sheets, when I run a post request for https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/create and set no properties, it creates a new spreadsheet.
I would love to add a title so I did this
$options = [
'form_params' => [
'properties' => [
'title' => 'A new title'
]
]
];
$client->post('v4/spreadsheets', $options);
I am using Guzzle to make this call. As a response I'm getting HTTP status code 400 (Bad Request) when adding title to form params.
How can I solve this?
You really should be using Google's SDK for this since they already have support for one in PHP.
According to their docs, sheet properties are set in a Google_Service_Sheets_SpreadsheetProperties instance which takes the title property.
An example from their docs:
<?php
$spreadsheet = new Google_Service_Sheets_Spreadsheet([
'properties' => [
'title' => $title
]
]);
$spreadsheet = $service->spreadsheets->create($spreadsheet, [
'fields' => 'spreadsheetId'
]);
printf("Spreadsheet ID: %s\n", $spreadsheet->spreadsheetId);
I am working on a project where we will be creating both subdomains as well as domains in Route53. We are hoping that there is a way to do this programmatically. The SDK for PHP documentation seems a little light, but it appears that createHostedZone can be used to create a domain or subdomain record and that changeResourceRecordSets can be used to create the DNS records necessary. Does anyone have examples of how to actually accomplish this?
Yes, this is possible using the changeResourceRecordSets call, as you already indicated. But it is a bit clumsy since you have to structure it like a batch even if you're changing/creating only one record, and even creations are changes. Here is a full example, without a credentials method:
<?php
// Include the SDK using the Composer autoloader
require 'vendor/autoload.php';
use Aws\Route53\Route53Client;
use Aws\Common\Credentials\Credentials;
$client = Route53Client::factory(array(
'credentials' => $credentials
));
$result = $client->changeResourceRecordSets(array(
// HostedZoneId is required
'HostedZoneId' => 'Z2ABCD1234EFGH',
// ChangeBatch is required
'ChangeBatch' => array(
'Comment' => 'string',
// Changes is required
'Changes' => array(
array(
// Action is required
'Action' => 'CREATE',
// ResourceRecordSet is required
'ResourceRecordSet' => array(
// Name is required
'Name' => 'myserver.mydomain.com.',
// Type is required
'Type' => 'A',
'TTL' => 600,
'ResourceRecords' => array(
array(
// Value is required
'Value' => '12.34.56.78',
),
),
),
),
),
),
));
The documentation of this method can be found here. You'll want to take very careful note of the required fields as well as the possible values for others. For instance, the name field must be a FQDN ending with a dot (.).
Also worth noting: You get no response back from the API after this call by default, i.e. there is no confirmation or transaction id. (Though it definitely gives errors back if something is wrong.) So that means that if you want your code to be bulletproof, you should write a Guzzle response handler AND you may want to wait a few seconds and then run a check that the new/changed record indeed exists.
Hope this helps!
Yes, I done using changeResourceRecordSets method.
<?php
require 'vendor/autoload.php';
use Aws\Route53\Route53Client;
use Aws\Exception\CredentialsException;
use Aws\Route53\Exception\Route53Exception;
//To build connection
try {
$client = Route53Client::factory(array(
'region' => 'string', //eg . us-east-1
'version' => 'date', // eg. latest or 2013-04-01
'credentials' => [
'key' => 'XXXXXXXXXXXXXXXXXXX', // eg. VSDFAJH6KXE7TXXXXXXXXXX
'secret' => 'XXXXXXXXXXXXXXXXXXXXXXX', //eg. XYZrnl/ejPEKyiME4dff45Pds54dfgr5XXXXXX
]
));
} catch (Exception $e) {
echo $e->getMessage();
}
/* Create sub domain */
try {
$dns = 'yourdomainname.com';
$HostedZoneId = 'XXXXXXXXXXXX'; // eg. A4Z9SD7DRE84I ( like 13 digit )
$name = 'test.yourdomainname.com.'; //eg. subdomain name you want to create
$ip = 'XX.XXXX.XX.XXX'; // aws domain Server ip address
$ttl = 300;
$recordType = 'CNAME';
$ResourceRecordsValue = array('Value' => $ip);
$client->changeResourceRecordSets([
'ChangeBatch' => [
'Changes' => [
[
'Action' => 'CREATE',
"ResourceRecordSet" => [
'Name' => $name,
'Type' => $recordType,
'TTL' => $ttl,
'ResourceRecords' => [
$ResourceRecordsValue
]
]
]
]
],
'HostedZoneId' => $HostedZoneId
]);
}
If you get any error please check into server error.log file. If you get error from SDK library then there is might PHP version not supported.
if you run this code from your local machine then you might get "SignatureDoesNotMatch" error then Make sure run this code into same (AWS)server environment.
In my example code I am using the php client library, but it should be understood by anyone familiar with elasticsearch.
I'm using elasticsearch to create an index where each document contains an array of nGram indexed authors. Initially, the document will have a single author, but as time progresses, more authors will be appended to the array. Ideally, a search could be executed by an author's name, and if any of the authors in the array get matched, the document will be found.
I have been trying to use the documentation here for appending to the array and here for using the array type - but I have not had success getting this working.
First, I want to create an index for documents, with a title, array of authors, and an array of comments.
$client = new Client();
$params = [
'index' => 'document',
'body' => [
'settings' => [
// Simple settings for now, single shard
'number_of_shards' => 1,
'number_of_replicas' => 0,
'analysis' => [
'filter' => [
'shingle' => [
'type' => 'shingle'
]
],
'analyzer' => [
'my_ngram_analyzer' => [
'tokenizer' => 'my_ngram_tokenizer',
'filter' => 'lowercase',
]
],
// Allow searching for partial names with nGram
'tokenizer' => [
'my_ngram_tokenizer' => [
'type' => 'nGram',
'min_gram' => 1,
'max_gram' => 15,
'token_chars' => ['letter', 'digit']
]
]
]
],
'mappings' => [
'_default_' => [
'properties' => [
'document_id' => [
'type' => 'string',
'index' => 'not_analyzed',
],
// The name, email, or other info related to the person
'title' => [
'type' => 'string',
'analyzer' => 'my_ngram_analyzer',
'term_vector' => 'yes',
'copy_to' => 'combined'
],
'authors' => [
'type' => 'list',
'analyzer' => 'my_ngram_analyzer',
'term_vector' => 'yes',
'copy_to' => 'combined'
],
'comments' => [
'type' => 'list',
'analyzer' => 'my_ngram_analyzer',
'term_vector' => 'yes',
'copy_to' => 'combined'
],
]
],
]
]
];
// Create index `person` with ngram indexing
$client->indices()->create($params);
Off the get go, I can't even create the index due to this error:
{"error":"MapperParsingException[mapping [_default_]]; nested: MapperParsingException[No handler for type [list] declared on field [authors]]; ","status":400}
HAD this gone successfully though, I would plan to create an index, starting with empty arrays for authors and title, something like this:
$client = new Client();
$params = array();
$params['body'] = array('document_id' => 'id_here', 'title' => 'my_title', 'authors' => [], 'comments' => []);
$params['index'] = 'document';
$params['type'] = 'example_type';
$params['id'] = 'id_here';
$ret = $client->index($params);
return $ret;
This seems like it should work if I had the desired index to add this structure of information to, but what concerns me would be appending something to the array using update. For example,
$client = new Client();
$params = array();
//$params['body'] = array('person_id' => $person_id, 'emails' => [$email]);
$params['index'] = 'document';
$params['type'] = 'example_type';
$params['id'] = 'id_here';
$params['script'] = 'NO IDEA WHAT THIS SCRIPT SHOULD BE TO APPEND TO THE ARRAY';
$ret = $client->update($params);
return $ret;
}
I am not sure how I would go about actually appending a thing to the array and making sure it's indexed.
Finally, another thing that confuses me is how I could search based on any author in the array. Ideally I could do something like this:
But I'm not 100% whether it will work. Maybe there is something fundemental about elasticsearch that I am not understanding. I am completely new to so any resources that will get me to a point where these little details don't hang me up would be appreciated.
Also, any direct advice on how to use elasticsearch to solve these problems would be appreciated.
Sorry for the big wall of text, to recap, I am looking for advice on how to
Create an index that supports nGram analysis on all elements of an array
Updating that index to append to the array
Searching for the now-updated index.
Thanks for any help
EDIT: thanks to #astax, I am now able to create the index and append to the value as a string. HOWEVER, there are two problems with this:
the array is stored as a string value, so a script like
$params['script'] = 'ctx._source.authors += [\'hello\']';
actually appends a STRING with [] rather than an array containing a value.
the value inputted does not appear to be ngram analyzed, so a search like this:
$client = new Client();
$searchParams['index'] = 'document';
$searchParams['type'] = 'example_type';
$searchParams['body']['query']['match']['_all'] = 'hello';
$queryResponse = $client->search($searchParams);
print_r($queryResponse); // SUCCESS
will find the new value but a search like this:
$client = new Client();
$searchParams['index'] = 'document';
$searchParams['type'] = 'example_type';
$searchParams['body']['query']['match']['_all'] = 'hel';
$queryResponse = $client->search($searchParams);
print_r($queryResponse); // NO RESULTS
does not
There is no type "list" in elasticsearch. But you can use "string" field type and store array of values.
....
'comments' => [
'type' => 'string',
'analyzer' => 'my_ngram_analyzer',
'term_vector' => 'yes',
'copy_to' => 'combined'
],
....
And index a document this way:
....
$params['body'] = array(
'document_id' => 'id_here',
'title' => 'my_title',
'authors' => [],
'comments' => ['comment1', 'comment2']);
....
As for the script for apending an element to array, this answer may help you - Elasticsearch upserting and appending to array
However, do you really need to update the document? It might be easier to just reindex it as this is exactly what Elasticsearch does internally. It reads the "_source" property, does the required modification and reindexes it. BTW, this means that "_source" must be enabled and all properties of the document should be included into it.
You also may consider storing comments and authors (as I understand these are authors of comments, not the document authors) as child document in ES and using "has_child" filter.
I can't really give you specific solution, but strongly recommend installing Marvel plugin for ElasticSearch and use its "sense" tool to check how your overall process works step by step.
So check if your tokenizer is properly configured by running tests as described at http://www.elastic.co/guide/en/elasticsearch/reference/1.4/indices-analyze.html.
Then check if your update script is doing what you expect by retrieving the document by running GET /document/example_type/some_existing_id
The authors and comments should be arrays, but not strings.
Finally perform the search:
GET /document/_search
{
'query' : {
'match': { '_all': 'hel' }
}
}
If you're building the query yourself rather than getting it from the user, you may use query_string with placeholders:
GET /document/_search
{
'query' : {
'query_string': {
'fields': '_all',
'query': 'hel*'
}
}
}
I am working Amazon API integration.I am also send request and get response.But i need to sort/filter by color.I am using this code for get response value.
$request = aws_signed_request('com', array(
'Operation' => 'ItemSearch',
'Keywords' => $keywords,
"SearchIndex" => $search_index,
"MaximumPrice" => $highprice,
"MinimumPrice" => $lowprice,
"Color" => $color,
"Count" => '24',"Brand" => $brand,
"MerchantId" => $MerchantId,
'ResponseGroup' => 'Large,EditorialReview'), $public_key, $private_key, $associate_tag);
In that coding, i need to filtered by color in amazon products.How is it possible? please advice me..
According to the AWS docs, sorting by color is not currently supported
Edit: Neither is filtering by color