How To decode Base64 encoded .SVG string using Swift 5.x - ios

I want to decode a base64 encoded .svg image using Swift 5.x. Can anybody guide me on how to do it?
I have encoded and decoded base64 .png before. Need help about .svg specifically.

pod 'SVGKit'
install this pod and then set up this code is really help me to solve my problem
let temp = qrCode.components(separatedBy: ",")
let dataDecoded : Data = Data(base64Encoded: temp[1], options:
.ignoreUnknownCharacters)!
let decoded = SVGKImage(data:dataDecoded)
self.youriimage.image = decoded?.uiImage

Related

swift read xls(excel) content + Hindi + Gujarati Character Encoding issue

read xls(Excel) file with non english character(**not xlsx file)
i have tried all the encoding option but i am unable to read xls file content.
let data = try Data(contentsOf: url)// Document Directory file path
let dataEncoded = String(data: data, encoding: .utf8)
Example
Thanks in advance.
resolved my issue through below SDK:
https://github.com/QuetzalMX/QuetzalXLSReader

Wkwebview cannot display images in html having path of library directory

I have studied similar questions but couldnot find solution.
I am using WkWebView. It renders a html from library directory so i did loadfileurl.
It has option of displaying an image, we select the image from gallery/take camera , then from image data wecreate a file in library directory and sendthe path to web .
I tried both path var/... and also appended file://
both cases image is not displaying.
Please help.
Any suggestions appreciated.
An alternative would be to encode the images as base64 strings and insert them into the HTML before rendering. You could either save the images as images or the base64 string, depending on whether you need to use them in another context.
// Get the base64 representation of the image
let image = UIImage(named: icon) // This could also be loaded from the file system
let data = image!.pngData()
let b64String = String(data: data!.base64EncodedData(), encoding: String.Encoding.utf8)!
let finalString = "data:image/png;base64," + b64String
// Insert into HTML string before rendering in webview
let myHTML = baseHTML.replacingOccurrences(of: "#PLACEHOLDER#", with: finalString)
You will need to have #PLACEHOLDER# in your HTML file at the point where you would have the path to the image.

Is it possible to add a password to generated PDF in Swift?

I found how to add a password while you are writing the data into the disk,
pdfDocument.write(to: encryptedFileURL, withOptions: [PDFDocumentWriteOption.userPasswordOption : "pwd",
PDFDocumentWriteOption.ownerPasswordOption : "pwd"])
but in my case, I'm generating the PDF file differently. I'm generating it from data and directly in the MailComposer convert and send it like:
if let pdfData = printPageRenderer.drawPDFUsingPrintPageRenderer(printPageRenderer: printPageRenderer) {
mailComposer.addAttachmentData(pdfData as Data, mimeType: "application/pdf", fileName: "PDF")
}
But I cannot find a way how can I add a password to my PDF file if I'm not saving the file on my FileManager and I'm not using PDFKit.
Are there any options to do that? It would be great to know that. Any tips or help are appreciated!
Thanks in advance!
I assume you use UIGraphicsPDFRenderer in iOS to obtain the PDF data.
When initializing UIGraphicsPDFRenderer, you may have to give an UIGraphicsPDFRendererFormat.
In this UIGraphicsPDFRendererFormat, you can set format.documentInfo.
This documentInfo has
const CFStringRef kCGPDFContextUserPassword
const CFStringRef kCGPDFContextOwnerPassword;
Hopefully, you can get what you like.

How to read GB2312 encoded text files using Swift 3.0

My app needs to read text files encoded in GB2312. Here is the current code.
SGFString = try String(contentsOf:path)
It throws an exception.
couldn’t be opened because the text encoding of its contents can’t be
determined.
While looking into the String.Encoding values, there is no GB2312. What would be the best way to read the GB2312 text files?
Thanks
Ray
Thanks for OOPer's help. I copied some of the code from the links, now it works.
Here is the code:
extension String.Encoding {
static let gb_18030_2000 = String.Encoding(rawValue: CFStringConvertEncodingToNSStringEncoding(CFStringEncoding(CFStringEncodings.GB_18030_2000.rawValue)))
}
Gb2312String = try String(contentsOf:path, encoding:String.Encoding.gb_18030_2000)

How to get details from QR code?

I got a string from a qr generated image. But how can I get URL out of it. The string I got is the following.
aHR0cDovL2R1Yml6emxlLWludGVydmlldy5zMy5hbWF6b25hd3MuY29tLzg3M2FhMTA5LnR4dA==
Can anybody help me to get all the information out of it?
Thanks
That string is encoded in Base64. The decoded version of your string is:
http://dubizzle-interview.s3.amazonaws.com/873aa109.txt
If you need to integrate this into your software, find a library that has a Base64 decoder to decode such strings.

Resources