Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scale resize PDF #60

Open
ghost opened this issue Jan 14, 2017 · 2 comments
Open

Scale resize PDF #60

ghost opened this issue Jan 14, 2017 · 2 comments

Comments

@ghost
Copy link

ghost commented Jan 14, 2017

I need to resize the PDF but the solution #45 will not scale the PDF for me. Is it possible to resize the Generate PDF ?

@CostaTC
Copy link

CostaTC commented Feb 8, 2017

The solutions I've found are to:

  • Convert the PDF to an image and resize then convert back to PDF
  • Have the files sized before they are converted into a PDF

There may be some normal way but these are the two solutions I found under time constraints.

@markst
Copy link

markst commented Nov 28, 2018

I'm doing the following:

@IBAction func printBookingsAction(_ sender: Any) {
    let dpi = DPIType.dpi_300
    
    let diaryViewController = UIStoryboard(name: "Bookings", bundle: Bundle.main).instantiateViewController(withIdentifier: "DiaryViewController") as! DiaryViewController
    diaryViewController.loadViewIfNeeded()
    diaryViewController.currentHourSection = nil
    
    let collectionView = diaryViewController.collectionView!
    collectionView.removeFromSuperview()
    collectionView.size(size: CGSize(width: PDFPageSize.A4.width, height: collectionView.collectionViewLayout.collectionViewContentSize.height))
    collectionView.reloadData()
    collectionView.layoutIfNeeded()
    collectionView.transform = CGAffineTransform(scaleX: dpi.scaleFactor, y: dpi.scaleFactor)
    
    let page = PDFPage.view(collectionView)
    do {
        let destination = NSHomeDirectory() + "/booking-today.pdf"
        try PDFGenerator.generate(page, to: destination, dpi: dpi, password: "")
        self.printPDF(filePath: destination)
    } catch let e {
        print(e)
    }
}

But this produces a PDF with the output size of:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants