public static void createPDF(String url, String pdf) throws IOException,
			DocumentException {
		FileOutputStream os = null;
		try {
			os = new FileOutputStream(pdf);
			ITextRenderer renderer = new ITextRenderer();
			ResourceLoaderUserAgent callback = new ResourceLoaderUserAgent(
					renderer.getOutputDevice());
			callback.setSharedContext(renderer.getSharedContext());
			renderer.getSharedContext().setUserAgentCallback(callback);

			Document doc = XMLResource.load(new InputSource(url)).getDocument();

			renderer.setDocument(doc, url);
			renderer.layout();
			renderer.createPDF(os);

			os.close();
			os = null;
		} finally {
			if (os != null) {
				try {
					os.close();
				} catch (IOException e) {
					System.err.println(e.getMessage());
				}
			}
		}
	}