Skip to content

Conversation

@typemytype
Copy link
Owner

not working yet

possible we have to set all: mediaBox, bleedBlox, trimBox

so far its seems not be possible to make one for each page... if so, it should raise that bleed is not possible for every page except the first one

@typemytype
Copy link
Owner Author

and other pdf attributes could be added https://developer.apple.com/documentation/coregraphics/cgpdfcontext/auxiliary_dictionary_keys?language=objc

like author, title, creator...

@justvanrossum
Copy link
Collaborator

The doco says "The bleed box for the document or for a given page." so it must be possible to set it on a per-page basis.

@justvanrossum
Copy link
Collaborator

Maybe it should be added "manually" in the page dictionary, which can be retrieved with CGPDFPageGetDictionary

@justvanrossum
Copy link
Collaborator

I see we use CGContextBeginPage to start a new page. But there is also CGPDFContextBeginPage which allows a pageInfo dict to be passed: https://developer.apple.com/documentation/coregraphics/1456578-cgpdfcontextbeginpage?language=objc

@typemytype typemytype changed the title [WIP] beeld support [WIP] bleed support Oct 9, 2019
@typemytype
Copy link
Owner Author

tried bleed again, still not working

a low level try out...

the title and author ends up in the pdf but not the bleed settings

import Quartz
import AppKit

width = 300
height = 300
leftBleed, topBleed, rightBleed, bottomBleed = 5, 5, 5, 5

mediaBox = Quartz.CGRectMake(0, 0, width + leftBleed + rightBleed, height + topBleed + bottomBleed)
bleedBox = Quartz.CGRectMake(leftBleed, topBleed, width, height)



"""
https://developer.apple.com/documentation/coregraphics/cgpdfcontext/auxiliary_dictionary_keys?language=objc
"""
auxiliaryInfo = {
    Quartz.kCGPDFContextTitle: "my title",
    Quartz.kCGPDFContextAuthor: "DrawBot",
}

pageAuxiliaryInfo = {
    Quartz.kCGPDFContextMediaBox: AppKit.NSValue.valueWithRect_(mediaBox),
    Quartz.kCGPDFContextBleedBox: AppKit.NSValue.valueWithRect_(bleedBox),    
    Quartz.kCGPDFContextTrimBox: AppKit.NSValue.valueWithRect_(mediaBox),
    
}      

print(pageAuxiliaryInfo)      

auxiliaryInfo = Quartz.NSDictionary.dictionaryWithDictionary_(auxiliaryInfo)

_pdfData = Quartz.CFDataCreateMutable(None, 0)
dataConsumer = Quartz.CGDataConsumerCreateWithCFData(_pdfData)

_pdfContext = Quartz.CGPDFContextCreate(dataConsumer, mediaBox, auxiliaryInfo)

Quartz.CGPDFContextBeginPage(_pdfContext, pageAuxiliaryInfo)


Quartz.CGContextMoveToPoint(_pdfContext, 50, 50)
Quartz.CGContextAddLineToPoint(_pdfContext, 150, 50)
Quartz.CGContextAddLineToPoint(_pdfContext, 150, 150)
Quartz.CGContextClosePath(_pdfContext)

Quartz.CGContextSetFillColorWithColor(_pdfContext,
    Quartz.CGColorCreateGenericRGB(1, 0, 0, 1)
)

Quartz.CGContextFillPath(_pdfContext)

Quartz.CGPDFContextEndPage(_pdfContext)
Quartz.CGPDFContextClose(_pdfContext)

path = 'example.pdf'
_pdfData.writeToFile_atomically_(path, True)


for path in [path,]:
    url = AppKit.NSURL.fileURLWithPath_(path)
    pdf = Quartz.CGPDFDocumentCreateWithURL(url)
    page = Quartz.CGPDFDocumentGetPage(pdf, 1)


    boxes = [    
        Quartz.kPDFDisplayBoxMediaBox,
        Quartz.kPDFDisplayBoxCropBox,
        Quartz.kPDFDisplayBoxBleedBox,
        Quartz.kPDFDisplayBoxTrimBox,
        #Quartz.kPDFDisplayBoxArtBox,
    ]
    print(path)
    for box in boxes:
        (x, y), (w, h) = Quartz.CGPDFPageGetBoxRect(page, box)        
        print("  ", box, x, y, w, h)

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

Successfully merging this pull request may close these issues.

3 participants