Snippets Collections
import UIKit
import PDFKit
import SVProgressHUD

class PdfViewController: UIViewController {
    
    @IBOutlet weak var dummyPdfView: UIView!
    
    @IBOutlet weak var courseLAbel: UILabel!
    
    var pdfView : PDFView!
    
    var pdfString = ""
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setPDF()
    }
    
    func setPDF() {
        
        SVProgressHUD.show(withStatus: "Loading...")

        DispatchQueue.global(qos: .background).async {
            if let pdfURL = URL(string: self.pdfString), let pdfDocument = PDFDocument(url: pdfURL) {
                DispatchQueue.main.async {
                    // Create and configure the PDFView on the main thread
                    let newPDFView = PDFView(frame: self.dummyPdfView.bounds)
                    newPDFView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
                    self.dummyPdfView.addSubview(newPDFView)
                    
                    // Set properties and assign document to PDFView
                    newPDFView.autoScales = true
                    newPDFView.displayDirection = .vertical
                    newPDFView.displayMode = .singlePageContinuous
                    newPDFView.document = pdfDocument
                    
                    SVProgressHUD.dismiss()
                }
            } else {
                DispatchQueue.main.async {
                    SVProgressHUD.showError(withStatus: "Failed to load PDF")
                }
            }
        }
    }
    
    @IBAction func backButtonPressed(_ sender: Any) {
        SVProgressHUD.dismiss()
        self.dismiss(animated: true)
    }
}
pip install fpdf2
https://pypi.org/project/fpdf2/
# STEP 1
# import libraries
import fitz
import io
from PIL import Image
  
# STEP 2
# file path you want to extract images from
file = "/content/pdf_file.pdf"
  
# open the file
pdf_file = fitz.open(file)
  
# STEP 3
# iterate over PDF pages
for page_index in range(len(pdf_file)):
    
    # get the page itself
    page = pdf_file[page_index]
    image_list = page.getImageList()
      
    # printing number of images found in this page
    if image_list:
        print(f"[+] Found a total of {len(image_list)} images in page {page_index}")
    else:
        print("[!] No images found on page", page_index)
    for image_index, img in enumerate(page.getImageList(), start=1):
        
        # get the XREF of the image
        xref = img[0]
          
        # extract the image bytes
        base_image = pdf_file.extractImage(xref)
        image_bytes = base_image["image"]
          
        # get the image extension
        image_ext = base_image["ext"]
# extract images from pdf file
import fitz
doc = fitz.open("file.pdf")
for i in range(len(doc)):
    for img in doc.getPageImageList(i):
        xref = img[0]
        pix = fitz.Pixmap(doc, xref)
        if pix.n < 5:       # this is GRAY or RGB
            pix.writePNG("p%s-%s.png" % (i, xref))
        else:               # CMYK: convert to RGB first
            pix1 = fitz.Pixmap(fitz.csRGB, pix)
            pix1.writePNG("p%s-%s.png" % (i, xref))
            pix1 = None
        pix = None
//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

Tue Mar 19 2024 05:26:56 GMT+0000 (Coordinated Universal Time)

#pdf #ios #swift
star

Tue Jan 23 2024 13:42:53 GMT+0000 (Coordinated Universal Time)

#commandline #git #pdf
star

Tue Jan 16 2024 10:31:15 GMT+0000 (Coordinated Universal Time) https://pypi.org/project/fpdf2/

#commandline #git #pdf
star

Mon Nov 20 2023 13:44:20 GMT+0000 (Coordinated Universal Time) https://www.google.com/search?q

#python #pdf #images
star

Mon Nov 20 2023 13:43:46 GMT+0000 (Coordinated Universal Time) https://www.google.com/search?q

#python #pdf #images
star

Mon Jun 27 2022 10:53:43 GMT+0000 (Coordinated Universal Time) 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 (Coordinated Universal Time)

#ios #swift #file #pdf #png
star

Tue Dec 07 2021 23:41:36 GMT+0000 (Coordinated Universal Time)

#javascript #pdf
star

Fri May 21 2021 20:09:05 GMT+0000 (Coordinated Universal Time)

#html #nodejs #pdf
star

Thu Nov 26 2020 18:43:15 GMT+0000 (Coordinated Universal Time) 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 (Coordinated Universal Time) 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