Snippets Collections
//MARK: - Document Picker

// From your project's capabilities, enable both the iCloud and the Key-Sharing.

@IBAction func pickDocumentPressed(_ sender: Any) {
       presentDocumentPicker()
    }

extension OffersReceivedViewController : UIDocumentPickerDelegate,UINavigationControllerDelegate {
    
    func presentDocumentPicker() {
        let sTypes = getSupportedTypes()
        let documentPickerController = UIDocumentPickerViewController(
            forOpeningContentTypes: sTypes)
        
        documentPickerController.delegate = self
        documentPickerController.allowsMultipleSelection = false
        SVProgressHUD.show()
        self.present(documentPickerController, animated: true) {
            SVProgressHUD.dismiss()
        }
    }
    
    public func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
        guard let myURL = urls.first else {
            return
        }
        print("import result : \(myURL)")
        print("get Image Url")
        fileUrl = myURL
    }
    
    func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
        print("view was cancelled")
        dismiss(animated: true, completion: nil)
    }
    
    func getSupportedTypes() -> [UTType] {
        let supportedTypes : [UTType] = [UTType.utf8TabSeparatedText, UTType.rtf,    UTType.pdf, UTType.webArchive, UTType.image, UTType.jpeg,    UTType.tiff, UTType.gif, UTType.png, UTType.bmp, UTType.ico,    UTType.rawImage, UTType.svg, UTType.livePhoto, UTType.movie,    UTType.video, UTType.audio, UTType.quickTimeMovie, UTType.mpeg,    UTType.mpeg2Video, UTType.mpeg2TransportStream, UTType.mp3,    UTType.mpeg4Movie, UTType.mpeg4Audio, UTType.avi, UTType.aiff,    UTType.wav, UTType.midi, UTType.archive, UTType.gzip, UTType.bz2,    UTType.zip, UTType.appleArchive, UTType.spreadsheet, UTType.epub]
        return supportedTypes
    }
}
let supportedTypes : [UTType] = [UTType.utf8TabSeparatedText, UTType.rtf,    UTType.pdf, UTType.webArchive, UTType.image, UTType.jpeg,    UTType.tiff, UTType.gif, UTType.png, UTType.bmp, UTType.ico,    UTType.rawImage, UTType.svg, UTType.livePhoto, UTType.movie,    UTType.video, UTType.audio, UTType.quickTimeMovie, UTType.mpeg,    UTType.mpeg2Video, UTType.mpeg2TransportStream, UTType.mp3,    UTType.mpeg4Movie, UTType.mpeg4Audio, UTType.avi, UTType.aiff,    UTType.wav, UTType.midi, UTType.archive, UTType.gzip, UTType.bz2,    UTType.zip, UTType.appleArchive, UTType.spreadsheet, UTType.epub]
$('#downloadRegistrationCertificate').on('click',function(){
    downloadPdf();
});

function downloadPdf() {
    var regNum = JSON.parse(sessionStorage.getItem("sessionPath")).regNumber
    
    $.ajax({
        url: apiPathEnv + "/web/registration-service/v1/download-certificate?registrationNumber="+regNum+"&sessionToken="+sessionTokenVar,
        type: 'get',
        headers: { 
            'Accept': 'application/json',
            'Content-Type': 'application/json' 
        }
    })
    .done(function (result) {

        if(result != undefined && (result.messages == null || result.messages.length == 0)){
            console.log("REsults",result.bytes);
            var responseBytes = _base64ToArrayBuffer(result.bytes);   
            var certificateBlob = new Blob([responseBytes], {type: 'application/pdf'});
            // console.log(responseBytes);
            var downloadLink = document.createElement('a');
            downloadLink.href = window.URL.createObjectURL(certificateBlob);
            //downloadLink.download="RegistrationCertificate_" +regNum+ ".pdf";
            //downloadLink.click();
            
            var isIE = /*@cc_on!@*/false || !!document.documentMode;
            var isSafari = /constructor/i.test(window.HTMLElement) || (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window['safari'] || (typeof safari !== 'undefined' && window['safari'].pushNotification));

            if(isIE) { // Internet Explorer 6-11
                window.navigator.msSaveBlob(certificateBlob, 'RegistrationCertificate.pdf');
            }
            else if(isSafari) { // Safari Browser
                var newWindow = window.open(window.URL.createObjectURL(certificateBlob),'_blank')

            }
            else {
                // Mobile Devices
                if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)){
                    downloadLink.download="RegistrationCertificate_" +regNum+ ".pdf";
                    downloadLink.click();
                }
                // Other Browsers
                else {
                    window.open(window.URL.createObjectURL(certificateBlob), '_blank');
                }						
            }
        }
    }).fail(function (result){
        console.log(result);
        // api .fail error page redirect
        siteNotAvailable();
    });
}

function _base64ToArrayBuffer(base64) {
    var binary_string = window.atob(base64);
    var len = binary_string.length;
    var bytes = new Uint8Array(len);
    for (var i = 0; i < len; i++) {
        bytes[i] = binary_string.charCodeAt(i);
    }
    return bytes.buffer;
}	
app.get('/downloadFile', function (req, res) {
  var file = path.join(__dirname, '/pdfs/');
  res.download(file, function (err) {
    if (err) {
      console.log('Error');
      console.log(err);
    } else {
      console.log('Success');
    }
  });
});
star

Mon Jun 27 2022 10:53:43 GMT+0000 (UTC) https://stackoverflow.com/questions/37296929/implement-document-picker-in-swift-ios

#ios #swift #file #pdf #doc #document #picker #mp3 #mp4 #video #audio
star

Mon Jun 27 2022 08:05:49 GMT+0000 (UTC)

#ios #swift #file #pdf #png
star

Tue Dec 07 2021 23:41:36 GMT+0000 (UTC)

#javascript #pdf
star

Fri May 21 2021 20:09:05 GMT+0000 (UTC)

#html #nodejs #pdf
star

Thu Nov 26 2020 18:43:15 GMT+0000 (UTC) https://virtumedia.wordpress.com/2020/02/27/generar-documentos-pdf-en-laravel-que-incluyan-graficos/

#pdf #laravel
star

Tue Jun 09 2020 18:03:00 GMT+0000 (UTC) https://github.com/MrRio/jsPDF

#pdf #imagetopdf #texttopdf

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension