IOS 4: How to simulate an A4 printer?

I use print in an iOS app. I have a Mac proxy application for a physical test printer, which is a U.S. mail printer. The printer simulator that comes with the iOS simulator is also displayed in US Letter by default.

Anyone have any suggestions on how I can check other default paper sizes?

Thanks!

+4
source share
3 answers

If I realized that the iOS print features are correct - and that big , if - then the print simulator will be set to the letter US or A4 depending on the sizes you send. So, if you send it in A4 size, it will select A4, and if you send it something in Letter Letter size, it will select US Letter.

However, I found with the actual print, this did not always work. To fix this, I found that this changed iOS’s explicit encouragement to choose A4 paper size. This is done in the printInteractionController: selectPaper: method in the UIPrintInteractionController delegate (see code below). If someone there understands this better, write.

More generally (and missing a bit of the question ...), the approach I used to print was to install an application for writing US or A4. When the application first starts, it checks if it is the United States (by testing [[NSLocale currentLocale] objectForKey: NSLocaleCountryCode]), and if so, selects US Letter. Otherwise it is A4. User can change this. (I allow the user to export PDF files, so, say, if she sends UK PDF files to the USA, she can make them look right.)

To print, I first create an A4 or US Letter PDF. Apple Code Sample will skip this for Letter Letter size. For A4, you need to set the PDF size to about 595.4 x 841.7. (To work with other sizes, note that these numbers are indicated at points whose dot density is 72dpi, i.e. you take the size in inches and multiply by 72.) Then I use setPrintingItem: on a UIPrintInteractionController with NSURL for PDF.

I found the iOS print documentation quite complicated, so it is unlikely that a simpler / better / more reliable approach to solving A4 / US writing, etc., would be available. But I hope some of what I wrote here helps.

Delegate code

// code in the UIPrintInteractionController delegate // The [Shared settings] object returns paperWidth and paperHeight depending on the app wide A4 or US Letter setting - (UIPrintPaper *)printInteractionController:(UIPrintInteractionController *)printInteractionController choosePaper:(NSArray *)paperList { CGSize pageSize = CGSizeMake([[Settings shared] paperWidth], [[Settings shared] paperHeight]); return [UIPrintPaper bestPaperForPageSize:pageSize withPapersFromArray:paperList]; } 

Create PDF

 UIGraphicsBeginPDFContextToFile(CGRectMake(0.0, 0.0, [[Settings shared] paperWidth], [[Settings shared] paperHeight]), nil); UIGraphicsBeginPDFPageWithInfo(CGRectMake(0.0, 0.0, [[Settings shared] paperWidth], [[Settings shared] paperHeight]), nil); // create the PDF UIGraphicsEndPDFContext(); 
+6
source

It is pretty simple! In the printer simulator window on your Mac, you will find the “Load Paper” icon. Thus, you can choose the default paper size for any simulated printer. You can determine the alternative size if the print format of your application document is not available!

+1
source

According to the Apple documentation :

If the output type is UIPrintInfoOutputPhoto, the default paper size is 4x6 or A6 or some other standard size, depending on the locale; if the output type is UIPrintInfoOutputGeneral or UIPrintInfoOutputGrayscale, the default paper size is US Letter (8 1/2 by 11 inches) or A4 or some other standard size, depending on the locale.

So, I assume that if you change the locale, you can check the print on A4.

0
source

Source: https://habr.com/ru/post/1336417/


All Articles