Conversation
|
and other pdf attributes could be added https://developer.apple.com/documentation/coregraphics/cgpdfcontext/auxiliary_dictionary_keys?language=objc like author, title, creator... |
|
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. |
|
Maybe it should be added "manually" in the page dictionary, which can be retrieved with CGPDFPageGetDictionary |
|
I see we use |
still not working
|
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) |
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