You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CommandLineOptions.java 55KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.cli;
  19. // java
  20. import java.io.File;
  21. import java.io.FileNotFoundException;
  22. import java.io.IOException;
  23. import java.io.PrintStream;
  24. import java.net.URI;
  25. import java.util.Locale;
  26. import java.util.Map;
  27. import java.util.Vector;
  28. import javax.swing.UIManager;
  29. import org.xml.sax.SAXException;
  30. import org.apache.commons.logging.Log;
  31. import org.apache.commons.logging.LogFactory;
  32. import org.apache.fop.Version;
  33. import org.apache.fop.accessibility.Accessibility;
  34. import org.apache.fop.apps.FOPException;
  35. import org.apache.fop.apps.FOUserAgent;
  36. import org.apache.fop.apps.FopConfParser;
  37. import org.apache.fop.apps.FopFactory;
  38. import org.apache.fop.apps.FopFactoryBuilder;
  39. import org.apache.fop.apps.FopFactoryConfig;
  40. import org.apache.fop.apps.MimeConstants;
  41. import org.apache.fop.pdf.PDFAMode;
  42. import org.apache.fop.pdf.PDFEncryptionManager;
  43. import org.apache.fop.pdf.PDFEncryptionParams;
  44. import org.apache.fop.pdf.PDFXMode;
  45. import org.apache.fop.render.Renderer;
  46. import org.apache.fop.render.awt.AWTRenderer;
  47. import org.apache.fop.render.intermediate.IFContext;
  48. import org.apache.fop.render.intermediate.IFDocumentHandler;
  49. import org.apache.fop.render.intermediate.IFSerializer;
  50. import org.apache.fop.render.pdf.PDFEncryptionOption;
  51. import org.apache.fop.render.print.PagesMode;
  52. import org.apache.fop.render.print.PrintRenderer;
  53. import org.apache.fop.render.xml.XMLRenderer;
  54. /**
  55. * Options parses the commandline arguments
  56. */
  57. public class CommandLineOptions {
  58. /** Used to indicate that only the result of the XSL transformation should be output */
  59. public static final int RENDER_NONE = -1;
  60. /* These following constants are used to describe the input (either .FO, .XML/.XSL or
  61. * intermediate format)
  62. */
  63. /** (input) not set */
  64. public static final int NOT_SET = 0;
  65. /** input: fo file */
  66. public static final int FO_INPUT = 1;
  67. /** input: xml+xsl file */
  68. public static final int XSLT_INPUT = 2;
  69. /** input: Area Tree XML file */
  70. public static final int AREATREE_INPUT = 3;
  71. /** input: Intermediate Format XML file */
  72. public static final int IF_INPUT = 4;
  73. /** input: Image file */
  74. public static final int IMAGE_INPUT = 5;
  75. /* show configuration information */
  76. private Boolean showConfiguration = Boolean.FALSE;
  77. /* for area tree XML output, only down to block area level */
  78. private Boolean suppressLowLevelAreas = Boolean.FALSE;
  79. /* user configuration file */
  80. private File userConfigFile;
  81. /* input fo file */
  82. private File fofile;
  83. /* xsltfile (xslt transformation as input) */
  84. private File xsltfile;
  85. /* xml file (xslt transformation as input) */
  86. private File xmlfile;
  87. /* area tree input file */
  88. private File areatreefile;
  89. /* intermediate format input file */
  90. private File iffile;
  91. /* area tree input file */
  92. private File imagefile;
  93. /* output file */
  94. private File outfile;
  95. /* input mode */
  96. private int inputmode = NOT_SET;
  97. /* output mode */
  98. private String outputmode;
  99. /* true if System.in (stdin) should be used for the input file */
  100. private boolean useStdIn;
  101. /* true if System.out (stdout) should be used for the output file */
  102. private boolean useStdOut;
  103. /* true if a catalog resolver should be used for entity and uri resolution */
  104. private boolean useCatalogResolver;
  105. /* rendering options (for the user agent) */
  106. private Map renderingOptions = new java.util.HashMap();
  107. /* target resolution (for the user agent) */
  108. private float targetResolution = FopFactoryConfig.DEFAULT_TARGET_RESOLUTION;
  109. private boolean strictValidation = true;
  110. /* control memory-conservation policy */
  111. private boolean conserveMemoryPolicy;
  112. /* true if a complex script features are enabled */
  113. private boolean useComplexScriptFeatures = true;
  114. /* set to true if -dpi used in command line */
  115. private boolean overrideTargetResolution;
  116. private FopFactory factory;
  117. private FOUserAgent foUserAgent;
  118. private InputHandler inputHandler;
  119. private Log log;
  120. private Vector xsltParams;
  121. private String mimicRenderer;
  122. private boolean flushCache;
  123. private URI baseURI = new File(".").getAbsoluteFile().toURI();
  124. /**
  125. * Construct a command line option object.
  126. */
  127. public CommandLineOptions() {
  128. log = LogFactory.getLog("FOP");
  129. }
  130. /**
  131. * Parses the command line arguments.
  132. *
  133. * @param args the command line arguments.
  134. * @throws FOPException for general errors
  135. * @throws IOException if the the configuration file could not be loaded
  136. * @return true if the processing can continue, false to abort
  137. */
  138. public boolean parse(String[] args)
  139. throws FOPException, IOException {
  140. boolean optionsParsed = true;
  141. try {
  142. optionsParsed = parseOptions(args);
  143. if (optionsParsed) {
  144. if (showConfiguration == Boolean.TRUE) {
  145. dumpConfiguration();
  146. }
  147. checkSettings();
  148. setUserConfig();
  149. if (flushCache) {
  150. flushCache();
  151. }
  152. //Factory config is set up, now we can create the user agent
  153. foUserAgent = factory.newFOUserAgent();
  154. foUserAgent.getRendererOptions().putAll(renderingOptions);
  155. addXSLTParameter("fop-output-format", getOutputFormat());
  156. addXSLTParameter("fop-version", Version.getVersion());
  157. foUserAgent.setConserveMemoryPolicy(conserveMemoryPolicy);
  158. // TODO: Handle this!!
  159. //if (!useComplexScriptFeatures) {
  160. // foUserAgent.setComplexScriptFeaturesEnabled(false);
  161. //}
  162. } else {
  163. return false;
  164. }
  165. } catch (FOPException e) {
  166. printUsage(System.err);
  167. throw e;
  168. } catch (java.io.FileNotFoundException e) {
  169. printUsage(System.err);
  170. throw e;
  171. }
  172. inputHandler = createInputHandler();
  173. if (MimeConstants.MIME_FOP_AWT_PREVIEW.equals(outputmode)) {
  174. //set the system look&feel for the preview dialog
  175. try {
  176. UIManager.setLookAndFeel(
  177. UIManager.getSystemLookAndFeelClassName());
  178. } catch (Exception e) {
  179. System.err.println("Couldn't set system look & feel!");
  180. }
  181. AWTRenderer renderer = new AWTRenderer(foUserAgent, inputHandler, true, true);
  182. foUserAgent.setRendererOverride(renderer);
  183. } else if (MimeConstants.MIME_FOP_AREA_TREE.equals(outputmode)
  184. && mimicRenderer != null) {
  185. // render from FO to Intermediate Format
  186. Renderer targetRenderer = foUserAgent.getRendererFactory().createRenderer(
  187. foUserAgent, mimicRenderer);
  188. XMLRenderer xmlRenderer = new XMLRenderer(foUserAgent);
  189. //Tell the XMLRenderer to mimic the target renderer
  190. xmlRenderer.mimicRenderer(targetRenderer);
  191. //Make sure the prepared XMLRenderer is used
  192. foUserAgent.setRendererOverride(xmlRenderer);
  193. } else if (MimeConstants.MIME_FOP_IF.equals(outputmode)
  194. && mimicRenderer != null) {
  195. // render from FO to Intermediate Format
  196. IFSerializer serializer = new IFSerializer(new IFContext(foUserAgent));
  197. IFDocumentHandler targetHandler
  198. = foUserAgent.getRendererFactory().createDocumentHandler(
  199. foUserAgent, mimicRenderer);
  200. serializer.mimicDocumentHandler(targetHandler);
  201. //Make sure the prepared serializer is used
  202. foUserAgent.setDocumentHandlerOverride(serializer);
  203. }
  204. return true;
  205. }
  206. /**
  207. * @return the InputHandler instance defined by the command-line options.
  208. */
  209. public InputHandler getInputHandler() {
  210. return inputHandler;
  211. }
  212. /**
  213. * Get the logger.
  214. * @return the logger
  215. */
  216. public Log getLogger() {
  217. return log;
  218. }
  219. private void addXSLTParameter(String name, String value) {
  220. if (xsltParams == null) {
  221. xsltParams = new Vector();
  222. }
  223. xsltParams.addElement(name);
  224. xsltParams.addElement(value);
  225. }
  226. /**
  227. * Parses the command line arguments.
  228. *
  229. * @return true if processing can continue, false if it should stop (nothing to do)
  230. * @exception FOPException if there was an error in the format of the options
  231. */
  232. private boolean parseOptions(String[] args) throws FOPException {
  233. // do not throw an exception for no args
  234. if (args.length == 0) {
  235. printVersion();
  236. printUsage(System.out);
  237. return false;
  238. }
  239. for (int i = 0; i < args.length; i++) {
  240. if (args[i].equals("-x")
  241. || args[i].equals("--dump-config")) {
  242. showConfiguration = Boolean.TRUE;
  243. } else if (args[i].equals("-c")) {
  244. i = i + parseConfigurationOption(args, i);
  245. } else if (args[i].equals("-l")) {
  246. i = i + parseLanguageOption(args, i);
  247. } else if (args[i].equals("-s")) {
  248. suppressLowLevelAreas = Boolean.TRUE;
  249. } else if (args[i].equals("-d")) {
  250. // nop. Left there for backwards compatibility
  251. } else if (args[i].equals("-r")) {
  252. strictValidation = false;
  253. } else if (args[i].equals("-conserve")) {
  254. conserveMemoryPolicy = true;
  255. } else if (args[i].equals("-flush")) {
  256. flushCache = true;
  257. } else if (args[i].equals("-cache")) {
  258. parseCacheOption(args, i);
  259. } else if (args[i].equals("-dpi")) {
  260. i = i + parseResolution(args, i);
  261. } else if (args[i].equals("-q") || args[i].equals("--quiet")) {
  262. // nop. Left there for backwards compatibility
  263. } else if (args[i].equals("-fo")) {
  264. i = i + parseFOInputOption(args, i);
  265. } else if (args[i].equals("-xsl")) {
  266. i = i + parseXSLInputOption(args, i);
  267. } else if (args[i].equals("-xml")) {
  268. i = i + parseXMLInputOption(args, i);
  269. } else if (args[i].equals("-atin")) {
  270. i = i + parseAreaTreeInputOption(args, i);
  271. } else if (args[i].equals("-ifin")) {
  272. i = i + parseIFInputOption(args, i);
  273. } else if (args[i].equals("-imagein")) {
  274. i = i + parseImageInputOption(args, i);
  275. } else if (args[i].equals("-awt")) {
  276. i = i + parseAWTOutputOption(args, i);
  277. } else if (args[i].equals("-pdf")) {
  278. i = i + parsePDFOutputOption(args, i, null);
  279. } else if (args[i].equals("-pdfa1b")) {
  280. i = i + parsePDFOutputOption(args, i, "PDF/A-1b");
  281. } else if (args[i].equals("-mif")) {
  282. i = i + parseMIFOutputOption(args, i);
  283. } else if (args[i].equals("-rtf")) {
  284. i = i + parseRTFOutputOption(args, i);
  285. } else if (args[i].equals("-tiff")) {
  286. i = i + parseTIFFOutputOption(args, i);
  287. } else if (args[i].equals("-png")) {
  288. i = i + parsePNGOutputOption(args, i);
  289. } else if (args[i].equals("-print")) {
  290. // show print help
  291. if (i + 1 < args.length) {
  292. if (args[i + 1].equals("help")) {
  293. printUsagePrintOutput();
  294. return false;
  295. }
  296. }
  297. i = i + parsePrintOutputOption(args, i);
  298. } else if (args[i].equals("-copies")) {
  299. i = i + parseCopiesOption(args, i);
  300. } else if (args[i].equals("-pcl")) {
  301. i = i + parsePCLOutputOption(args, i);
  302. } else if (args[i].equals("-ps")) {
  303. i = i + parsePostscriptOutputOption(args, i);
  304. } else if (args[i].equals("-txt")) {
  305. i = i + parseTextOutputOption(args, i);
  306. } else if (args[i].equals("-svg")) {
  307. i = i + parseSVGOutputOption(args, i);
  308. } else if (args[i].equals("-afp")) {
  309. i = i + parseAFPOutputOption(args, i);
  310. } else if (args[i].equals("-foout")) {
  311. i = i + parseFOOutputOption(args, i);
  312. } else if (args[i].equals("-out")) {
  313. i = i + parseCustomOutputOption(args, i);
  314. } else if (args[i].equals("-at")) {
  315. i = i + parseAreaTreeOption(args, i);
  316. } else if (args[i].equals("-if")) {
  317. i = i + parseIntermediateFormatOption(args, i);
  318. } else if (args[i].equals("-a")) {
  319. this.renderingOptions.put(Accessibility.ACCESSIBILITY, Boolean.TRUE);
  320. } else if (args[i].equals("-v")) {
  321. /* verbose mode although users may expect version; currently just print the version */
  322. printVersion();
  323. if (args.length == 1) {
  324. return false;
  325. }
  326. } else if (args[i].equals("-param")) {
  327. if (i + 2 < args.length) {
  328. String name = args[++i];
  329. String expression = args[++i];
  330. addXSLTParameter(name, expression);
  331. } else {
  332. throw new FOPException("invalid param usage: use -param <name> <value>");
  333. }
  334. } else if (args[i].equals("-catalog")) {
  335. useCatalogResolver = true;
  336. } else if (args[i].equals("-o")) {
  337. i = i + parsePDFOwnerPassword(args, i);
  338. } else if (args[i].equals("-u")) {
  339. i = i + parsePDFUserPassword(args, i);
  340. } else if (args[i].equals("-pdfprofile")) {
  341. i = i + parsePDFProfile(args, i);
  342. } else if (args[i].equals("-noprint")) {
  343. getPDFEncryptionParams().setAllowPrint(false);
  344. } else if (args[i].equals("-nocopy")) {
  345. getPDFEncryptionParams().setAllowCopyContent(false);
  346. } else if (args[i].equals("-noedit")) {
  347. getPDFEncryptionParams().setAllowEditContent(false);
  348. } else if (args[i].equals("-noannotations")) {
  349. getPDFEncryptionParams().setAllowEditAnnotations(false);
  350. } else if (args[i].equals("-nocs")) {
  351. useComplexScriptFeatures = false;
  352. } else if (args[i].equals("-nofillinforms")) {
  353. getPDFEncryptionParams().setAllowFillInForms(false);
  354. } else if (args[i].equals("-noaccesscontent")) {
  355. getPDFEncryptionParams().setAllowAccessContent(false);
  356. } else if (args[i].equals("-noassembledoc")) {
  357. getPDFEncryptionParams().setAllowAssembleDocument(false);
  358. } else if (args[i].equals("-noprinthq")) {
  359. getPDFEncryptionParams().setAllowPrintHq(false);
  360. } else if (args[i].equals("-version")) {
  361. printVersion();
  362. return false;
  363. } else if (!isOption(args[i])) {
  364. i = i + parseUnknownOption(args, i);
  365. } else {
  366. printUsage(System.err);
  367. System.exit(1);
  368. }
  369. }
  370. return true;
  371. } // end parseOptions
  372. private int parseCacheOption(String[] args, int i) throws FOPException {
  373. if ((i + 1 == args.length)
  374. || (isOption(args[i + 1]))) {
  375. throw new FOPException("if you use '-cache', you must specify "
  376. + "the name of the font cache file");
  377. } else {
  378. factory.getFontManager().setCacheFile(URI.create(args[i + 1]));
  379. return 1;
  380. }
  381. }
  382. private int parseConfigurationOption(String[] args, int i) throws FOPException {
  383. if ((i + 1 == args.length)
  384. || (isOption(args[i + 1]))) {
  385. throw new FOPException("if you use '-c', you must specify "
  386. + "the name of the configuration file");
  387. } else {
  388. userConfigFile = new File(args[i + 1]);
  389. return 1;
  390. }
  391. }
  392. private int parseLanguageOption(String[] args, int i) throws FOPException {
  393. if ((i + 1 == args.length)
  394. || (isOption(args[i + 1]))) {
  395. throw new FOPException("if you use '-l', you must specify a language");
  396. } else {
  397. Locale.setDefault(new Locale(args[i + 1], ""));
  398. return 1;
  399. }
  400. }
  401. private int parseResolution(String[] args, int i) throws FOPException {
  402. if ((i + 1 == args.length)
  403. || (isOption(args[i + 1]))) {
  404. throw new FOPException(
  405. "if you use '-dpi', you must specify a resolution (dots per inch)");
  406. } else {
  407. this.targetResolution = Integer.parseInt(args[i + 1]);
  408. this.overrideTargetResolution = true;
  409. return 1;
  410. }
  411. }
  412. private int parseFOInputOption(String[] args, int i) throws FOPException {
  413. setInputFormat(FO_INPUT);
  414. if ((i + 1 == args.length)
  415. || (isOption(args[i + 1]))) {
  416. throw new FOPException("you must specify the fo file for the '-fo' option");
  417. } else {
  418. String filename = args[i + 1];
  419. if (isSystemInOutFile(filename)) {
  420. this.useStdIn = true;
  421. } else {
  422. fofile = new File(filename);
  423. baseURI = getBaseURI(fofile);
  424. }
  425. return 1;
  426. }
  427. }
  428. private int parseXSLInputOption(String[] args, int i) throws FOPException {
  429. setInputFormat(XSLT_INPUT);
  430. if ((i + 1 == args.length)
  431. || (isOption(args[i + 1]))) {
  432. throw new FOPException("you must specify the stylesheet "
  433. + "file for the '-xsl' option");
  434. } else {
  435. xsltfile = new File(args[i + 1]);
  436. return 1;
  437. }
  438. }
  439. private int parseXMLInputOption(String[] args, int i) throws FOPException {
  440. setInputFormat(XSLT_INPUT);
  441. if ((i + 1 == args.length)
  442. || (isOption(args[i + 1]))) {
  443. throw new FOPException("you must specify the input file "
  444. + "for the '-xml' option");
  445. } else {
  446. String filename = args[i + 1];
  447. if (isSystemInOutFile(filename)) {
  448. this.useStdIn = true;
  449. } else {
  450. xmlfile = new File(filename);
  451. baseURI = getBaseURI(xmlfile);
  452. }
  453. return 1;
  454. }
  455. }
  456. private URI getBaseURI(File file) {
  457. return file.getAbsoluteFile().getParentFile().toURI();
  458. }
  459. private int parseAWTOutputOption(String[] args, int i) throws FOPException {
  460. setOutputMode(MimeConstants.MIME_FOP_AWT_PREVIEW);
  461. return 0;
  462. }
  463. private int parsePDFOutputOption(String[] args, int i, String pdfAMode) throws FOPException {
  464. setOutputMode(MimeConstants.MIME_PDF);
  465. if ((i + 1 == args.length)
  466. || (isOption(args[i + 1]))) {
  467. throw new FOPException("you must specify the PDF output file");
  468. } else {
  469. setOutputFile(args[i + 1]);
  470. if (pdfAMode != null) {
  471. if (renderingOptions.get("pdf-a-mode") != null) {
  472. throw new FOPException("PDF/A mode already set");
  473. }
  474. renderingOptions.put("pdf-a-mode", pdfAMode);
  475. }
  476. return 1;
  477. }
  478. }
  479. private void setOutputFile(String filename) {
  480. if (isSystemInOutFile(filename)) {
  481. this.useStdOut = true;
  482. } else {
  483. outfile = new File(filename);
  484. }
  485. }
  486. /**
  487. * Checks whether the given argument is the next option or the specification of
  488. * stdin/stdout.
  489. *
  490. * TODO this is very ad-hoc and should be better handled. Consider the adoption of
  491. * Apache Commons CLI.
  492. *
  493. * @param arg an argument
  494. * @return true if the argument is an option ("-something"), false otherwise
  495. */
  496. private boolean isOption(String arg) {
  497. return arg.length() > 1 && arg.startsWith("-");
  498. }
  499. private boolean isSystemInOutFile(String filename) {
  500. return "-".equals(filename);
  501. }
  502. private int parseMIFOutputOption(String[] args, int i) throws FOPException {
  503. setOutputMode(MimeConstants.MIME_MIF);
  504. if ((i + 1 == args.length)
  505. || (isOption(args[i + 1]))) {
  506. throw new FOPException("you must specify the MIF output file");
  507. } else {
  508. setOutputFile(args[i + 1]);
  509. return 1;
  510. }
  511. }
  512. private int parseRTFOutputOption(String[] args, int i) throws FOPException {
  513. setOutputMode(MimeConstants.MIME_RTF);
  514. if ((i + 1 == args.length)
  515. || (isOption(args[i + 1]))) {
  516. throw new FOPException("you must specify the RTF output file");
  517. } else {
  518. setOutputFile(args[i + 1]);
  519. return 1;
  520. }
  521. }
  522. private int parseTIFFOutputOption(String[] args, int i) throws FOPException {
  523. setOutputMode(MimeConstants.MIME_TIFF);
  524. if ((i + 1 == args.length)
  525. || (isOption(args[i + 1]))) {
  526. throw new FOPException("you must specify the TIFF output file");
  527. } else {
  528. setOutputFile(args[i + 1]);
  529. return 1;
  530. }
  531. }
  532. private int parsePNGOutputOption(String[] args, int i) throws FOPException {
  533. setOutputMode(MimeConstants.MIME_PNG);
  534. if ((i + 1 == args.length)
  535. || (isOption(args[i + 1]))) {
  536. throw new FOPException("you must specify the PNG output file");
  537. } else {
  538. setOutputFile(args[i + 1]);
  539. return 1;
  540. }
  541. }
  542. private int parsePrintOutputOption(String[] args, int i) throws FOPException {
  543. setOutputMode(MimeConstants.MIME_FOP_PRINT);
  544. if ((i + 1 < args.length)
  545. && (args[i + 1].charAt(0) != '-')) {
  546. String arg = args[i + 1];
  547. String[] parts = arg.split(",");
  548. for (int j = 0; j < parts.length; j++) {
  549. String s = parts[j];
  550. if (s.matches("\\d+")) {
  551. renderingOptions.put(PrintRenderer.START_PAGE, new Integer(s));
  552. } else if (s.matches("\\d+-\\d+")) {
  553. String[] startend = s.split("-");
  554. renderingOptions.put(PrintRenderer.START_PAGE, new Integer(startend[0]));
  555. renderingOptions.put(PrintRenderer.END_PAGE, new Integer(startend[1]));
  556. } else {
  557. PagesMode mode = PagesMode.byName(s);
  558. renderingOptions.put(PrintRenderer.PAGES_MODE, mode);
  559. }
  560. }
  561. return 1;
  562. } else {
  563. return 0;
  564. }
  565. }
  566. private int parseCopiesOption(String[] args, int i) throws FOPException {
  567. if ((i + 1 == args.length)
  568. || (isOption(args[i + 1]))) {
  569. throw new FOPException("you must specify the number of copies");
  570. } else {
  571. renderingOptions.put(PrintRenderer.COPIES, new Integer(args[i + 1]));
  572. return 1;
  573. }
  574. }
  575. private int parsePCLOutputOption(String[] args, int i) throws FOPException {
  576. setOutputMode(MimeConstants.MIME_PCL);
  577. if ((i + 1 == args.length)
  578. || (isOption(args[i + 1]))) {
  579. throw new FOPException("you must specify the PDF output file");
  580. } else {
  581. setOutputFile(args[i + 1]);
  582. return 1;
  583. }
  584. }
  585. private int parsePostscriptOutputOption(String[] args, int i) throws FOPException {
  586. setOutputMode(MimeConstants.MIME_POSTSCRIPT);
  587. if ((i + 1 == args.length)
  588. || (isOption(args[i + 1]))) {
  589. throw new FOPException("you must specify the PostScript output file");
  590. } else {
  591. setOutputFile(args[i + 1]);
  592. return 1;
  593. }
  594. }
  595. private int parseTextOutputOption(String[] args, int i) throws FOPException {
  596. setOutputMode(MimeConstants.MIME_PLAIN_TEXT);
  597. if ((i + 1 == args.length)
  598. || (isOption(args[i + 1]))) {
  599. throw new FOPException("you must specify the text output file");
  600. } else {
  601. setOutputFile(args[i + 1]);
  602. return 1;
  603. }
  604. }
  605. private int parseSVGOutputOption(String[] args, int i) throws FOPException {
  606. setOutputMode(MimeConstants.MIME_SVG);
  607. if ((i + 1 == args.length)
  608. || (isOption(args[i + 1]))) {
  609. throw new FOPException("you must specify the SVG output file");
  610. } else {
  611. setOutputFile(args[i + 1]);
  612. return 1;
  613. }
  614. }
  615. private int parseAFPOutputOption(String[] args, int i) throws FOPException {
  616. setOutputMode(MimeConstants.MIME_AFP);
  617. if ((i + 1 == args.length)
  618. || (isOption(args[i + 1]))) {
  619. throw new FOPException("you must specify the AFP output file");
  620. } else {
  621. setOutputFile(args[i + 1]);
  622. return 1;
  623. }
  624. }
  625. private int parseFOOutputOption(String[] args, int i) throws FOPException {
  626. setOutputMode(MimeConstants.MIME_XSL_FO);
  627. if ((i + 1 == args.length)
  628. || (isOption(args[i + 1]))) {
  629. throw new FOPException("you must specify the FO output file");
  630. } else {
  631. setOutputFile(args[i + 1]);
  632. return 1;
  633. }
  634. }
  635. private int parseCustomOutputOption(String[] args, int i) throws FOPException {
  636. String mime = null;
  637. if ((i + 1 < args.length)
  638. || (args[i + 1].charAt(0) != '-')) {
  639. mime = args[i + 1];
  640. if ("list".equals(mime)) {
  641. String[] mimes = factory.getRendererFactory().listSupportedMimeTypes();
  642. System.out.println("Supported MIME types:");
  643. for (int j = 0; j < mimes.length; j++) {
  644. System.out.println(" " + mimes[j]);
  645. }
  646. System.exit(0);
  647. }
  648. }
  649. if ((i + 2 >= args.length)
  650. || (isOption(args[i + 1]))
  651. || (isOption(args[i + 2]))) {
  652. throw new FOPException("you must specify the output format and the output file");
  653. } else {
  654. setOutputMode(mime);
  655. setOutputFile(args[i + 2]);
  656. return 2;
  657. }
  658. }
  659. private int parseUnknownOption(String[] args, int i) throws FOPException {
  660. if (inputmode == NOT_SET) {
  661. inputmode = FO_INPUT;
  662. String filename = args[i];
  663. if (isSystemInOutFile(filename)) {
  664. this.useStdIn = true;
  665. } else {
  666. fofile = new File(filename);
  667. baseURI = getBaseURI(fofile);
  668. }
  669. } else if (outputmode == null) {
  670. outputmode = MimeConstants.MIME_PDF;
  671. setOutputFile(args[i]);
  672. } else {
  673. throw new FOPException("Don't know what to do with "
  674. + args[i]);
  675. }
  676. return 0;
  677. }
  678. private int parseAreaTreeOption(String[] args, int i) throws FOPException {
  679. setOutputMode(MimeConstants.MIME_FOP_AREA_TREE);
  680. if ((i + 1 == args.length)
  681. || (isOption(args[i + 1]))) {
  682. throw new FOPException("you must specify the area-tree output file");
  683. } else if ((i + 2 == args.length)
  684. || (isOption(args[i + 2]))) {
  685. // only output file is specified
  686. setOutputFile(args[i + 1]);
  687. return 1;
  688. } else {
  689. // mimic format and output file have been specified
  690. mimicRenderer = args[i + 1];
  691. setOutputFile(args[i + 2]);
  692. return 2;
  693. }
  694. }
  695. private int parseIntermediateFormatOption(String[] args, int i) throws FOPException {
  696. setOutputMode(MimeConstants.MIME_FOP_IF);
  697. if ((i + 1 == args.length)
  698. || (args[i + 1].charAt(0) == '-')) {
  699. throw new FOPException("you must specify the intermediate format output file");
  700. } else if ((i + 2 == args.length)
  701. || (args[i + 2].charAt(0) == '-')) {
  702. // only output file is specified
  703. setOutputFile(args[i + 1]);
  704. return 1;
  705. } else {
  706. // mimic format and output file have been specified
  707. mimicRenderer = args[i + 1];
  708. setOutputFile(args[i + 2]);
  709. return 2;
  710. }
  711. }
  712. private int parseAreaTreeInputOption(String[] args, int i) throws FOPException {
  713. setInputFormat(AREATREE_INPUT);
  714. if ((i + 1 == args.length)
  715. || (isOption(args[i + 1]))) {
  716. throw new FOPException("you must specify the Area Tree file for the '-atin' option");
  717. } else {
  718. String filename = args[i + 1];
  719. if (isSystemInOutFile(filename)) {
  720. this.useStdIn = true;
  721. } else {
  722. areatreefile = new File(filename);
  723. baseURI = getBaseURI(areatreefile);
  724. }
  725. return 1;
  726. }
  727. }
  728. private int parseIFInputOption(String[] args, int i) throws FOPException {
  729. setInputFormat(IF_INPUT);
  730. if ((i + 1 == args.length)
  731. || (isOption(args[i + 1]))) {
  732. throw new FOPException("you must specify the intermediate file for the '-ifin' option");
  733. } else {
  734. String filename = args[i + 1];
  735. if (isSystemInOutFile(filename)) {
  736. this.useStdIn = true;
  737. } else {
  738. iffile = new File(filename);
  739. baseURI = getBaseURI(iffile);
  740. }
  741. return 1;
  742. }
  743. }
  744. private int parseImageInputOption(String[] args, int i) throws FOPException {
  745. setInputFormat(IMAGE_INPUT);
  746. if ((i + 1 == args.length)
  747. || (isOption(args[i + 1]))) {
  748. throw new FOPException("you must specify the image file for the '-imagein' option");
  749. } else {
  750. String filename = args[i + 1];
  751. if (isSystemInOutFile(filename)) {
  752. this.useStdIn = true;
  753. } else {
  754. imagefile = new File(filename);
  755. baseURI = getBaseURI(imagefile);
  756. }
  757. return 1;
  758. }
  759. }
  760. private PDFEncryptionParams getPDFEncryptionParams() throws FOPException {
  761. PDFEncryptionParams params = (PDFEncryptionParams) renderingOptions.get(PDFEncryptionOption.ENCRYPTION_PARAMS);
  762. if (params == null) {
  763. if (!PDFEncryptionManager.checkAvailableAlgorithms()) {
  764. throw new FOPException("PDF encryption requested but it is not available."
  765. + " Please make sure MD5 and RC4 algorithms are available.");
  766. }
  767. params = new PDFEncryptionParams();
  768. renderingOptions.put(PDFEncryptionOption.ENCRYPTION_PARAMS, params);
  769. }
  770. return params;
  771. }
  772. private int parsePDFOwnerPassword(String[] args, int i) throws FOPException {
  773. if ((i + 1 == args.length)
  774. || (isOption(args[i + 1]))) {
  775. getPDFEncryptionParams().setOwnerPassword("");
  776. return 0;
  777. } else {
  778. getPDFEncryptionParams().setOwnerPassword(args[i + 1]);
  779. return 1;
  780. }
  781. }
  782. private int parsePDFUserPassword(String[] args, int i) throws FOPException {
  783. if ((i + 1 == args.length)
  784. || (isOption(args[i + 1]))) {
  785. getPDFEncryptionParams().setUserPassword("");
  786. return 0;
  787. } else {
  788. getPDFEncryptionParams().setUserPassword(args[i + 1]);
  789. return 1;
  790. }
  791. }
  792. private int parsePDFProfile(String[] args, int i) throws FOPException {
  793. if ((i + 1 == args.length)
  794. || (isOption(args[i + 1]))) {
  795. throw new FOPException("You must specify a PDF profile");
  796. } else {
  797. String profile = args[i + 1];
  798. PDFAMode pdfAMode = PDFAMode.getValueOf(profile);
  799. if (pdfAMode != null && pdfAMode != PDFAMode.DISABLED) {
  800. if (renderingOptions.get("pdf-a-mode") != null) {
  801. throw new FOPException("PDF/A mode already set");
  802. }
  803. renderingOptions.put("pdf-a-mode", pdfAMode.getName());
  804. return 1;
  805. } else {
  806. PDFXMode pdfXMode = PDFXMode.getValueOf(profile);
  807. if (pdfXMode != null && pdfXMode != PDFXMode.DISABLED) {
  808. if (renderingOptions.get("pdf-x-mode") != null) {
  809. throw new FOPException("PDF/X mode already set");
  810. }
  811. renderingOptions.put("pdf-x-mode", pdfXMode.getName());
  812. return 1;
  813. }
  814. }
  815. throw new FOPException("Unsupported PDF profile: " + profile);
  816. }
  817. }
  818. private void setOutputMode(String mime) throws FOPException {
  819. if (outputmode == null) {
  820. outputmode = mime;
  821. } else {
  822. throw new FOPException("you can only set one output method");
  823. }
  824. }
  825. private void setInputFormat(int format) throws FOPException {
  826. if (inputmode == NOT_SET || inputmode == format) {
  827. inputmode = format;
  828. } else {
  829. throw new FOPException("Only one input mode can be specified!");
  830. }
  831. }
  832. /**
  833. * checks whether all necessary information has been given in a consistent way
  834. */
  835. private void checkSettings() throws FOPException, FileNotFoundException {
  836. if (inputmode == NOT_SET) {
  837. throw new FOPException("No input file specified");
  838. }
  839. if (outputmode == null) {
  840. throw new FOPException("No output file specified");
  841. }
  842. if ((outputmode.equals(MimeConstants.MIME_FOP_AWT_PREVIEW)
  843. || outputmode.equals(MimeConstants.MIME_FOP_PRINT))
  844. && outfile != null) {
  845. throw new FOPException("Output file may not be specified "
  846. + "for AWT or PRINT output");
  847. }
  848. if (inputmode == XSLT_INPUT) {
  849. // check whether xml *and* xslt file have been set
  850. if (xmlfile == null && !this.useStdIn) {
  851. throw new FOPException("XML file must be specified for the transform mode");
  852. }
  853. if (xsltfile == null) {
  854. throw new FOPException("XSLT file must be specified for the transform mode");
  855. }
  856. // warning if fofile has been set in xslt mode
  857. if (fofile != null) {
  858. log.warn("Can't use fo file with transform mode! Ignoring.\n"
  859. + "Your input is " + "\n xmlfile: "
  860. + xmlfile.getAbsolutePath()
  861. + "\nxsltfile: "
  862. + xsltfile.getAbsolutePath()
  863. + "\n fofile: "
  864. + fofile.getAbsolutePath());
  865. }
  866. if (xmlfile != null && !xmlfile.exists()) {
  867. throw new FileNotFoundException("Error: xml file "
  868. + xmlfile.getAbsolutePath()
  869. + " not found ");
  870. }
  871. if (!xsltfile.exists()) {
  872. throw new FileNotFoundException("Error: xsl file "
  873. + xsltfile.getAbsolutePath()
  874. + " not found ");
  875. }
  876. } else if (inputmode == FO_INPUT) {
  877. if (outputmode.equals(MimeConstants.MIME_XSL_FO)) {
  878. throw new FOPException(
  879. "FO output mode is only available if you use -xml and -xsl");
  880. }
  881. if (fofile != null && !fofile.exists()) {
  882. throw new FileNotFoundException("Error: fo file "
  883. + fofile.getAbsolutePath()
  884. + " not found ");
  885. }
  886. } else if (inputmode == AREATREE_INPUT) {
  887. if (outputmode.equals(MimeConstants.MIME_XSL_FO)) {
  888. throw new FOPException(
  889. "FO output mode is only available if you use -xml and -xsl");
  890. } else if (outputmode.equals(MimeConstants.MIME_FOP_AREA_TREE)) {
  891. throw new FOPException(
  892. "Area Tree Output is not available if Area Tree is used as input!");
  893. }
  894. if (areatreefile != null && !areatreefile.exists()) {
  895. throw new FileNotFoundException("Error: area tree file "
  896. + areatreefile.getAbsolutePath()
  897. + " not found ");
  898. }
  899. } else if (inputmode == IF_INPUT) {
  900. if (outputmode.equals(MimeConstants.MIME_XSL_FO)) {
  901. throw new FOPException(
  902. "FO output mode is only available if you use -xml and -xsl");
  903. } else if (outputmode.equals(MimeConstants.MIME_FOP_AREA_TREE)) {
  904. throw new FOPException(
  905. "Area Tree Output is not available if Intermediate Format"
  906. + " is used as input!");
  907. } else if (outputmode.equals(MimeConstants.MIME_FOP_IF)) {
  908. throw new FOPException(
  909. "Intermediate Output is not available if Intermediate Format"
  910. + " is used as input!");
  911. }
  912. if (iffile != null && !iffile.exists()) {
  913. throw new FileNotFoundException("Error: intermediate format file "
  914. + iffile.getAbsolutePath()
  915. + " not found ");
  916. }
  917. } else if (inputmode == IMAGE_INPUT) {
  918. if (outputmode.equals(MimeConstants.MIME_XSL_FO)) {
  919. throw new FOPException(
  920. "FO output mode is only available if you use -xml and -xsl");
  921. }
  922. if (imagefile != null && !imagefile.exists()) {
  923. throw new FileNotFoundException("Error: image file "
  924. + imagefile.getAbsolutePath()
  925. + " not found ");
  926. }
  927. }
  928. } // end checkSettings
  929. /**
  930. * Sets the user configuration.
  931. * @throws FOPException if creating the user configuration fails
  932. * @throws IOException
  933. */
  934. private void setUserConfig() throws FOPException, IOException {
  935. FopFactoryBuilder fopFactoryBuilder;
  936. if (userConfigFile == null) {
  937. fopFactoryBuilder = new FopFactoryBuilder(baseURI);
  938. fopFactoryBuilder.setStrictFOValidation(strictValidation);
  939. fopFactoryBuilder.setTargetResolution(targetResolution);
  940. fopFactoryBuilder.setComplexScriptFeatures(useComplexScriptFeatures);
  941. } else {
  942. try {
  943. FopConfParser fopConfParser = new FopConfParser(userConfigFile, baseURI);
  944. fopFactoryBuilder = fopConfParser.getFopFactoryBuilder();
  945. if (this.overrideTargetResolution) {
  946. fopFactoryBuilder.setTargetResolution(targetResolution);
  947. }
  948. } catch (SAXException e) {
  949. throw new FOPException(e);
  950. }
  951. if (!strictValidation) {
  952. fopFactoryBuilder.setStrictFOValidation(strictValidation);
  953. }
  954. if (!useComplexScriptFeatures) {
  955. // note: by default cs is enabled so we need to disable it
  956. fopFactoryBuilder.setComplexScriptFeatures(useComplexScriptFeatures);
  957. }
  958. }
  959. factory = fopFactoryBuilder.build();
  960. }
  961. /**
  962. * @return the chosen output format (MIME type)
  963. * @throws FOPException for invalid output formats
  964. */
  965. protected String getOutputFormat() throws FOPException {
  966. if (outputmode == null) {
  967. throw new FOPException("Renderer has not been set!");
  968. }
  969. if (outputmode.equals(MimeConstants.MIME_FOP_AREA_TREE)) {
  970. renderingOptions.put("fineDetail", isCoarseAreaXml());
  971. }
  972. return outputmode;
  973. }
  974. /**
  975. * Create an InputHandler object based on command-line parameters
  976. * @return a new InputHandler instance
  977. * @throws IllegalArgumentException if invalid/missing parameters
  978. */
  979. private InputHandler createInputHandler() {
  980. switch (inputmode) {
  981. case FO_INPUT:
  982. return new InputHandler(fofile);
  983. case AREATREE_INPUT:
  984. return new AreaTreeInputHandler(areatreefile);
  985. case IF_INPUT:
  986. return new IFInputHandler(iffile);
  987. case XSLT_INPUT:
  988. InputHandler handler = new InputHandler(xmlfile, xsltfile, xsltParams);
  989. if (useCatalogResolver) {
  990. handler.createCatalogResolver(foUserAgent);
  991. }
  992. return handler;
  993. case IMAGE_INPUT:
  994. return new ImageInputHandler(imagefile, xsltfile, xsltParams);
  995. default:
  996. throw new IllegalArgumentException("Error creating InputHandler object.");
  997. }
  998. }
  999. /**
  1000. * Get the FOUserAgent for this Command-Line run
  1001. * @return FOUserAgent instance
  1002. */
  1003. protected FOUserAgent getFOUserAgent() {
  1004. return foUserAgent;
  1005. }
  1006. /**
  1007. * Returns the XSL-FO file if set.
  1008. * @return the XSL-FO file, null if not set
  1009. */
  1010. public File getFOFile() {
  1011. return fofile;
  1012. }
  1013. /**
  1014. * Returns the input XML file if set.
  1015. * @return the input XML file, null if not set
  1016. */
  1017. public File getXMLFile() {
  1018. return xmlfile;
  1019. }
  1020. /**
  1021. * Returns the stylesheet to be used for transformation to XSL-FO.
  1022. * @return stylesheet
  1023. */
  1024. public File getXSLFile() {
  1025. return xsltfile;
  1026. }
  1027. /**
  1028. * Returns the output file
  1029. * @return the output file
  1030. */
  1031. public File getOutputFile() {
  1032. return outfile;
  1033. }
  1034. /**
  1035. * Returns the user configuration file to be used.
  1036. * @return the userconfig.xml file
  1037. */
  1038. public File getUserConfigFile() {
  1039. return userConfigFile;
  1040. }
  1041. /**
  1042. * Indicates whether the XML renderer should generate coarse area XML
  1043. * @return true if coarse area XML is desired
  1044. */
  1045. public Boolean isCoarseAreaXml() {
  1046. return suppressLowLevelAreas;
  1047. }
  1048. /**
  1049. * Indicates whether input comes from standard input (stdin).
  1050. * @return true if input comes from standard input (stdin)
  1051. */
  1052. public boolean isInputFromStdIn() {
  1053. return this.useStdIn;
  1054. }
  1055. /**
  1056. * Indicates whether output is sent to standard output (stdout).
  1057. * @return true if output is sent to standard output (stdout)
  1058. */
  1059. public boolean isOutputToStdOut() {
  1060. return this.useStdOut;
  1061. }
  1062. /**
  1063. * Returns the input file.
  1064. * @return either the fofile or the xmlfile
  1065. */
  1066. public File getInputFile() {
  1067. switch (inputmode) {
  1068. case FO_INPUT:
  1069. return fofile;
  1070. case XSLT_INPUT:
  1071. return xmlfile;
  1072. default:
  1073. return fofile;
  1074. }
  1075. }
  1076. private static void printVersion() {
  1077. System.out.println("FOP Version " + Version.getVersion());
  1078. }
  1079. /**
  1080. * Shows the command line syntax including a summary of all available options and some
  1081. * examples.
  1082. *
  1083. * @param out the stream to which the message must be printed
  1084. */
  1085. public static void printUsage(PrintStream out) {
  1086. out.println(
  1087. "\nUSAGE\nfop [options] [-fo|-xml] infile [-xsl file] "
  1088. + "[-awt|-pdf|-mif|-rtf|-tiff|-png|-pcl|-ps|-txt|-at [mime]|-print] <outfile>\n"
  1089. + " [OPTIONS] \n"
  1090. + " -version print FOP version and exit\n"
  1091. + " -x dump configuration settings \n"
  1092. + " -c cfg.xml use additional configuration file cfg.xml\n"
  1093. + " -l lang the language to use for user information \n"
  1094. + " -nocs disable complex script features\n"
  1095. + " -r relaxed/less strict validation (where available)\n"
  1096. + " -dpi xxx target resolution in dots per inch (dpi) where xxx is a number\n"
  1097. + " -s for area tree XML, down to block areas only\n"
  1098. + " -v run in verbose mode (currently simply print FOP version"
  1099. + " and continue)\n\n"
  1100. + " -o [password] PDF file will be encrypted with option owner password\n"
  1101. + " -u [password] PDF file will be encrypted with option user password\n"
  1102. + " -noprint PDF file will be encrypted without printing permission\n"
  1103. + " -nocopy PDF file will be encrypted without copy content permission\n"
  1104. + " -noedit PDF file will be encrypted without edit content permission\n"
  1105. + " -noannotations PDF file will be encrypted without edit annotation permission\n"
  1106. + " -nofillinforms PDF file will be encrypted without"
  1107. + " fill in interactive form fields permission\n"
  1108. + " -noaccesscontent PDF file will be encrypted without"
  1109. + " extract text and graphics permission\n"
  1110. + " -noassembledoc PDF file will be encrypted without"
  1111. + " assemble the document permission\n"
  1112. + " -noprinthq PDF file will be encrypted without"
  1113. + " print high quality permission\n"
  1114. + " -a enables accessibility features (Tagged PDF etc., default off)\n"
  1115. + " -pdfprofile prof PDF file will be generated with the specified profile\n"
  1116. + " (Examples for prof: PDF/A-1b or PDF/X-3:2003)\n\n"
  1117. + " -conserve enable memory-conservation policy (trades memory-consumption"
  1118. + " for disk I/O)\n"
  1119. + " (Note: currently only influences whether the area tree is"
  1120. + " serialized.)\n\n"
  1121. + " -cache specifies a file/directory path location"
  1122. + " for the font cache file\n"
  1123. + " -flush flushes the current font cache file\n\n"
  1124. + " [INPUT] \n"
  1125. + " infile xsl:fo input file (the same as the next) \n"
  1126. + " (use '-' for infile to pipe input from stdin)\n"
  1127. + " -fo infile xsl:fo input file \n"
  1128. + " -xml infile xml input file, must be used together with -xsl \n"
  1129. + " -atin infile area tree input file \n"
  1130. + " -ifin infile intermediate format input file \n"
  1131. + " -imagein infile image input file (piping through stdin not supported)\n"
  1132. + " -xsl stylesheet xslt stylesheet \n \n"
  1133. + " -param name value <value> to use for parameter <name> in xslt stylesheet\n"
  1134. + " (repeat '-param name value' for each parameter)\n \n"
  1135. + " -catalog use catalog resolver for input XML and XSLT files\n"
  1136. + " [OUTPUT] \n"
  1137. + " outfile input will be rendered as PDF into outfile\n"
  1138. + " (use '-' for outfile to pipe output to stdout)\n"
  1139. + " -pdf outfile input will be rendered as PDF (outfile req'd)\n"
  1140. + " -pdfa1b outfile input will be rendered as PDF/A-1b compliant PDF\n"
  1141. + " (outfile req'd, same as \"-pdf outfile -pdfprofile PDF/A-1b\")\n"
  1142. + " -awt input will be displayed on screen \n"
  1143. + " -rtf outfile input will be rendered as RTF (outfile req'd)\n"
  1144. + " -pcl outfile input will be rendered as PCL (outfile req'd) \n"
  1145. + " -ps outfile input will be rendered as PostScript (outfile req'd) \n"
  1146. + " -afp outfile input will be rendered as AFP (outfile req'd)\n"
  1147. + " -tiff outfile input will be rendered as TIFF (outfile req'd)\n"
  1148. + " -png outfile input will be rendered as PNG (outfile req'd)\n"
  1149. + " -txt outfile input will be rendered as plain text (outfile req'd) \n"
  1150. + " -at [mime] out representation of area tree as XML (outfile req'd) \n"
  1151. + " specify optional mime output to allow the AT to be converted\n"
  1152. + " to final format later\n"
  1153. + " -if [mime] out representation of document in intermediate format XML"
  1154. + " (outfile req'd)\n"
  1155. + " specify optional mime output to allow the IF to be converted\n"
  1156. + " to final format later\n"
  1157. + " -print input file will be rendered and sent to the printer \n"
  1158. + " see options with \"-print help\" \n"
  1159. + " -out mime outfile input will be rendered using the given MIME type\n"
  1160. + " (outfile req'd) Example: \"-out application/pdf D:\\out.pdf\"\n"
  1161. + " (Tip: \"-out list\" prints the list of supported MIME types"
  1162. + " and exits)\n"
  1163. //+ " -mif outfile input will be rendered as MIF (FrameMaker) (outfile req'd)\n"
  1164. //+ " Experimental feature - requires additional fop-sandbox.jar.\n"
  1165. + " -svg outfile input will be rendered as an SVG slides file (outfile req'd) \n"
  1166. + " Experimental feature - requires additional fop-sandbox.jar.\n"
  1167. + "\n"
  1168. + " -foout outfile input will only be XSL transformed. The intermediate \n"
  1169. + " XSL-FO file is saved and no rendering is performed. \n"
  1170. + " (Only available if you use -xml and -xsl parameters)\n\n"
  1171. + "\n"
  1172. + " [Examples]\n" + " fop foo.fo foo.pdf \n"
  1173. + " fop -fo foo.fo -pdf foo.pdf (does the same as the previous line)\n"
  1174. + " fop -xml foo.xml -xsl foo.xsl -pdf foo.pdf\n"
  1175. + " fop -xml foo.xml -xsl foo.xsl -foout foo.fo\n"
  1176. + " fop -xml - -xsl foo.xsl -pdf -\n"
  1177. + " fop foo.fo -mif foo.mif\n"
  1178. + " fop foo.fo -rtf foo.rtf\n"
  1179. + " fop foo.fo -print\n"
  1180. + " fop foo.fo -awt\n");
  1181. }
  1182. /**
  1183. * shows the options for print output
  1184. */
  1185. private void printUsagePrintOutput() {
  1186. System.err.println("USAGE: -print [from[-to][,even|odd]] [-copies numCopies]\n\n"
  1187. + "Example:\n"
  1188. + "all pages: fop infile.fo -print\n"
  1189. + "all pages with two copies: fop infile.fo -print -copies 2\n"
  1190. + "all pages starting with page 7: fop infile.fo -print 7\n"
  1191. + "pages 2 to 3: fop infile.fo -print 2-3\n"
  1192. + "only even page between 10 and 20: fop infile.fo -print 10-20,even\n");
  1193. }
  1194. /**
  1195. * Outputs all commandline settings
  1196. */
  1197. private void dumpConfiguration() {
  1198. log.info("Input mode: ");
  1199. switch (inputmode) {
  1200. case NOT_SET:
  1201. log.info("not set");
  1202. break;
  1203. case FO_INPUT:
  1204. log.info("FO ");
  1205. if (isInputFromStdIn()) {
  1206. log.info("fo input file: from stdin");
  1207. } else {
  1208. log.info("fo input file: " + fofile.toString());
  1209. }
  1210. break;
  1211. case XSLT_INPUT:
  1212. log.info("xslt transformation");
  1213. if (isInputFromStdIn()) {
  1214. log.info("xml input file: from stdin");
  1215. } else {
  1216. log.info("xml input file: " + xmlfile.toString());
  1217. }
  1218. log.info("xslt stylesheet: " + xsltfile.toString());
  1219. break;
  1220. case AREATREE_INPUT:
  1221. log.info("AT ");
  1222. if (isInputFromStdIn()) {
  1223. log.info("area tree input file: from stdin");
  1224. } else {
  1225. log.info("area tree input file: " + areatreefile.toString());
  1226. }
  1227. break;
  1228. case IF_INPUT:
  1229. log.info("IF ");
  1230. if (isInputFromStdIn()) {
  1231. log.info("intermediate input file: from stdin");
  1232. } else {
  1233. log.info("intermediate input file: " + iffile.toString());
  1234. }
  1235. break;
  1236. case IMAGE_INPUT:
  1237. log.info("Image ");
  1238. if (isInputFromStdIn()) {
  1239. log.info("image input file: from stdin");
  1240. } else {
  1241. log.info("image input file: " + imagefile.toString());
  1242. }
  1243. break;
  1244. default:
  1245. log.info("unknown input type");
  1246. }
  1247. log.info("Output mode: ");
  1248. if (outputmode == null) {
  1249. log.info("not set");
  1250. } else if (MimeConstants.MIME_FOP_AWT_PREVIEW.equals(outputmode)) {
  1251. log.info("awt on screen");
  1252. if (outfile != null) {
  1253. log.error("awt mode, but outfile is set:");
  1254. log.error("out file: " + outfile.toString());
  1255. }
  1256. } else if (MimeConstants.MIME_FOP_PRINT.equals(outputmode)) {
  1257. log.info("print directly");
  1258. if (outfile != null) {
  1259. log.error("print mode, but outfile is set:");
  1260. log.error("out file: " + outfile.toString());
  1261. }
  1262. } else if (MimeConstants.MIME_FOP_AREA_TREE.equals(outputmode)) {
  1263. log.info("area tree");
  1264. if (mimicRenderer != null) {
  1265. log.info("mimic renderer: " + mimicRenderer);
  1266. }
  1267. if (isOutputToStdOut()) {
  1268. log.info("output file: to stdout");
  1269. } else {
  1270. log.info("output file: " + outfile.toString());
  1271. }
  1272. } else if (MimeConstants.MIME_FOP_IF.equals(outputmode)) {
  1273. log.info("intermediate format");
  1274. log.info("output file: " + outfile.toString());
  1275. } else {
  1276. log.info(outputmode);
  1277. if (isOutputToStdOut()) {
  1278. log.info("output file: to stdout");
  1279. } else {
  1280. log.info("output file: " + outfile.toString());
  1281. }
  1282. }
  1283. log.info("OPTIONS");
  1284. if (userConfigFile != null) {
  1285. log.info("user configuration file: "
  1286. + userConfigFile.toString());
  1287. } else {
  1288. log.info("no user configuration file is used [default]");
  1289. }
  1290. }
  1291. private void flushCache() throws FOPException {
  1292. factory.getFontManager().deleteCache();
  1293. }
  1294. }