-
-
Notifications
You must be signed in to change notification settings - Fork 63
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
[WIP] bleed support #304
base: master
Are you sure you want to change the base?
[WIP] bleed support #304
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