Bonjour à toutes et à tous,
je souhaite générer via Quartz un PDF.
voici le code de l'initialisation du Pdf :
ok pas de problème pour l'initialisation du PDF.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53CGContextRef pdfContext; CFStringRef path; CFURLRef url; CFDataRef boxData = NULL; CFMutableDictionaryRef myDictionary = NULL; CFMutableDictionaryRef pageDictionary = NULL; const char * namePDF = [@"myPDF" cStringUsingEncoding:NSUTF8StringEncoding]; path = CFStringCreateWithCString (NULL, namePDF, kCFStringEncodingUTF8); url = CFURLCreateWithFileSystemPath (NULL, path, kCFURLPOSIXPathStyle, 0); myDictionary = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); CFDictionarySetValue(myDictionary, kCGPDFContextTitle, path); CFRelease (path); CFDictionarySetValue(myDictionary, kCGPDFContextCreator, CFSTR("__xxx__")); pdfContext = CGPDFContextCreateWithURL (url, &pageRect, myDictionary); CFRelease(myDictionary); CFRelease(url); pageDictionary = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); boxData = CFDataCreate(NULL,(const UInt8 *)&pageRect, sizeof (CGRect)); CFDictionarySetValue(pageDictionary, kCGPDFContextMediaBox, boxData); CGPDFContextBeginPage (pdfContext, myDictionary); // draw content of document... ... CGPDFContextEndPage (pdfContext); CGContextRelease (pdfContext); CFRelease(pageDictionary); CFRelease(boxData);
je souhaite écrire 2 lignes de texte (dans la partie du code // draw content of document...).
La première est dessinée correctement sur le PDF - ok.
La deuxième n'apparait pas !!!
voici le code pour écrire le texte dans le PDF :
ce qui est bizarre c'est que je peux écrire soit l'une soit l'autre mais pas les 2 !!!
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28- (void) drawText : (CGContextRef) myContext : (CGRect) contextRect : (NSMutableAttributedString *) text : (const char *) nameFont : (struct tColor) foreground : (struct tColor) background { float w, h; w = contextRect.size.width; h = contextRect.size.height; if (![[text string] isEqualToString: @""]) { CGContextSetRGBFillColor(myContext, background.red, background.green, background.blue, 0.8); CGContextFillRect(myContext, NSMakeRect(px, py, w, h + 2)); CGContextSelectFont (myContext, nameFont, [NSFont systemFontSize], kCGEncodingMacRoman); CGContextSetCharacterSpacing (myContext, 1); CGContextSetTextDrawingMode (myContext, kCGTextFillClip); CGContextSetRGBFillColor (myContext, foreground.red, foreground.green, foreground.blue, 1.0); const char * txt = [[text string] cStringUsingEncoding:NSUTF8StringEncoding]; CGContextShowTextAtPoint (myContext, px, py + 4, txt, [[text string] length]); } }
pourtant le CGContextRef est de taille largement suffisante.
je pense qu'il faut un seul CGContextRef par PDF, il suffit ensuite de dessiner ce qu'on y veut ?
si vous avez une idée, ne pas hésiter...
merci par avance![]()








Répondre avec citation
Partager