मैं आईओएस ऐप में एक पीडीएफ उत्पन्न करता हूं, ड्रॉप्ड फ़ंक्शन का उपयोग करते हुए, nsobject क्लास में ड्रॉटेक्स्ट फ़ंक्शन को कॉल करते समय यह टेक्स्ट को स्पष्ट रूप से फ्रेम और स्ट्रिंग के अनुसार खींचता है जो मैंने निर्दिष्ट किया है।आईओएस: पीडीएफ पीढ़ी में पाठ खींचते समय फ़ॉन्ट कैसे सेट करें?
मेरे कोड
+(void)drawText:(NSString*)textToDraw inFrame:(CGRect)frameRect
{
CFStringRef stringRef = (__bridge CFStringRef)textToDraw;
// Prepare the text using a Core Text Framesetter
CFAttributedStringRef currentText = CFAttributedStringCreate(NULL, stringRef, NULL);
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(currentText);
CGMutablePathRef framePath = CGPathCreateMutable();
CGPathAddRect(framePath, NULL, frameRect);
// Get the frame that will do the rendering.
CFRange currentRange = CFRangeMake(0, 0);
CTFrameRef frameRef = CTFramesetterCreateFrame(framesetter, currentRange, framePath, NULL);
CGPathRelease(framePath);
// Get the graphics context.
CGContextRef currentContext = UIGraphicsGetCurrentContext();
// Put the text matrix into a known state. This ensures
// that no old scaling factors are left in place.
CGContextSetTextMatrix(currentContext, CGAffineTransformIdentity);
// Core Text draws from the bottom-left corner up, so flip
// the current transform prior to drawing.
CGContextTranslateCTM(currentContext, 0, frameRect.origin.y*2);
CGContextScaleCTM(currentContext, 1.0, -1.0);
// Draw the frame.
CTFrameDraw(frameRef, currentContext);
CGContextScaleCTM(currentContext, 1.0, -1.0);
CGContextTranslateCTM(currentContext, 0, (-1)*frameRect.origin.y*2);
CFRelease(frameRef);
CFRelease(stringRef);
CFRelease(framesetter);
}
है लेकिन मैं पाठ fontsize बड़ा और bolder सेट करना होगा।
मैं
CGContextSelectFont(currentContext, "Helvetica", 20, kCGEncodingMacRoman);
और
CGContextSetFontSize (currentContext, 20);
ऊपर समारोह में mr.texian द्वारा प्रदान की जवाब के संदर्भ में, लेकिन कोई बदलाव नहीं इस्तेमाल किया
मैं में उत्पन्न पीडीएफ दिखा रहा UIWebView।
मुझे यह कोड नेट से मिला है। मुझे नहीं पता था कि फ़ॉन्ट सेटिंग के लिए कोड को कहां संपादित करना है। किसी भी मदद की सराहना की जाएगी।
ऊपर दिए गए दो कोड लाइनों को CFAttributtedStringRef सूचक में कैसे जोड़ना है? –