How to use a dictionary from JSON with Realm? - ios

Creating a data model to use with codable and realm. Im getting stuck on dictionaries. As I understand it, you cannot use dictionaries with realm? How can I decode the following JSON and use it with something Realm will accept?
JSON Example A
"platform": {
"data": {
"25": {
"id": 25,
"name": "3DO",
"alias": "3do"
},
"4944": {
"id": 4944,
"name": "Acorn Archimedes",
"alias": "acorn-archimedes"
},
"4954": {
"id": 4954,
"name": "Acorn Electron",
"alias": "acorn-electron"
}
}
Note, the keys are strings that change, in decoable form i have it as
StructExample A
struct PlatformData : Codable {
let data : [String: PlatformInformation]
}
JSON Example B
"include": {
"boxart": {
"base_url": {
"original": "https:\/\/cdn.thegamesdb.net\/images\/original\/",
"small": "https:\/\/cdn.thegamesdb.net\/images\/small\/",
"thumb": "https:\/\/cdn.thegamesdb.net\/images\/thumb\/",
"cropped_center_thumb": "https:\/\/cdn.thegamesdb.net\/images\/cropped_center_thumb\/",
"medium": "https:\/\/cdn.thegamesdb.net\/images\/medium\/",
"large": "https:\/\/cdn.thegamesdb.net\/images\/large\/"
},
"data": {
"1":
[
{
"id": 242,
"type": "fanart",
"side": null,
"filename": "fanart\/1-2.jpg",
"resolution": "1920x1080"
},
{
"id": 433,
"type": "fanart",
"side": null,
"filename": "fanart\/1-5.jpg",
"resolution": "1920x1080"
}
],
"2":
[
{
"id": 15,
"type": "fanart",
"side": null,
"filename": "fanart\/2-1.jpg",
"resolution": "1920x1080"
},
{
"id": 133,
"type": "fanart",
"side": null,
"filename": "fanart\/2-2.jpg",
"resolution": "1920x1080"
},
{
"id": 656,
"type": "fanart",
"side": null,
"filename": "fanart\/2-4.jpg",
"resolution": "1920x1080"
}
],
"4":
[
{
"id": 208,
"type": "fanart",
"side": null,
"filename": "fanart\/4-1.jpg",
"resolution": "1920x1080"
},
{
"id": 481,
"type": "banner",
"side": null,
"filename": "graphical\/4-g.jpg",
"resolution": null
},
{
"id": 846,
"type": "boxart",
"side": "front",
"filename": "boxart\/front\/4-1.jpg",
"resolution": "1000x705"
},
{
"id": 847,
"type": "boxart",
"side": "back",
"filename": "boxart\/back\/4-1.jpg",
"resolution": "1000x705"
},
{
"id": 73897,
"type": "clearlogo",
"side": null,
"filename": "clearlogo\/4.png",
"resolution": "400x148"
},
{
"id": 215539,
"type": "fanart",
"side": null,
"filename": "fanart\/4-2.jpg",
"resolution": null
},
{
"id": 238533,
"type": "screenshot",
"side": null,
"filename": "screenshot\/4-1.jpg",
"resolution": null
},
{
"id": 238534,
"type": "screenshot",
"side": null,
"filename": "screenshot\/4-2.jpg",
"resolution": null
},
{
"id": 238535,
"type": "screenshot",
"side": null,
"filename": "screenshot\/4-3.jpg",
"resolution": null
},
{
"id": 238536,
"type": "screenshot",
"side": null,
"filename": "screenshot\/4-4.jpg",
"resolution": null
},
{
"id": 238537,
"type": "screenshot",
"side": null,
"filename": "screenshot\/4-5.jpg",
"resolution": null
},
{
"id": 238538,
"type": "screenshot",
"side": null,
"filename": "screenshot\/4-6.jpg",
"resolution": null
}
],
"5":
[
{
"id": 396,
"type": "banner",
"side": null,
"filename": "graphical\/5-g.jpg",
"resolution": null
},
{
"id": 2364,
"type": "fanart",
"side": null,
"filename": "fanart\/5-4.jpg",
"resolution": "1920x1080"
},
]
Here is similar, except now with an array of objects as the value
Struct Example B
struct BoxArtData : Codeable {
let data: [String:[ExtraImages]]
}

Related

Correct format for decimal and timestamp-micros

I am trying to find the correct AVRO Schema format to define decimal and timestamp-micros logical types?
Whether NumericField1/ DateFieldA or NumericField2/DateFieldB is correct format for the Logical Type?
{
"type": "record",
"name": "DateAndNumber",
"namespace": "org.sample",
"fields": [
{
"name": "NumericField1",
"type": [
"null",
"bytes"
],
"default": null,
"locgicalType": "decimal",
"precision": 8,
"scale": 2
},
{
"name": "NumericField2",
"type": [
"null",
{
"type": "bytes",
"logicalType": "decimal",
"precision": 4,
"scale": 2
}
],
"default": null
},
{
"name": "DateFieldA",
"type": "long",
"logicalType": "timestamp-micros",
"default": 0
},
{
"name": "DateFieldB",
"type": {
"type": "long",
"logicalType": "timestamp-micros"
},
"default": 0
}
]
}

confluent_kafka.error.ValueSerializationError: KafkaError{code=_VALUE_SERIALIZATION,val=-161 : ValueError

I am new bee to python and trying to use 'confluent_kafka' for avro message produce.
Using 'confluent_kafka.schema_registry.avro.AvroSerializer' for the same
(referred : https://github.com/confluentinc/confluent-kafka-python/blob/master/examples/avro_producer.py)
It works for simple avro schema with dict(json converted to dict) input, but for below sample schema I am getting error :
Schema :
{
"type": "record",
"name": "Envelope",
"namespace": "CoreOLTPEvents.dbo.Event",
"fields": [{
"name": "before",
"type": ["null", {
"type": "record",
"name": "Value",
"fields": [{
"name": "EventId",
"type": "long"
}, {
"name": "CameraId",
"type": ["null", "long"],
"default": null
}],
"connect.name": "CoreOLTPEvents.dbo.Event.Value"
}],
"default": null
}, {
"name": "after",
"type": ["null", "Value"],
"default": null
}, {
"name": "source",
"type": {
"type": "record",
"name": "Source",
"namespace": "io.debezium.connector.sqlserver",
"fields": [{
"name": "version",
"type": "string"
}, {
"name": "connector",
"type": "string"
}],
"connect.name": "io.debezium.connector.sqlserver.Source"
}
}, {
"name": "op",
"type": "string"
}],
"connect.name": "CoreOLTPEvents.dbo.Event.Envelope"
}
Input Json :
{
"after": null,
"before": {
"CoreOLTPEvents.dbo.Event.Value" : {
"EventId": 1111111111,
"CameraId": 222222222
}
},
"source": {
"version": "InitialLoad",
"connector": "sqlserver"
},
"op": "C"
}
Error :
ValueError: {'CoreOLTPEvents.dbo.Event.Value': {'EventId': 1111111111, 'CameraId': 222222222}} (type <class 'dict'>) do not match ['null', {'connect.name': 'CoreOLTPEvents.dbo.Event.Value', 'type': 'record', 'name': 'CoreOLTPEvents.dbo.Event.Value', 'fields': [{'name': 'EventId', 'type': 'long'}, {'default': None, 'name': 'CameraId', 'type': ['null', 'long']}]}] on field before
'before' field type is union (['null',record]), if I change it to only record (remove union) then it works fine.
But I need to adjust my input such a way that it works for given schema.
(Note : I am reading json input using 'json.load(json_file)' so it gives dict output)
Any help would be much appreciated.
Update :
Actual large schema :
{
"type": "record",
"name": "Envelope",
"namespace": "CoreOLTPEvents.dbo.Event",
"fields": [{
"name": "before",
"type": ["null", {
"type": "record",
"name": "Value",
"fields": [{
"name": "EventId",
"type": "long"
}, {
"name": "CameraId",
"type": ["null", "long"],
"default": null
}, {
"name": "SiteId",
"type": ["null", "long"],
"default": null
}, {
"name": "VehicleId",
"type": ["null", "long"],
"default": null
}, {
"name": "EventReviewStatusID",
"type": "int"
}, {
"name": "EventTypeId",
"type": ["null", "int"],
"default": null
}, {
"name": "EventDateTime",
"type": ["null", {
"type": "string",
"connect.name": "net.smartdrive.converters.SmartdriveEventDateFieldConverter"
}],
"default": null
}, {
"name": "FTPUploadDateTime",
"type": {
"type": "long",
"connect.version": 1,
"connect.name": "io.debezium.time.Timestamp"
}
}, {
"name": "CAMFileName",
"type": "string"
}, {
"name": "KeypadEntryCode",
"type": ["null", "string"],
"default": null
}, {
"name": "IsActive",
"type": {
"type": "boolean",
"connect.default": true
},
"default": true
}, {
"name": "Flagged",
"type": "boolean"
}, {
"name": "EventTitle",
"type": ["null", "string"],
"default": null
}, {
"name": "CreatedBy",
"type": "long"
}, {
"name": "CreatedDate",
"type": {
"type": "long",
"connect.version": 1,
"connect.name": "io.debezium.time.Timestamp"
}
}, {
"name": "ModifiedBy",
"type": "long"
}, {
"name": "ModifiedDate",
"type": {
"type": "long",
"connect.version": 1,
"connect.name": "io.debezium.time.Timestamp"
}
}, {
"name": "ReReviewAnalysis",
"type": ["null", "string"],
"default": null
}, {
"name": "LegacyEventId",
"type": ["null", "long"],
"default": null
}, {
"name": "TripId",
"type": ["null", "long"],
"default": null
}, {
"name": "FileVersion",
"type": ["null", "string"],
"default": null
}, {
"name": "EventNumber",
"type": ["null", "string"],
"default": null
}, {
"name": "Latitude",
"type": ["null", {
"type": "bytes",
"scale": 10,
"precision": 13,
"connect.version": 1,
"connect.parameters": {
"scale": "10",
"connect.decimal.precision": "13"
},
"connect.name": "org.apache.kafka.connect.data.Decimal",
"logicalType": "decimal"
}],
"default": null
}, {
"name": "Longitude",
"type": ["null", {
"type": "bytes",
"scale": 10,
"precision": 13,
"connect.version": 1,
"connect.parameters": {
"scale": "10",
"connect.decimal.precision": "13"
},
"connect.name": "org.apache.kafka.connect.data.Decimal",
"logicalType": "decimal"
}],
"default": null
}, {
"name": "GeoAddressId",
"type": ["null", "long"],
"default": null
}, {
"name": "ReviewedEventId",
"type": ["null", "long"],
"default": null
}, {
"name": "VideoStatus",
"type": {
"type": "int",
"connect.default": 0
},
"default": 0
}, {
"name": "PredictionImportance",
"type": ["null", {
"type": "bytes",
"scale": 10,
"precision": 15,
"connect.version": 1,
"connect.parameters": {
"scale": "10",
"connect.decimal.precision": "15"
},
"connect.name": "org.apache.kafka.connect.data.Decimal",
"logicalType": "decimal"
}],
"default": null
}, {
"name": "FlaggedBy",
"type": ["null", "long"],
"default": null
}, {
"name": "FlaggedDate",
"type": ["null", {
"type": "long",
"connect.version": 1,
"connect.name": "io.debezium.time.Timestamp"
}],
"default": null
}, {
"name": "TriggerTypeId",
"type": ["null", "int"],
"default": null
}, {
"name": "VideoDeleteDate",
"type": ["null", {
"type": "long",
"connect.version": 1,
"connect.name": "io.debezium.time.Timestamp"
}],
"default": null
}, {
"name": "MetadataDeleteDate",
"type": ["null", {
"type": "long",
"connect.version": 1,
"connect.name": "io.debezium.time.Timestamp"
}],
"default": null
}, {
"name": "RetentionStatus",
"type": {
"type": "int",
"connect.default": 0,
"connect.type": "int16"
},
"default": 0
}, {
"name": "PartnerTriggerId",
"type": ["null", "int"],
"default": null
}, {
"name": "CoachingStateId",
"type": {
"type": "int",
"connect.default": 0,
"connect.type": "int16"
},
"default": 0
}, {
"name": "EventKudoHistoryId",
"type": ["null", "int"],
"default": null
}],
"connect.name": "CoreOLTPEvents.dbo.Event.Value"
}],
"default": null
}, {
"name": "after",
"type": ["null", "Value"],
"default": null
}, {
"name": "source",
"type": {
"type": "record",
"name": "Source",
"namespace": "io.debezium.connector.sqlserver",
"fields": [{
"name": "version",
"type": "string"
}, {
"name": "connector",
"type": "string"
}, {
"name": "name",
"type": "string"
}, {
"name": "ts_ms",
"type": "long"
}, {
"name": "snapshot",
"type": [{
"type": "string",
"connect.version": 1,
"connect.parameters": {
"allowed": "true,last,false"
},
"connect.default": "false",
"connect.name": "io.debezium.data.Enum"
}, "null"],
"default": "false"
}, {
"name": "db",
"type": "string"
}, {
"name": "schema",
"type": "string"
}, {
"name": "table",
"type": "string"
}, {
"name": "change_lsn",
"type": ["null", "string"],
"default": null
}, {
"name": "commit_lsn",
"type": ["null", "string"],
"default": null
}, {
"name": "event_serial_no",
"type": ["null", "long"],
"default": null
}],
"connect.name": "io.debezium.connector.sqlserver.Source"
}
}, {
"name": "op",
"type": "string"
}, {
"name": "ts_ms",
"type": ["null", "long"],
"default": null
}, {
"name": "transaction",
"type": ["null", {
"type": "record",
"name": "ConnectDefault",
"namespace": "io.confluent.connect.avro",
"fields": [{
"name": "id",
"type": "string"
}, {
"name": "total_order",
"type": "long"
}, {
"name": "data_collection_order",
"type": "long"
}]
}],
"default": null
}],
"connect.name": "CoreOLTPEvents.dbo.Event.Envelope"
}
Input for large schema :
{
"before": null,
"after": {
"EventId": 1234566,
"CameraId": 2233,
"SiteId": 111,
"VehicleId": 45587,
"EventReviewStatusID": 10,
"EventTypeId": 123,
"EventDateTime": "2015-01-02T01:30:29Z",
"FTPUploadDateTime": 1420193330590,
"CAMFileName": "XYZ",
"KeypadEntryCode": "0",
"IsActive": false,
"Flagged": false,
"EventTitle": null,
"CreatedBy": 1,
"CreatedDate": 1420191120730,
"ModifiedBy": 1,
"ModifiedDate": 1577871185680,
"ReReviewAnalysis": null,
"LegacyEventId": null,
"TripId": 3382,
"FileVersion": "2.2",
"EventNumber": "AAAA-BBBB",
"Latitude": "UU9elrA=",
"Longitude": "/ueZUeFw",
"GeoAddressId": null,
"ReviewedEventId": 129411077,
"VideoStatus": 4,
"PredictionImportance": 0.1402457539,
"FlaggedBy": null,
"FlaggedDate": null,
"TriggerTypeId": 322,
"VideoDeleteDate": 1422783120000,
"MetadataDeleteDate": 1577871120000,
"RetentionStatus": 15,
"PartnerTriggerId": null,
"CoachingStateId": 0,
"EventKudoHistoryId": null
},
"source": {
"version": "Final",
"connector": "sqlserver",
"name": "CoreOLTP",
"ts_ms": 1615813992548,
"snapshot": "false",
"db": "CoreOLTP",
"schema": "dbo",
"table": "xyz",
"change_lsn": null,
"commit_lsn": null,
"event_serial_no": null
},
"op": "C",
"ts_ms": 1615813992548,
"transaction": null
}
Error :
confluent_kafka.error.ValueSerializationError: KafkaError{code=_VALUE_SERIALIZATION,val=-161,str="{'EventId': 129411077, 'CameraId': 46237, 'SiteId': 2148, 'VehicleId': 45587, 'EventReviewStatusID': 10, 'EventTypeId': 247, 'EventDateTime': '2015-01-02T01:30:29Z', 'FTPUploadDateTime': 1420191120590, 'CAMFileName': 'JD2BC02120150102013029ER.SDE', 'KeypadEntryCode': '0', 'IsActive': False, 'Flagged': False, 'EventTitle': None, 'CreatedBy': 1, 'CreatedDate': 1420191120730, 'ModifiedBy': 1, 'ModifiedDate': 1577871185680, 'ReReviewAnalysis': None, 'LegacyEventId': None, 'TripId': 3382, 'FileVersion': '2.2', 'EventNumber': 'WSHX-8QQ2', 'Latitude': 'UU9elrA=', 'Longitude': '/ueZUeFw', 'GeoAddressId': None, 'ReviewedEventId': 129411077, 'VideoStatus': 4, 'PredictionImportance': 0.1402457539, 'FlaggedBy': None, 'FlaggedDate': None, 'TriggerTypeId': 322, 'VideoDeleteDate': 1422783120000, 'MetadataDeleteDate': 1577871120000, 'RetentionStatus': 15, 'PartnerTriggerId': None, 'CoachingStateId': 0, 'EventKudoHistoryId': None} (type <class 'dict'>) do not match ['null', 'CoreOLTPEvents.dbo.Event.Value'] on field after"}
You just need to change your input so that the before field doesn't have the namespace. So it needs to look like this:
{
"after": null,
"before": {
"EventId": 1111111111,
"CameraId": 222222222
},
"source": {
"version": "InitialLoad",
"connector": "sqlserver"
},
"op": "C"
}
The original input you had looked like it was trying to be JSON encoded avro because the field before had the CoreOLTPEvents.dbo.Event.Value namespace. However, I'm guessing it must have been hand crafted because CameraId should have been specified as {"long": 222222222} rather than just 222222222.
If you do actually have Avro encoded JSON (from the result of some other process or something) then you you could use something like fastavro.json_reader to read in that file and it will create the correct memory representation (that doesn't include the type information for union fields).
UPDATE:
To figure out what the problem is with the full schema and full data, I first loaded the two objects using json.load and then used fastavro.validate(record, schema) The output from that is a stacktrace that ends with this:
fastavro._validate_common.ValidationError: [
"CoreOLTPEvents.dbo.Event.Envelope.after is <{'EventId': 1234566, 'CameraId': 2233, 'SiteId': 111, 'VehicleId': 45587, 'EventReviewStatusID': 10, 'EventTypeId': 123, 'EventDateTime': '2015-01-02T01:30:29Z', 'FTPUploadDateTime': 1420193330590, 'CAMFileName': 'XYZ', 'KeypadEntryCode': '0', 'IsActive': False, 'Flagged': False, 'EventTitle': None, 'CreatedBy': 1, 'CreatedDate': 1420191120730, 'ModifiedBy': 1, 'ModifiedDate': 1577871185680, 'ReReviewAnalysis': None, 'LegacyEventId': None, 'TripId': 3382, 'FileVersion': '2.2', 'EventNumber': 'AAAA-BBBB', 'Latitude': 'UU9elrA=', 'Longitude': '/ueZUeFw', 'GeoAddressId': None, 'ReviewedEventId': 129411077, 'VideoStatus': 4, 'PredictionImportance': 0.1402457539, 'FlaggedBy': None, 'FlaggedDate': None, 'TriggerTypeId': 322, 'VideoDeleteDate': 1422783120000, 'MetadataDeleteDate': 1577871120000, 'RetentionStatus': 15, 'PartnerTriggerId': None, 'CoachingStateId': 0, 'EventKudoHistoryId': None}> of type <class 'dict'> expected null",
"CoreOLTPEvents.dbo.Event.Value.Latitude is <UU9elrA=> of type <class 'str'> expected null",
"CoreOLTPEvents.dbo.Event.Value.Latitude is <UU9elrA=> of type <class 'str'> expected {'scale': 10, 'precision': 13, 'connect.version': 1, 'connect.parameters': {'scale': '10', 'connect.decimal.precision': '13'}, 'connect.name': 'org.apache.kafka.connect.data.Decimal', 'logicalType': 'decimal', 'type': 'bytes'}"
]
So that is trying to tell us that there is 3 potential problems. The first is that the value in after doesn't match null, but we can ignore that because we don't want after to match null.
The later two problems are the actual problem. It says that the value of Latitude is the string UU9elrA=, but that doesn't match either null or bytes. The string here looks base64 encoded, so maybe you have some code that decodes that to bytes and if so then maybe the actual problem is something else, but if so then I think you should be able to use fastavro.validate to figure out what the problem is.

Pull Request Lists and the set of approvers from BITBUCKET SERVER API

Is it possible to get the List of all pull request with the details like the date when it was raised, the Person who raised it and the list of all the approvers from the BITBUCKET SERVER using the REST APIs
Absolutely, You can fetch the list of Pull requests along with all the other details like who raised it, when it was raised and who are the reviewers using the following API,
https://docs.atlassian.com/bitbucket-server/rest/7.4.0/bitbucket-rest.html#idp285
You will have the following as response,
{
"size": 1,
"limit": 25,
"isLastPage": true,
"values": [
{
"id": 101,
"version": 1,
"title": "Talking Nerdy",
"description": "It’s a kludge, but put the tuple from the database in the cache.",
"state": "OPEN",
"open": true,
"closed": false,
"createdDate": 1359075920,
"updatedDate": 1359085920,
"fromRef": {
"id": "refs/heads/feature-ABC-123",
"repository": {
"slug": "my-repo",
"name": null,
"project": {
"key": "PRJ"
}
}
},
"toRef": {
"id": "refs/heads/master",
"repository": {
"slug": "my-repo",
"name": null,
"project": {
"key": "PRJ"
}
}
},
"locked": false,
"author": {
"user": {
"name": "tom",
"emailAddress": "tom#example.com",
"id": 115026,
"displayName": "Tom",
"active": true,
"slug": "tom",
"type": "NORMAL"
},
"role": "AUTHOR",
"approved": true,
"status": "APPROVED"
},
"reviewers": [
{
"user": {
"name": "jcitizen",
"emailAddress": "jane#example.com",
"id": 101,
"displayName": "Jane Citizen",
"active": true,
"slug": "jcitizen",
"type": "NORMAL"
},
"lastReviewedCommit": "7549846524f8aed2bd1c0249993ae1bf9d3c9998",
"role": "REVIEWER",
"approved": true,
"status": "APPROVED"
}
],
"participants": [
{
"user": {
"name": "dick",
"emailAddress": "dick#example.com",
"id": 3083181,
"displayName": "Dick",
"active": true,
"slug": "dick",
"type": "NORMAL"
},
"role": "PARTICIPANT",
"approved": false,
"status": "UNAPPROVED"
},
{
"user": {
"name": "harry",
"emailAddress": "harry#example.com",
"id": 99049120,
"displayName": "Harry",
"active": true,
"slug": "harry",
"type": "NORMAL"
},
"role": "PARTICIPANT",
"approved": true,
"status": "APPROVED"
}
],
"links": {
"self": [
{
"href": "http://link/to/pullrequest"
}
]
}
}
],
"start": 0 }

Is it possible to combine jsPDF and Autotable plugin?

Is it possible to use jsPDF to grab text from a HTML page and jsPDF-autotable to grab the table and to get that all inside one PDF? I have a document which has some content, and tables in the middle of the content. However, I was not able to print that document.
Sample code:
Sample code:enter code here
In the below code I am looping my Content array. Content can be of different types. For the table content am trying to use pdf.autoTable and for the text content am using pdf.text
var pdf = new jspdf('p', 'pt', 'a4');
pdf.setFontSize(18);
pdf.line(20, 25, 25, 25);
for (let i = 0; i < this.dalSectionsArray.length; i++) {
dynamicHtmlSource = dynamicHtmlSource + '<p style="text-align:left;">
<b>' + this.dalSectionsArray[i].title + '</b></p><b/>';
pdf.text(dynamicHtmlSource, 10+i, 10+i);
for (let j = 0; j < this.dalContentsArray.length; j++) {
if (this.dalSectionsArray[i].id ===
this.dalContentsArray[j].sectionView.id) {
if (this.dalContentsArray[j].subType === 'Clause') {
dynamicHtmlSource = this.getClauseData(this.dalContentsArray[j]);
pdf.text(dynamicHtmlSource,20+j,20+j);
} else if (this.dalContentsArray[j].subType === 'Block') {
dynamicHtmlSource = this.getBlockData(this.dalContentsArray[j]);
pdf.text(dynamicHtmlSource,30+j,30+j);
} else if (this.dalContentsArray[j].subType === 'Restriction') {
dynamicHtmlSource =
this.getRestrictionData(this.dalContentsArray[j]);
pdf.text(dynamicHtmlSource, 40+j, 40+j);
} else if (this.dalContentsArray[j].subType === 'Table') {
pdf.autoTable({
startY:50+j,
columnStyles: { europe: { halign: 'center' } }, // European
countries centered
body: this.dalContentsArray[j].tableValues,
columns: this.dalContentsArray[j].displayColumns
})
}
}
pdf.fromHTML('',
this.margins.left, // x coord
this.margins.top,
{
// y coord
width: this.margins.width// max width of content on PDF
}, (dispose) => {
this.headerFooterFormatting(pdf, pdf.internal.getNumberOfPages());
},
this.margins);
var iframe = document.createElement('iframe');
iframe.setAttribute('style', 'position:absolute;right:0; top:0;
bottom:0; height:100%; width:650px; padding:20px;');
document.body.appendChild(iframe);
pdf.setProperties({
title: 'jspdf-iframe',
subject: 'DAL Content',
author: 'PDFAuthor',
keywords: 'generated, javascript, web 2.0, ajax',
creator: 'ABC'
});
iframe.src = pdf.output('datauristring');
Issue is the pdf is completely messed and not printed properly. Can any
one help me in this regard.
Sample JSON:
{
"dalId": "{QQ-4b3544ef-3821-439c-84cf-b6f18c9a86fc-uw}-{1}",
"sections": [
{
"title": "ABC",
"description": "",
"order": "1",
"status": "Active",
"startDate": "2018-12-12T00:00:00",
"endDate": null,
"id": "{b3cdda34-1fd2-4463-9aa0-24beff4b83fe}-{1}",
"_etag": "\"0d0006a2-0000-0c00-0000-5c94e5760000\"",
"partitionKey": "GGG-Section-{b3cdda34-1fd2-4463-9aa0-24beff4b83fe}-{1}",
"type": "Section",
"clientId": "GGG",
"createdBy": "FFFFF",
"createdDate": "2018-11-12T00:00:00",
"modifiedBy": "FFFFF",
"modifiedDate": "2018-11-12T00:00:00",
"isactive": false
},
{
"title": "DEF",
"description": "",
"order": "2",
"status": "Active",
"startDate": "2018-12-12T00:00:00",
"endDate": null,
"id": "{fca09906-dff9-40b2-a971-28fef7f37dbf}-{1}",
"_etag": "\"0d0004a2-0000-0c00-0000-5c94e5760000\"",
"partitionKey": "GGG-Section-{fca09906-dff9-40b2-a971-28fef7f37dbf}-{1}",
"type": "Section",
"clientId": "GGG",
"createdBy": "FFFFF",
"createdDate": "2018-11-12T00:00:00",
"modifiedBy": "FFFFF",
"modifiedDate": "2018-11-12T00:00:00",
"isactive": false
},
{
"title": "GHI",
"description": "",
"order": "3",
"status": "Active",
"startDate": "2018-12-12T00:00:00",
"endDate": null,
"id": "{9cfb60cf-354c-4194-9e2e-6bab41c6b280}-{1}",
"_etag": "\"0d00faa1-0000-0c00-0000-5c94e5750000\"",
"partitionKey": "GGG-Section-{9cfb60cf-354c-4194-9e2e-6bab41c6b280}-{1}",
"type": "Section",
"clientId": "GGG",
"createdBy": "FFFFF",
"createdDate": "2018-11-12T00:00:00",
"modifiedBy": "FFFFF",
"modifiedDate": "2018-11-12T00:00:00",
"isactive": false
}
],
"contents": [
{
"dalId": "{QQ-4b3544ef-3821-439c-84cf-b6f18c9a86fc-uw}-{1}",
"baseDataid": "{a351366f-bf4b-44e0-94ff-a81be899ec3a}-{1}",
"subType": "Table",
"sectionView": {
"id": "{9cfb60cf-354c-4194-9e2e-6bab41c6b280}-{1}",
"title": "AAA",
"description": "",
"order": "4"
},
"title": "PL",
"description": "",
"order": "3",
"status": "Active",
"startDate": "2018-12-12T00:00:00",
"endDate": null,
"displayColumns": [ "N", "M", "O", "P" ],
"tableValues": [
{
"N": "Level 21",
"M": "22",
"O": "",
"P": "",
"isRowEditable": false
},
{
"id": "6cb79b9f-2ef2-4d3a-b6c4-7d84dd61aaf7",
"isDeleted": true,
"N": "KKKKKKK",
"M": "GBP 20M",
"O": "",
"isRowEditable": false
},
{
"id": "c83caf0b-8f00-4dc8-bf35-473bda398937",
"isDeleted": true,
"N": "EP",
"M": "GBP 15M",
"O": "",
"isRowEditable": false
}
],
"placeHolderValues": "",
"organizationDataView": [
{
"id": "{8b958d63-d605-4b9a-a3c4-a3c1c052316e}-{1}",
"orgGroupName": "QQ",
"orgGroupType": "DD",
"orgLevel": 1,
"orgParentGroupId": ""
}
],
"id": "{16a3fb1e-f7fa-4dfe-a4d3-c51b56c8dbee-uw}-{1}",
"_etag": "\"0d00a0ca-0000-0c00-0000-5c94ef3f0000\"",
"partitionKey": "GGG-CCCCOOOOO-{16a3fb1e-f7fa-4dfe-a4d3-c51b56c8dbee-uw}-{1}",
"type": "CCCCOOOOO",
"clientId": "GGG",
"createdBy": "MM",
"createdDate": "2018-12-12T00:00:00",
"modifiedBy": "PPP",
"modifiedDate": null,
"isactive": false
},
{
"dalId": "{QQ-4b3544ef-3821-439c-84cf-b6f18c9a86fc-uw}-{1}",
"baseDataid": "{2b498850-8f11-475d-b170-5705d05c4bf1}-{1}",
"subType": "Clause",
"sectionView": {
"id": "{b3cdda34-1fd2-4463-9aa0-24beff4b83fe}-{1}",
"title": "LLL",
"description": "",
"order": "3"
},
"title": "kkkkk",
"Description": [
{
"type": "label",
"value": "<br/>Some sample text here"
}
],
"order": "6",
"status": "Active",
"startDate": "2018-12-12T00:00:00",
"endDate": null,
"displayColumns": [],
"tableValues": null,
"placeHolderValues": "",
"organizationDataView": [
{
"id": "{8b958d63-d605-4b9a-a3c4-a3c1c052316e}-{1}",
"orgGroupName": "QQ",
"orgGroupType": "DD",
"orgLevel": 1,
"orgParentGroupId": ""
}
],
"id": "{6193cef1-2fe5-47c2-8367-0650ab66caf3-uw}-{1}",
"_etag": "\"0d00a5ca-0000-0c00-0000-5c94ef400000\"",
"partitionKey": "GGG-CCCCOOOOO-{6193cef1-2fe5-47c2-8367-0650ab66caf3-uw}-{1}",
"type": "CCCCOOOOO",
"clientId": "GGG",
"createdBy": "MM",
"createdDate": "2018-12-12T00:00:00",
"modifiedBy": "PPP",
"modifiedDate": null,
"isactive": false
},
{
"dalId": "{QQ-4b3544ef-3821-439c-84cf-b6f18c9a86fc-uw}-{1}",
"baseDataid": "{d6793120-5e5b-40ec-a1ea-e82e7bdc9d1a}-{1}",
"subType": "Clause",
"sectionView": {
"id": "{9cfb60cf-354c-4194-9e2e-6bab41c6b280}-{1}",
"title": "UT",
"description": "Sample Text",
"order": "4"
},
"title": "PR",
"Description": [
{
"type": "label",
"value": "Sample"
},
{
"type": "dropDown",
"value": "USD",
"options": [ "USD", "INR", "Dollar" ]
},
{
"type": "text",
"value": "50"
},
{
"type": "label",
"value": "Sample "
},
{
"type": "dropDown",
"value": "USD",
"options": [ "USD", "INR", "Dollar" ]
},
{
"type": "text",
"value": "50"
},
{
"type": "label",
"value": "Sample"
},
{
"type": "dropDown",
"value": "USD",
"options": [ "USD", "INR", "Dollar" ]
},
{
"type": "text",
"value": "50"
},
{
"type": "label",
"value": "Sample "
},
{
"type": "dropDown",
"value": "USD",
"options": [ "USD", "INR", "Dollar" ]
},
{
"type": "text",
"value": "50"
},
{
"type": "label",
"value": "Sample"
},
{
"type": "dropDown",
"value": "USD",
"options": [ "USD", "INR", "Dollar" ]
},
{
"type": "text",
"value": "50"
},
{
"type": "label",
"value": "any one programme/risk</li><li>a maximum premium of "
},
{
"type": "dropDown",
"value": "USD",
"options": [ "USD", "INR", "Dollar" ]
},
{
"type": "text",
"value": "50"
},
{
"type": "label",
"value": "Sample"
},
{
"type": "dropDown",
"value": "USD",
"options": [ "USD", "INR", "Dollar" ]
},
{
"type": "text",
"value": "50"
},
{
"type": "label",
"value": "<br/>SSample"
},
{
"type": "dropDown",
"value": "USD",
"options": [ "USD", "INR", "Dollar" ]
},
{
"type": "text",
"value": "50"
},
{
"type": "label",
"value": "Sample"
},
{
"type": "dropDown",
"value": "USD",
"options": [ "USD", "INR", "Dollar" ]
},
{
"type": "text",
"value": "50"
},
{
"type": "label",
"value": ".Sample"
},
{
"type": "dropDown",
"value": "USD",
"options": [ "USD", "INR", "Dollar" ]
},
{
"type": "text",
"value": "50"
},
{
"type": "label",
"value": ", on Lloyd's paper, in respect of Canadian domiciled Property risks<br/>Your authority for Health extends to unlimited Healthcare where required by statute<br/>You may accept up to "
},
{
"type": "dropDown",
"value": "USD",
"options": [ "USD", "INR", "Dollar" ]
},
{
"type": "text",
"value": "50"
},
{
"type": "label",
"value": ", on Lloyd's paper, in respect of declarations under the Coast P&I Facility<br/>You may accept up to "
},
{
"type": "dropDown",
"value": "USD",
"options": [ "USD", "INR", "Dollar" ]
},
{
"type": "text",
"value": "50"
},
{
"type": "label",
"value": ", on Lloyd's paper, in respect of combined primary and excess grounding liability<br/>"
}
],
"order": "6",
"status": "Active",
"startDate": "2018-12-12T00:00:00",
"endDate": null,
"displayColumns": [],
"tableValues": null,
"placeHolderValues": "",
"organizationDataView": [
{
"id": "{8b958d63-d605-4b9a-a3c4-a3c1c052316e}-{1}",
"orgGroupName": "QQ",
"orgGroupType": "DD",
"orgLevel": 1,
"orgParentGroupId": ""
}
],
"id": "{22505164-4d56-493e-8df2-b1bb53ab419a-uw}-{1}",
"_etag": "\"0d00acca-0000-0c00-0000-5c94ef400000\"",
"partitionKey": "GGG-CCCCOOOOO-{22505164-4d56-493e-8df2-b1bb53ab419a-uw}-{1}",
"type": "CCCCOOOOO",
"clientId": "GGG",
"createdBy": "MM",
"createdDate": "2018-12-12T00:00:00",
"modifiedBy": "PPP",
"modifiedDate": null,
"isactive": false
},
{
"dalId": "{QQ-4b3544ef-3821-439c-84cf-b6f18c9a86fc-uw}-{1}",
"baseDataid": "{ac949799-60c7-4f85-840f-f30203c5ee43}-{1}",
"subType": "Block",
"sectionView": {
"id": "{fca09906-dff9-40b2-a971-28fef7f37dbf}-{1}",
"title": "GR",
"description": "",
"order": "2"
},
"title": "",
"description": "Sample",
"order": "1",
"status": "Active",
"startDate": "2018-12-12T00:00:00",
"endDate": null,
"displayColumns": [],
"tableValues": null,
"placeHolderValues": "",
"organizationDataView": [
{
"id": "{8b958d63-d605-4b9a-a3c4-a3c1c052316e}-{1}",
"orgGroupName": "QQ",
"orgGroupType": "DD",
"orgLevel": 1,
"orgParentGroupId": ""
}
],
"id": "{8652fedc-0d7c-48d8-bc3f-577294551671-uw}-{1}",
"_etag": "\"0d00baca-0000-0c00-0000-5c94ef400000\"",
"partitionKey": "GGG-CCCCOOOOO-{8652fedc-0d7c-48d8-bc3f-577294551671-uw}-{1}",
"type": "CCCCOOOOO",
"clientId": "GGG",
"createdBy": "MM",
"createdDate": "2018-12-12T00:00:00",
"modifiedBy": "PPP",
"modifiedDate": null,
"isactive": false
},
{
"dalId": "{QQ-4b3544ef-3821-439c-84cf-b6f18c9a86fc-uw}-{1}",
"baseDataid": "{522f1248-0882-4348-9bba-59c056c816c8}-{1}",
"subType": "Clause",
"sectionView": {
"id": "{b3cdda34-1fd2-4463-9aa0-24beff4b83fe}-{1}",
"title": "LLL",
"description": "",
"order": "3"
},
"title": "UP",
"Description": [
{
"type": "label",
"value": "Sample"
}
],
"order": "1",
"status": "Active",
"startDate": "2018-12-12T00:00:00",
"endDate": null,
"displayColumns": [],
"tableValues": null,
"placeHolderValues": "",
"organizationDataView": [
{
"id": "{8b958d63-d605-4b9a-a3c4-a3c1c052316e}-{1}",
"orgGroupName": "QQ",
"orgGroupType": "DD",
"orgLevel": 1,
"orgParentGroupId": ""
}
],
"id": "{944eae3d-fa0f-4b0e-9c66-3499a16fc2fd-uw}-{1}",
"_etag": "\"0d00bfca-0000-0c00-0000-5c94ef400000\"",
"partitionKey": "GGG-CCCCOOOOO-{944eae3d-fa0f-4b0e-9c66-3499a16fc2fd-uw}-{1}",
"type": "CCCCOOOOO",
"clientId": "GGG",
"createdBy": "MM",
"createdDate": "2018-12-12T00:00:00",
"modifiedBy": "PPP",
"modifiedDate": null,
"isactive": false
},
{
"dalId": "{QQ-4b3544ef-3821-439c-84cf-b6f18c9a86fc-uw}-{1}",
"baseDataid": "{6c6a3c80-3536-4c51-8ccf-fcdc16d94090}-{1}",
"subType": "Table",
"sectionView": {
"id": "{9cfb60cf-354c-4194-9e2e-6bab41c6b280}-{1}",
"title": "KKPKPKPK",
"description": "",
"order": "4"
},
"title": "PT",
"description": "",
"order": "4",
"status": "Active",
"startDate": "2018-12-12T00:00:00",
"endDate": null,
"displayColumns": [ ".", "KKKKKKK", "EP", "P" ],
"tableValues": [
{
".": "Level 11",
"KKKKKKK": "",
"EP": "Level 21",
"P": "",
"isRowEditable": false
},
{
".": "Asbestos - other than licensed removers",
"KKKKKKK": "GBP 5M",
"EP": ".",
"isRowEditable": false
},
{
".": "Auto manufacturing - safety critical components",
"KKKKKKK": "GBP 10M",
"EP": ".",
"isRowEditable": false
},
{
".": "Rail - contracting companies",
"KKKKKKK": "GBP 5M",
"EP": ".",
"isRowEditable": false
},
{
".": "Asbestos - other than licensed removers",
"KKKKKKK": ".",
"EP": "GBP 10M",
"isRowEditable": false
},
{
".": "Rail - contracting companies",
"KKKKKKK": ".",
"EP": "GBP 10M",
"isRowEditable": false
}
],
"placeHolderValues": "",
"organizationDataView": [
{
"id": "{8b958d63-d605-4b9a-a3c4-a3c1c052316e}-{1}",
"orgGroupName": "QQ",
"orgGroupType": "DD",
"orgLevel": 1,
"orgParentGroupId": "."
}
],
"id": "{91de8a0b-4156-4121-be05-844b03928c29-uw}-{1}",
"_etag": "\"0d00c5ca-0000-0c00-0000-5c94ef410000\"",
"partitionKey": "GGG-CCCCOOOOO-{91de8a0b-4156-4121-be05-844b03928c29-uw}-{1}",
"type": "CCCCOOOOO",
"clientId": "GGG",
"createdBy": "MM",
"createdDate": "2018-12-12T00:00:00",
"modifiedBy": "PPP",
"modifiedDate": null,
"isactive": false
},
{
"dalId": "{QQ-4b3544ef-3821-439c-84cf-b6f18c9a86fc-uw}-{1}",
"baseDataid": "{92860693-e038-4a58-814c-6a74d59e7cce}-{1}",
"subType": "Clause",
"sectionView": {
"id": "{9cfb60cf-354c-4194-9e2e-6bab41c6b280}-{1}",
"title": "KKPKPKPK",
"description": "",
"order": "4"
},
"title": "",
"Description": [
{
"type": "label",
"value": "Sample"
}
],
"order": "9",
"status": "Active",
"startDate": "2018-12-12T00:00:00",
"endDate": null,
"displayColumns": [],
"tableValues": null,
"placeHolderValues": "",
"organizationDataView": [
{
"id": "{8b958d63-d605-4b9a-a3c4-a3c1c052316e}-{1}",
"orgGroupName": "QQ",
"orgGroupType": "DD",
"orgLevel": 1,
"orgParentGroupId": ""
}
],
"id": "{af17341e-a88c-4564-8296-c513e3708af2-uw-per}-{1}",
"_etag": "\"0d00e3ca-0000-0c00-0000-5c94ef420000\"",
"partitionKey": "GGG-CCCCOOOOO-{af17341e-a88c-4564-8296-c513e3708af2-uw-per}-{1}",
"type": "CCCCOOOOO",
"clientId": "GGG",
"createdBy": "MM",
"createdDate": "2018-12-12T00:00:00",
"modifiedBy": "PPP",
"modifiedDate": null,
"isactive": false
},
{
"dalId": "{QQ-4b3544ef-3821-439c-84cf-b6f18c9a86fc-uw}-{1}",
"baseDataid": "{92860693-e038-4a58-814c-6a74d59e7cce}-{1}",
"subType": "Clause",
"sectionView": {
"id": "{9cfb60cf-354c-4194-9e2e-6bab41c6b280}-{1}",
"title": "KKPKPKPK",
"description": "",
"order": "4"
},
"title": "PL",
"Description": [
{
"type": "label",
"value": "Sample"
}
],
"order": "7",
"status": "Active",
"startDate": "2018-12-12T00:00:00",
"endDate": null,
"displayColumns": [],
"tableValues": null,
"placeHolderValues": "",
"organizationDataView": [
{
"id": "{8b958d63-d605-4b9a-a3c4-a3c1c052316e}-{1}",
"orgGroupName": "QQ",
"orgGroupType": "DD",
"orgLevel": 1,
"orgParentGroupId": ""
}
],
"id": "{af17341e-a88c-4564-8296-c513e3708af2-uw}-{1}",
"_etag": "\"0d00e8ca-0000-0c00-0000-5c94ef420000\"",
"partitionKey": "GGG-CCCCOOOOO-{af17341e-a88c-4564-8296-c513e3708af2-uw}-{1}",
"type": "CCCCOOOOO",
"clientId": "GGG",
"createdBy": "MM",
"createdDate": "2018-12-12T00:00:00",
"modifiedBy": "PPP",
"modifiedDate": null,
"isactive": false
},
{
"dalId": "{QQ-4b3544ef-3821-439c-84cf-b6f18c9a86fc-uw}-{1}",
"baseDataid": "{92c5bd05-c8a2-45c1-a1e9-fd3f78c705ab}-{1}",
"subType": "Table",
"sectionView": {
"id": "{9cfb60cf-354c-4194-9e2e-6bab41c6b280}-{1}",
"title": "KKPKPKPK",
"description": "",
"order": "4"
},
"title": "KKPKPKPK PP",
"description": "",
"order": "1",
"status": "Active",
"startDate": "2018-12-12T00:00:00",
"endDate": null,
"displayColumns": [ "N", "kkk", "LPLPLPL", "Ccy", "M", "LTLT", "P" ],
"tableValues": [
{
"N": "Level 11",
"kkk": "",
"LPLPLPL": "",
"Ccy": "",
"M": "",
"LTLT": "",
"P": "",
"isRowEditable": false
},
{
"N": "Level 11",
"kkk": "",
"LPLPLPL": "",
"Ccy": "",
"M": "11",
"LTLT": "",
"P": "",
"isRowEditable": false
},
{
"N": "QQQl",
"kkk": "QQQQ",
"LPLPLPL": "DDDD",
"Ccy": "GBP",
"M": "10M",
"LTLT": "Any one vessel",
"isRowEditable": false
},
{
"N": "Marine Cargo",
"kkk": "QIEL",
"LPLPLPL": "Lineslip and other non-coverholder facilities",
"Ccy": "GBP",
"M": "5M",
"LTLT": "Any one event",
"isRowEditable": false
},
{
"N": "KKKK",
"kkk": "PPPP",
"LPLPLPL": "DDDD",
"Ccy": "GBP",
"M": "20M",
"LTLT": "Any one vessel",
"isRowEditable": false
}
],
"placeHolderValues": "",
"organizationDataView": [
{
"id": "{8b958d63-d605-4b9a-a3c4-a3c1c052316e}-{1}",
"orgGroupName": "QQ",
"orgGroupType": "DD",
"orgLevel": 1,
"orgParentGroupId": ""
}
],
"id": "{d036bc60-db2d-4c93-86ff-981a62e207ca-uw}-{1}",
"_etag": "\"0d00eacb-0000-0c00-0000-5c94ef530000\"",
"partitionKey": "GGG-CCCCOOOOO-{d036bc60-db2d-4c93-86ff-981a62e207ca-uw}-{1}",
"type": "CCCCOOOOO",
"clientId": "GGG",
"createdBy": "MM",
"createdDate": "2018-12-12T00:00:00",
"modifiedBy": "PPP",
"modifiedDate": null,
"isactive": false
},
{
"dalId": "{QQ-4b3544ef-3821-439c-84cf-b6f18c9a86fc-uw}-{1}",
"baseDataid": "{bf1f6e82-6afd-4837-81ab-acabc665da14}-{1}",
"subType": "Clause",
"sectionView": {
"id": "{b3cdda34-1fd2-4463-9aa0-24beff4b83fe}-{1}",
"title": "LLL",
"description": "",
"order": "3"
},
"title": "klklkl",
"Description": [
{
"type": "label",
"value": "sAMPLE tEXT"
}
],
"order": "4",
"status": "Active",
"startDate": "2018-12-12T00:00:00",
"endDate": null,
"displayColumns": [],
"tableValues": null,
"placeHolderValues": "",
"organizationDataView": [
{
"id": "{8b958d63-d605-4b9a-a3c4-a3c1c052316e}-{1}",
"orgGroupName": "QQ",
"orgGroupType": "DD",
"orgLevel": 1,
"orgParentGroupId": ""
}
],
"id": "{QQ-851f96e7-542f-4a57-a0b1-35feb4698f5e-uw}-{1}",
"_etag": "\"0d0062cc-0000-0c00-0000-5c94ef5a0000\"",
"partitionKey": "GGG-CCCCOOOOO-{QQ-851f96e7-542f-4a57-a0b1-35feb4698f5e-uw}-{1}",
"type": "CCCCOOOOO",
"clientId": "GGG",
"createdBy": "MM",
"createdDate": "2018-12-12T00:00:00",
"modifiedBy": "PPP",
"modifiedDate": null,
"isactive": false
}
]
}
getClauseData(dalContentdata) {
let dynamicClauseHtmlSource = '<h4>' + dalContentdata.title + '</h4>';
dynamicClauseHtmlSource = dynamicClauseHtmlSource + '<p></p>';
dynamicClauseHtmlSource = dynamicClauseHtmlSource + + '<p style="text-align:justify;line-height:0.3em">' + dalContentdata.description + '</p>';
dynamicClauseHtmlSource = this.brToNewLine(dynamicClauseHtmlSource);
return dynamicClauseHtmlSource;
}
getBlockData(dalContentdata) {
let dynamicBlockHtmlSource = '<h4>' + dalContentdata.title + '</h4>';
dynamicBlockHtmlSource = dynamicBlockHtmlSource + '<p></p>';
dynamicBlockHtmlSource = dynamicBlockHtmlSource + dalContentdata.description;
dynamicBlockHtmlSource = this.brToNewLine(dynamicBlockHtmlSource);
return dynamicBlockHtmlSource;
}
getTableData(dalContentdata) {
let tableSource = "<table>";
tableSource = tableSource + "<tr>";
for (var k = 0; k < dalContentdata.displayColumns.length; k++) {
tableSource = tableSource + "<th style='word-wrap: break-word'>" + dalContentdata.displayColumns[k] + "</th>";
}
tableSource = tableSource + "</tr>";
for (var j = 0; j < dalContentdata.tableValues.length; j++) {
tableSource = tableSource + "<tr>";
for (var k = 0; k < dalContentdata.displayColumns.length; k++) {
tableSource = tableSource + "<td style='word-wrap: break-word'>" + dalContentdata.tableValues[0][dalContentdata.displayColumns[k]] + "</td>";
}
tableSource = tableSource + "</tr>";
}
tableSource = tableSource + "</table>";
return tableSource;
}
brToNewLine(str) {
return str.replace(/<br ?\/?>/g, "\n");
}

Fetch photos from Instagram

Currently I'm able to fetch the photos of the logged in user in my app. But I want to fetch the photos from my instagram developer account in which I have registered my app. Is this possible? Currently,
NSString *urlString=[NSString stringWithFormat:#"https://api.instagram.com/v1/users/self/feed/?access_token=%#",appDelegate.instagram.accessToken];
fetches the detail of the logged in user. But I want to get the photos from my client's instagram account. Replacing 'self' in the above url with client's username doesn't work. Any ideas ?
Can't you use the /users/user-id/media/recent Endpoint?
Example from Instagram API Documentation, to get Feed for UserID = 3, use following
https://api.instagram.com/v1/users/3/media/recent/?access_token=ACCESS-TOKEN
Returns
{
"data": [{
"comments": {
"data": [],
"count": 0
},
"caption": {
"created_time": "1296710352",
"text": "Inside le truc #foodtruck",
"from": {
"username": "kevin",
"full_name": "Kevin Systrom",
"type": "user",
"id": "3"
},
"id": "26621408"
},
"likes": {
"count": 15,
"data": [{
"username": "mikeyk",
"full_name": "Mike Krieger",
"id": "4",
"profile_picture": "..."
}, {...subset of likers...}]
},
"link": "http://instagr.am/p/BWrVZ/",
"user": {
"username": "kevin",
"profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_3_75sq_1295574122.jpg",
"id": "3"
},
"created_time": "1296710327",
"images": {
"low_resolution": {
"url": "http://distillery.s3.amazonaws.com/media/2011/02/02/6ea7baea55774c5e81e7e3e1f6e791a7_6.jpg",
"width": 306,
"height": 306
},
"thumbnail": {
"url": "http://distillery.s3.amazonaws.com/media/2011/02/02/6ea7baea55774c5e81e7e3e1f6e791a7_5.jpg",
"width": 150,
"height": 150
},
"standard_resolution": {
"url": "http://distillery.s3.amazonaws.com/media/2011/02/02/6ea7baea55774c5e81e7e3e1f6e791a7_7.jpg",
"width": 612,
"height": 612
}
},
"type": "image",
"users_in_photo": [],
"filter": "Earlybird",
"tags": ["foodtruck"],
"id": "22721881",
"location": {
"latitude": 37.778720183610183,
"longitude": -122.3962783813477,
"id": "520640",
"street_address": "",
"name": "Le Truc"
}
},
{
"videos": {
"low_resolution": {
"url": "http://distilleryvesper9-13.ak.instagram.com/090d06dad9cd11e2aa0912313817975d_102.mp4",
"width": 480,
"height": 480
},
"standard_resolution": {
"url": "http://distilleryvesper9-13.ak.instagram.com/090d06dad9cd11e2aa0912313817975d_101.mp4",
"width": 640,
"height": 640
},
"comments": {
"data": [{
"created_time": "1279332030",
"text": "Love the sign here",
"from": {
"username": "mikeyk",
"full_name": "Mikey Krieger",
"id": "4",
"profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_1242695_75sq_1293915800.jpg"
},
"id": "8"
},
{
"created_time": "1279341004",
"text": "Chilako taco",
"from": {
"username": "kevin",
"full_name": "Kevin S",
"id": "3",
"profile_picture": "..."
},
"id": "3"
}],
"count": 2
},
"caption": null,
"likes": {
"count": 1,
"data": [{
"username": "mikeyk",
"full_name": "Mikeyk",
"id": "4",
"profile_picture": "..."
}]
},
"link": "http://instagr.am/p/D/",
"created_time": "1279340983",
"images": {
"low_resolution": {
"url": "http://distilleryimage2.ak.instagram.com/11f75f1cd9cc11e2a0fd22000aa8039a_6.jpg",
"width": 306,
"height": 306
},
"thumbnail": {
"url": "http://distilleryimage2.ak.instagram.com/11f75f1cd9cc11e2a0fd22000aa8039a_5.jpg",
"width": 150,
"height": 150
},
"standard_resolution": {
"url": "http://distilleryimage2.ak.instagram.com/11f75f1cd9cc11e2a0fd22000aa8039a_7.jpg",
"width": 612,
"height": 612
}
},
"type": "video",
"users_in_photo": null,
"filter": "Vesper",
"tags": [],
"id": "363839373298",
"user": {
"username": "kevin",
"full_name": "Kevin S",
"profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_3_75sq_1295574122.jpg",
"id": "3"
},
"location": null
},
]
}
Instagram only provides the API to get the feeds of self .. Have a look on
https://api.instagram.com/v1/users/userID/media/recent
this i hope it provides some recent medias of a user for more info look at this
http://instagram.com/developer/api-console/

Resources