Reputation: 505
I have a MonoTouch application that generates some PDFs locally and then prints them to a network printer. To get this working I initially just added a PDF resource to the project that I could try and print but am having a heck of a time. When I print just HMTL or a string value everything is good but printing the PDF has me lost. When debugging it looks like the app is getting the proper URL.
Any help would be greatly appreciated and my sampled code is below:
public void PrintSomePDF ()
{
var printInfo = UIPrintInfo.PrintInfo;
printInfo.OutputType = UIPrintInfoOutputType.General;
printInfo.JobName = "Test: PDF Print";
string pdfFileName = "printthispdf_01.pdf";
NSUrl url = NSUrl.FromFilename(pdfFileName);
var printer = UIPrintInteractionController.SharedPrintController;
printer.PrintInfo = printInfo;
printer.PrintingItem = url.Path;
printer.ShowsPageRange = true;
printer.Present (true, (handler, completed, err) => {
if (!completed && err != null){
Console.WriteLine ("error");
}
});
}
I was able to resolve the problem with the way I passed in the NSUrl to the PrintingItem. Before I was passing in printer.PrintingItem = url.Path; which was basically just passing in a string of the path and not the actual shape of NSUrl.
printer.PrintingItem = url;
Upvotes: 0
Views: 936
Reputation: 17196
What I've always preferred to do (and this depends very much on the deployed device - in my case it was a server I controlled) was to just install a PDF printer and then it's as easy as printing any other kind of document.
Something like BullZip is free and allows you to write any settings for the print to a RunOnce.ini
(xml) file to have a silent mode print with settings for the filename and so forth.
Obviously not a great solution if you don't have control of the system you're deploying to, but a solid and easy one if you do.
Upvotes: 1