6 Replies Latest reply on Feb 25, 2011 7:30 AM by Jerry62712

    How do I print XML?

    Jerry62712 Level 1

      I'm trying to print from within Flex.  I tried printing the source datagrid using FlexPrintJob, but the grid lacked one of the fields I needed.  I then built an XML string (see code below) and perhaps there is a way there.

       

      One thought (in a separate thread) is to somehow put the XML string into a PDF, display it and let the users print from there.  But if there is a way within Flex that won't involve a complex process, I'd rather do that.

       

      Datagrid (dataprovider) to XML:

       

                      var numNotes:int = model.dpCASENOTES.length;
                      if (numNotes != 0)
                      {
                          var xmlHold:String = "";
                          for (var i:int = 0; i < numNotes; i++)
                          {
                              var noteNum:int = numNotes - i;
                              xmlHold += "<RepeatingData>";
                              var tempData:String = (model.dpCASENOTES[i] as CaseNotesVO).updatedBy.toString();
                              xmlHold += "<UpdatedBy>" + tempData + "</UpdatedBy>";
                              tempData = (model.dpCASENOTES[i] as CaseNotesVO).postTs.toString();
                              xmlHold += "<PostedDate>" + tempData + "</PostedDate>";
                              tempData = (model.dpCASENOTES[i] as CaseNotesVO).notes.toString();
                              xmlHold += "<Notes>" + tempData + "</Notes>";
                              tempData = (model.dpCASENOTES[i] as CaseNotesVO).cnNum.toString();
                              xmlHold += "<CaseNoteNumber>" + noteNum.toString() + "</CaseNoteNumber>";
                              tempData = (model.dpCASENOTES[i] as CaseNotesVO).shortDescription.toString();
                              xmlHold += "<ShortDesc>" + tempData + "</ShortDesc>";
                              xmlHold += "</RepeatingData>";
                          }
                          xmlHold = "<allNotes>" + xmlHold + "</allNotes>";
                          // create PDF or something with the created XML
                          var xmlCaseNotes:XML = new XML(xmlHold);
                      }
                      else
                      {
                          Alert.show("Nothing to print","Print Warning");
                      }
                  }

        • 1. Re: How do I print XML?
          Flex harUI Adobe Employee

          If you have a datagrid with more than one page of rows, setup a

          PrintDataGrid with the fields you want.

          • 2. Re: How do I print XML?
            Jerry62712 Level 1

            I tried a "FlexPrintJob" and it only prints the visible columns and rows.  We want to print all of them.  Do you have an example of PrintDataGrid?

            http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/printing/PrintDataGr id.html#includeExamplesSummary

            This seems to replace the data grid.  We are using an AdvanceDataGrid (probably for accessibility) currently.

             

            I also tried, and failed, to use PrintAdvanceDataGrid.

            http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/printing/PrintAdvanc edDataGrid.html#includeExamplesSummary

             

            There has to be some way to do this that doesn't involve Einsteinian brains.

            • 3. Re: How do I print XML?
              Flex harUI Adobe Employee

              Try using PrintAdvancedDataGrid.  These component are a bit hard to use, but

              are designed for printing multiple pages of rows without ugly scrollbars and

              other chrome the visual AdvancedDataGrid would print by default.

              • 4. Re: How do I print XML?
                Jerry62712 Level 1

                Would I create on via script, populate it and somehow print it?  I don't want to change the existing visible AdvanceDataGrid as it meets accessibility standards and the stock controls don't.

                 

                I looked at the doc as shown in the prior message and couldn't get them to work.  Do you have an example that does work?

                 

                I appreciate the help.

                • 5. Re: How do I print XML?
                  Flex harUI Adobe Employee

                  My recommendation is to create a print view, just like many websites offer a

                  printable version of a page.  You can even hide the print view when printing

                  it so the user never sees it, or you can show it to them as a sort of

                  preview.

                   

                  If you set up your app to have a data model, then both the interactive view

                  and the print view would hook up to the same model, and both can be defined

                  via MXML.

                  • 6. Re: How do I print XML?
                    Jerry62712 Level 1

                    I like that idea, if I can get it to work.

                     

                    The first problem is I can't get states to work in the component.  The doc says it has to be at the root of the component.  I tried it in all the places indicated:

                    <?xml version="1.0" encoding="utf-8"?>
                    <options:OptionContent
                        xmlns:fx="http://ns.adobe.com/mxml/2009"
                        xmlns:s="library://ns.adobe.com/flex/spark"
                        xmlns:mx="library://ns.adobe.com/flex/mx"
                        xmlns:options="gov.il.dhs.wvs.view.options.*"
                        xmlns:cust="cust.*"
                        creationComplete="_init();"
                        show="showHandler(event)">
                    **couldn't put it here**
                        <fx:Script>
                            <![CDATA[
                                import gov.il.dhs.utils.Utils;
                    stuff cut for space
                    **couldn't put it here**
                                private function printCaseNotes():void
                                {
                                    // Tanf00000620 - add print notes function - JD 2/22/11
                                    // loop through "model.dpCASENOTES" putting members in some printable
                                    // area including: Date Updated, Updated By, Type, Notes

                    //                var flexPrint:FlexPrintJob = new FlexPrintJob();
                    //                var x:PrintAdvancedDataGrid = new PrintAdvancedDataGrid();
                    //                x.source = dg;
                    //                if (flexPrint.start() != true)
                    //                {
                    //                    return;
                    //                }
                    //                flexPrint.addObject(dg);
                    //                // Send the job to the printer.
                    //                flexPrint.send();
                    //                return;

                                    var numNotes:int = model.dpCASENOTES.length;
                                    if (numNotes != 0)
                                    {
                                        var xmlHold:String = "";
                                        for (var i:int = 0; i < numNotes; i++)
                                        {
                                            var noteNum:int = numNotes - i;
                                            xmlHold += "<RepeatingData>";
                                            var tempData:String = (model.dpCASENOTES[i] as CaseNotesVO).updatedBy.toString();
                    stuff cut for space
                                        }
                                        xmlHold = "<allNotes>" + xmlHold + "</allNotes>";
                                        // create PDF or something with the created XML
                                        var xmlCaseNotes:XML = new XML(xmlHold);
                    //                    var flexPrint:FlexPrintJob = new FlexPrintJob();
                    //                    flexPrint.addObject(Object(xmlCaseNotes));
                    //                    flexPrint.send();
                                    }
                                    else
                                    {
                                        Alert.show("Nothing to print","Print Warning");
                                    }
                                    currentState="print";
                                }
                            ]]>
                        </fx:Script>

                        <fx:Script source="../scripts/PagingScript.as"/>

                        <fx:Binding source="{model.applicationStatus}" destination="_checkStatus"/>

                        <fx:Declarations>
                    **couldn't put it here**
                            <!-- Place non-visual elements (e.g., services, value objects) here -->
                            <mx:DateValidator id="fromVal"
                                              source="{fromDate}"
                                              property="text"
                                              requiredFieldError=" is required"/>

                            <mx:DateValidator id="toVal"
                                              source="{toDate}"
                                              requiredFieldError=" is required"
                                              property="text"/>

                            <!--<mx:NumberValidator id="typeVal"
                                 minValue="0"
                                 triggerEvent=""
                                 lowerThanMinError=" is not selected"
                                 source="{TypeDp1}"
                                 property="selectedIndex"/>-->
                        </fx:Declarations>


                        <s:Panel id="casenotes"
                                title="Manage Case Notes"
                                width="100%" height="100%"
                                styleName="mainPanel">
                    **couldn't put it here**
                            <s:layout>
                                <s:VerticalLayout horizontalAlign="left"
                                                  paddingBottom="10" paddingLeft="10"
                                                  paddingRight="10" paddingTop="5"/>
                            </s:layout>

                            <s:Panel id="caseNotesPrint"
                                     includeIn="print">
                                <mx:PrintAdvancedDataGrid>
                                    <mx:columns>
                                        <mx:AdvancedDataGridColumn headerText="Date Updated"
                                                                   textAlign="center"
                                                                   dataField="postTs"
                                                                   labelFunction="formatDate"
                                                                   color="blue"/>
                    stuff cut for space
                                    </mx:columns>
                                </mx:PrintAdvancedDataGrid>
                                <mx:Button label="Return"
                                           click="currentState='normal'" />
                            </s:Panel>

                            <mx:Text id="errors"
                                     color="red"
                                     visible="false"
                                     width="100%" height="0"/>

                            <s:Panel title="Case Notes Search"
                                     id="csSearch"
                                     width="100%" height="70"
                                     includeIn="normal">
                    more stuff cut for space
                            </s:Panel>

                        </s:Panel>
                    </options:OptionContent>

                    As you can see, I'm assuming:

                    1) the PrintAdvancedDataGrid will allow all the rows and columns included to be printed

                    2) it will have the same dataprovider as the normal displayed grid

                    3) once the print panel is displayed, it will be easy to print

                     

                    (the **couldn't...** is this:

                            <s:states>
                                <s:State name="normal" />
                                <s:State name="print" />
                            </s:states>