I'm following this guide to create PDF but I don't understand what I have to code on myDrawnContent function : https://developer.apple.com/library/archive/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_pdf/dq_pdf.html#//apple_ref/doc/uid/TP30001066-CH214-CJBFFHHA
Using this guide I'm able to create a PDF with the function:
-(void) MyCreatePDFFile:(CGRect)pageRect filename:(const char *)filename;
I need to code the -(void)myDrawContent:(CGContextRef) pdfContext; I want to set a Tittle on the top, a NSImage and a NSString after the image, how i do that?
Adiccionaly: for that I found this code:
NSString * path = @"/Users/admin/Downloads/prueba.pdf";
PDFDocument * pdf = [[PDFDocument alloc]init];
NSImage *image = [self getRepImage];
PDFPage * page = [[PDFPage alloc ] initWithImage:image];
[pdf insertPage:page atIndex: [pdf pageCount]];
[pdf writeToFile:path];
It creates a pdf with a NSImage but I how do i add text ? Thank you
The PDFKit classes like
PDFDocumentandPDFPagedo not let you add text. If you need to create a PDF with text, use the data structureCGContextin the Quartz framework to create a PDF context to create a PDF file and use Core Text to draw text in the PDF context.To create a PDF context create a
CGContextobject. You must supply a URL for the PDF file. The second argument is a rectangle that specifies the page size. If you want a standard 8.5 by 11 inch page, you can pass NULL. The third and final argument is an optional dictionary of auxiliary information. You can pass NULL for this option.Call the
CGContextfunctionbeginPDFPageto create a PDF page that you can draw in. Draw your image. For small amounts of text, call the Core Text functionCTLineCreateWithAttributedStringto create a line for the text. Call the Core Text functionCTLineDrawto draw the text in the PDF context. If you have large amounts of text to draw, you will need to create a Core Text framesetter and use that to create and draw frames of text.Call the
CGContextfunctionendPDFPageto finish drawing the page. Repeat the calls tobeginPDFPageandendPDFPageto draw additional pages. When you are finished, call theCGContextfunctionclosePDFto close the PDF context and save the PDF file.