Objective-C Requires Chilkat v11.7.0+
Objective-C
Generate a QR Code as SVG
See more QR Code Examples
Demonstrates SVG output. An SVG is a vector image, so it stays sharp at any size, which suits print and responsive web pages. Setting output.format to svg and output.return to text returns the SVG document as a string in outputs[0].text. The SVG can also be written straight to a file with output.path, the same as a PNG.Chilkat Objective-C Downloads
#import <CkoJsonObject.h>
#import <CkoFormats.h>
#import <CkoStringBuilder.h>
BOOL success = NO;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"payload.text" value: @"https://www.chilkatsoft.com/"];
[json UpdateString: @"output.format" value: @"svg"];
// An SVG is text, so it can be returned as text rather than as base64.
[json UpdateString: @"output.return" value: @"text"];
CkoFormats *fmt = [[CkoFormats alloc] init];
CkoJsonObject *jsonOut = [[CkoJsonObject alloc] init];
success = [fmt QrCode: @"generate" jsonIn: json jsonOut: jsonOut];
if (success == NO) {
NSLog(@"%@",fmt.LastErrorText);
return;
}
CkoStringBuilder *sbSvg = [[CkoStringBuilder alloc] init];
[jsonOut StringOfSb: @"outputs[0].text" sb: sbSvg];
NSLog(@"%@%@",@"MIME type: ",[jsonOut StringOf: @"outputs[0].mimeType"]);
NSLog(@"%@%d%@%d%@%@",@"size: ",[[jsonOut IntOf: @"outputs[0].width"] intValue],@" x ",[[jsonOut IntOf: @"outputs[0].height"] intValue],@" ",[jsonOut StringOf: @"outputs[0].units"]);
NSLog(@"%@%d%@",@"SVG length: ",[sbSvg.Length intValue],@" characters");
// The SVG is a complete document that can be saved, or placed inline in an HTML page.
success = [sbSvg WriteFile: @"qa_output/qr_chilkat.svg" charset: @"utf-8" emitBom: NO];
if (success == NO) {
NSLog(@"%@",sbSvg.LastErrorText);
return;
}
// The SVG:
//
// Sample output:
// MIME type: image/svg+xml
// size: 148 x 148 px
// SVG length: 12500 characters