[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Printing XML-data to LabelSheet

Posted on 2009-04-21
10
Medium Priority
?
286 Views
Last Modified: 2013-11-18
I need some code that can print xml-data to a labelsheet (ex. Avery) through a browser ... Precise printing-
maybee something xsl-stylesheet or CSS..

Some ideas ???
0
Comment
Question by:conceptdata
  • 6
  • 4
10 Comments
 
LVL 13

Expert Comment

by:R7AF
ID: 24193513
You can create a PDF by transforming the XML data into XSL-FO using XSLT. The resulting XSL-FO document is like HTML, a mix of data and markup. FOP is a free FO processor that can create a PDF from the resulting XSL-FO.
0
 
LVL 13

Expert Comment

by:R7AF
ID: 24193536
And Altova has a tool that can create this XSL-FO plus the necessary XSLT for you. XSL-FO can be complex in the beginning. You can download a trial that works for a month, enough to create the code you need, which you can then edit by hand, and process using FOP.
0
 

Author Comment

by:conceptdata
ID: 24196640
Yes, I know FOP, and have used XSLFAST to make XSL-FO templates for generating PDF-documents.
BUT, I have only tried it locally on a PC, with at batch-file, running the Java command.
Is it possible to run it from a website ???
If that, then how ?
And, please, an example ?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Expert Comment

by:R7AF
ID: 24196846
Yes it is possible, but not simple in my experience. You need a server that can handle java, like tomcat. If you're not familiar with Tomcat, it may be difficult. Below is the code for a JSP file, which save you the trouble of compiling a servlet. You can save this as fop.jsp. You need to change the file names and paths, and you should be up and running in no time, provided that you have the FO file ready.
<%@ page import="
java.io.*, 
java.io.File.*, 
java.net.URL, 
javax.servlet.*, 
javax.servlet.http.*, 
javax.xml.parsers.*, 
javax.xml.transform.*,
javax.xml.transform.stream.*, 
javax.xml.transform.sax.*, 
org.w3c.dom.*, 
org.apache.fop.apps.FopFactory, org.apache.fop.apps.Fop, 
org.apache.fop.apps.MimeConstants; " %>
 
<%
 
response.setContentType("application/pdf");
response.setHeader("Content-Disposition", "inline; filename=fop.pdf" );
 
String filepath = new File(application.getRealPath(request.getServletPath())).getParent().toString();
 
File FoFile = new File(filepath + "/normal.fo");
 
StreamSource fo = new StreamSource(FoFile);
StreamResult result = new StreamResult(out);
 
FopFactory fopFactory = FopFactory.newInstance();
TransformerFactory tFactory = TransformerFactory.newInstance();
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, response.getOutputStream());
 
Result result = new SAXResult(fop.getDefaultHandler());
 
StreamSource source = new StreamSource(FoFile.openStream());
Transformer transformer = tFactory.newTransformer();
transformer = tFactory.newTransformer();
transformer.transform(fo,result);
%>

Open in new window

0
 

Author Comment

by:conceptdata
ID: 24197111
I don't think my web provider have tomcat on their server.
I think it is a IIS webserver . ??

Any other way  ?
0
 
LVL 13

Expert Comment

by:R7AF
ID: 24197909
Is is IIS or Apache? Does it run ASP or PHP pages? Some providers with Linux servers (mostly apache+php) allow for Tomcat war-files. But you should ask your provider first. Tomcat can run behind IIS, but most providers don't want this because of the possible problems when running a badly configured tomcat server, or a webapp that misuses memory. If it is an IIS server, then using ASP can be a much simpler solution, not using FOP, but another parser.
0
 

Author Comment

by:conceptdata
ID: 24198091
Its a IIS server, with no Tomcat .....
How do I et started with a ASP solution / parser.. ??
Can you help too ?
0
 
LVL 13

Expert Comment

by:R7AF
ID: 24198531
http://www.renderx.com/download/personal.html
http://www.antennahouse.com/product/ahf50/download.htm

These are two options. The renderx personal edition is free. I don't know much about .net tools.
0
 

Author Comment

by:conceptdata
ID: 24222266
Hi again R7AF
I didn't use your solution, but you gave me enough info, to find the right solution .
IIS server -> NFOP (.NET apache FOP version -> great)
XSL <-> XML to PDF.....

So the points is yours....

BUT can you help with the following :

Is it possible to do the following in XSLFAST / ALTOVA / any other product :
"5 columns
"3 rows
"XML FILE :
   oQty
   oName
   oBarcode
"The qty is how many labels of each name/barcode I need

Something like this :

<Item>
<qty>2</qty>
<name>test</name>
<barcode>123456789123</barcode>
</Item>
<Item>
<qty>5</qty>
<name>test1</name>
<barcode>133456789123</barcode>
</Item>

_________________________________________________________________________
|     test                  |   test                  |      test1                |   test1                |     test1                |
|    123456789123 | 123456789123  |                              |                           |                             |
_________________________________________________________________________
|     test1                |   test1                |                              |                           |                             |
|    123456789123 | 123456789123  |                              |                           |                             |
_________________________________________________________________________
And so on
Can you help me here.
0
 
LVL 13

Accepted Solution

by:
R7AF earned 2000 total points
ID: 24225287
Below is some code I wrote a while ago. You have to adapt this to your situation, but I think that won't be too difficult. If you have a fixed set of rows, you can remove the foreach if you want.
<fo:table width="100%" space-after.optimum="5mm" font-size="8pt">
 
	<fo:table-column column-width="proportional-column-width(5)" /> <!-- pos -->
	<fo:table-column column-width="proportional-column-width(65)" /> <!-- title -->
	<fo:table-column column-width="proportional-column-width(9)" /> <!-- price -->
	<fo:table-column column-width="proportional-column-width(9)" /> <!-- tax -->
	<fo:table-column column-width="proportional-column-width(12)" /> <!-- taxrate -->
	
	<fo:table-body>
	
		<fo:table-row font-weight="bold" font-family="Helvetica">
			<fo:table-cell display-align="before" padding="3pt" text-align="start"  >
				<fo:block> </fo:block>
			</fo:table-cell>
			<fo:table-cell display-align="before" padding="3pt" text-align="start"   >
				<fo:block>
					Description
				</fo:block>
			</fo:table-cell>
			<fo:table-cell display-align="before" padding="3pt" text-align="end"   >
				<fo:block>
					Price
				</fo:block>
			</fo:table-cell>
			<fo:table-cell display-align="before" padding="3pt" text-align="end"   >
				<fo:block>
					Tax
				</fo:block>
			</fo:table-cell>
			
			<fo:table-cell display-align="before" padding="3pt" text-align="end"   >
				<fo:block>
					% (Taxrate)
				</fo:block>
			</fo:table-cell>
			
		</fo:table-row>
		
		<xsl:for-each select="/results/items/record[invoice=$invoice/id]">
		
			<fo:table-row>
				<xsl:attribute name="background-color">
					<xsl:choose>
						<xsl:when test="position() mod 2 = 1">	#eee</xsl:when>
						<xsl:otherwise>white</xsl:otherwise>
					</xsl:choose>
				</xsl:attribute>
				<fo:table-cell display-align="before" padding="3pt" text-align="end"  >
					<fo:block><xsl:value-of select="position()"/> </fo:block>
				</fo:table-cell>
				<fo:table-cell display-align="before" padding="3pt" text-align="start"   >
					<fo:block>
						<xsl:value-of select="title"/>
					</fo:block>
					<fo:block font-size="7pt">
						<xsl:value-of select="description"/>
					</fo:block>
				</fo:table-cell>
				
				<fo:table-cell display-align="before" padding="3pt" text-align="end"   >
					<fo:block>
						<xsl:value-of select="format-number(price, '#.###,00', 'european')"/>
					</fo:block>
				</fo:table-cell>
				<fo:table-cell display-align="before" padding="3pt" text-align="end"  >
					<fo:block>
						<xsl:value-of select="format-number(tax, '#.###,00', 'european')"/>
						
					</fo:block>
				</fo:table-cell>
				<fo:table-cell display-align="before" padding="3pt" text-align="end"   >
					<fo:block>
						<xsl:value-of select="format-number(taxrate, '#.###,00', 'european')"/>
					</fo:block>
				</fo:table-cell>
				
			</fo:table-row>
		</xsl:for-each>
	</fo:table-body>
</fo:table>

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question