I want to generate dynamically in UIKit a minimal PDF page,
so sending it straight to AirPrint (no file involved),
which contains only one line of text, for example,
Hello, world
as Helvetica Neue Light 180pt.
TBC it must be actually typeset in the PDF, not rendered as an image.
Note that the code to render a bitmap is trivial and widely available .. example https://stackoverflow.com/a/6566696/294884
I've read and tried until I'm blue in the face. Can anyone do this?
PS if you're reading this and you're a Postscript programmer, I'm specifically talking about the PDF generation systems in iPad, example: https://developer.apple.com/library/mac/documentation/graphicsimaging/conceptual/drawingwithquartz2d/dq_pdf/dq_pdf.html
(I'm totally unclear whether Quartz specifically is the best way to do this - it's a nightmare.)
By the way, here's the exact code to do this with a html approach...
This example sends some dynamic html direct to AirPrint, with no files involved.
PDF is trickier
-(NSString*)_sample
{
NSString *r = @"<table border=0 cellpadding=0 cellspacing=0 width=100%>"
"<tr><td align=right>"
"<font face=courier size=1>Almost a header!</font>"
"</tr></td></table>"
"<br><br><br><br>"
"<font size=4 face=sans-serif>"
"Hello"
"<br><br><br><br>"
"Some <i>italics</i>."
"<br><br><br><br>"
"<table border=1 cellpadding=10 cellspacing=1>"
"<tr><td align=right>one</td><td>two</td><td>three</td></tr>"
"</table>"
"</font>";
return r;
}
-(IBAction)printRawHtml:(UIView *)sender
{
UIPrintInfo *pif = [UIPrintInfo printInfo];
pif.outputType = UIPrintInfoOutputGeneral;
pif.jobName = @"Test HTML-like Job";
UIMarkupTextPrintFormatter *formatter = [[UIMarkupTextPrintFormatter alloc]
initWithMarkupText:[self _sample]
];
formatter.startPage = 0;
formatter.contentInsets = UIEdgeInsetsMake(10, 72.0, 72.0, 72.0);
//top,left,bottom,right
UIPrintInteractionController *pic =
[UIPrintInteractionController sharedPrintController];
pic.delegate = self;
pic.printInfo = pif;
pic.printFormatter = formatter;
pic.showsPageRange = NO;
pic.showsNumberOfCopies = NO;
void (^cph)(UIPrintInteractionController *, BOOL, NSError *) =
^(UIPrintInteractionController
*printController, BOOL completed, NSError *error)
{
if (!completed && error) NSLog(@"print error %@", error);
};
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
[pic presentFromRect:sender.frame
inView:self.view animated:YES completionHandler:cph];
else
[pic presentAnimated:YES completionHandler:cph];
}