Deleting Blank Line

Last post 07-03-2009, 2:40 AM by alexey.noskov. 17 replies.
Page 1 of 2 (18 items)   1 2 Next >
Sort Posts: Previous Next
  •  06-05-2009, 9:30 AM 182732

    Deleting Blank Line

    Hi,

    I'm using Aspose.Word for Java.

    I have 2 documents, where the second document is appended directly to the end of the first one.

    After the append, there is a blank line between the two, that I need to get rid of. Is there a way to position the cursor at this line and delete it?

    I used SectionStart.CONTINUOUS to append the doc. I need the transition to be seamless, because both docs contain tables, and there should be a single table with no breaks/gaps after the append.

    In other words, if there was a way to press the Del key at the current line (programmatically), this would solve my problem, and join the tables from the two docs seamlessly.

    Thanks

     
  •  06-05-2009, 11:14 AM 182743 in reply to 182732

    Re: Deleting Blank Line

    Hi

     

    Thanks for your request. Could you please attach your source document, your code, output document and expected output here for testing? I will investigate the issue and provide you more information.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  06-05-2009, 12:10 PM 182754 in reply to 182743

    Re: Deleting Blank Line

    Attachment: Present (inaccessible)

    Hi Alexey, thanks for the reply.

    I have attached two documents: Doc1 and Doc2. I would like to append Doc2 directly to the end of Doc1. They both contain tables, and the result should be a single table, with Doc2 as the next row. No gaps, no blank lines.

    Until today, I was using the Evaluation version, which inserted the line "Evaluation Version" at the top of each document. This broke up the flow of the single table.

    To get a better idea of what the table would look like, I tried artificially removing this line by replacing with a blank:

    doc.getRange().replace("Evaluation Only. Created with Aspose.Words. Copyright 2003-2008 Aspose Pty Ltd.", "",false,false);

    This created a blank line between the tables that I need to remove. Thanks for your help.

    P.S.: As mentioned in my other thread ("30-Day License"), I'm having problems applying the license file. So, is there a workaround I can use to achieve my goal of joining the tables from the docs seamlessly, without the license file? Thanks again.

     
  •  06-06-2009, 1:01 AM 182807 in reply to 182754

    Re: Deleting Blank Line

    Attachment: Present (inaccessible)

    Hi

     

    Thank you for additional information. I think in this case you can use InsertDocument method. Please see the following link for more information:

    http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/insert-a-document-into-another-document.html

     

    Here is code example:

     

    // Open documents

    Document doc1 = new Document(@"Test182\doc1.doc");

    Document doc2 = new Document(@"Test182\doc2.doc");

     

    // Get table from the first document

    Table tab = doc1.FirstSection.Body.Tables[0];

     

    if (tab != null)

    {

        // Insert another docuemnt into the main document

        InsertDocument(tab, doc2);

    }

     

    // Save output document

    doc1.Save(@"Test182\out.doc");

     

    The output document produced on my side is also attached.

     

    Hope this helps.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  06-08-2009, 3:49 PM 182982 in reply to 182807

    Re: Deleting Blank Line

    Thanks for the reply. Can you show me how to get rid of the enhanced new Java for-loops in insertDocument()? My version of Java doesn't support this collection loop. Thanks.
     
  •  06-08-2009, 11:35 PM 183007 in reply to 182982

    Re: Deleting Blank Line

    Hi

     

    Thanks for your inquiry. Here is changed insertDocuemnt method.

     

    /// <summary>

    /// Inserts content of the external document after the specified node.

    /// Section breaks and section formatting of the inserted document are ignored.

    /// </summary>

    /// <param name="insertAfterNode">Node in the destination document after which the content

    /// should be inserted. This node should be a block level node (paragraph or table).</param>

    /// <param name="srcDoc">The document to insert.</param>

    private static void InsertDocument1(Node insertAfterNode, Document srcDoc) throws Exception

    {

        // Make sure that the node is either a pargraph or table.

        if ((insertAfterNode.getNodeType() != NodeType.PARAGRAPH) &

          (insertAfterNode.getNodeType() != NodeType.TABLE))

            throw new Exception("The destination node should be either a paragraph or table.");

     

        // We will be inserting into the parent of the destination paragraph.

        CompositeNode dstStory = insertAfterNode.getParentNode();

     

        // This object will be translating styles and lists during the import.

        NodeImporter importer = new NodeImporter(srcDoc, insertAfterNode.getDocument(), ImportFormatMode.KEEP_SOURCE_FORMATTING);

     

        // Loop through all sections in the source document.

        for (int sectIdx = 0; sectIdx < srcDoc.getSections().getCount(); sectIdx++)

        {

            Section srcSection = srcDoc.getSections().get(sectIdx);

           

            // Loop through all block level nodes (paragraphs and tables) in the body of the section.

            for (int nodeIdx = 0; nodeIdx < srcSection.getBody().getChildNodes().getCount(); nodeIdx++)

            {

                Node srcNode = srcSection.getBody().getChildNodes().get(nodeIdx);

               

                // Let's skip the node if it is a last empty paragarph in a section.

                if (srcNode.getNodeType() == NodeType.PARAGRAPH)

                {

                    Paragraph para = (Paragraph)srcNode;

                    if (para.isEndOfSection() && !para.hasChildNodes())

                        continue;

                }

     

                // This creates a clone of the node, suitable for insertion into the destination document.

                Node newNode = importer.importNode(srcNode, true);

     

                // Insert new node after the reference node.

                dstStory.insertAfter(newNode, insertAfterNode);

                insertAfterNode = newNode;

            }

        }

    }

     

    Hope this helps.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  06-09-2009, 9:09 AM 183081 in reply to 183007

    Re: Deleting Blank Line

    Attachment: Present (inaccessible)

    Thank you, I appreciate your responses. However, there's still a problem.

    I get the red line "Evaluation Version" stuck between the two documents. And when I try to remove it manually, e.g.
    doc2.getRange().replace("Evaluation Only. Created with Aspose.Words. Copyright 2003-2008 Aspose Pty Ltd.", "",false,false);

    -- I get a blank line, still.

    I've attached the results from the operation you told me to use: doc3_eval.doc and doc3_NoEval.doc. In both of these, I use insertDocument() as instructed. But neither one is what I need. The first one has the evaluation line between the tables, and the second one has a blank line after I remove that string.

    The problem seems to be the Evaluation line--your method would probably work if it wasn't there.

    Thanks

     
  •  06-09-2009, 9:32 AM 183085 in reply to 183081

    Re: Deleting Blank Line

    Hi

     

    Thanks for your request. Did you resolve the problem with evaluation license? If no, please try requesting evaluation license one more time, but to another e-mail account. In addition, I think, you can ask our sales team to send the evaluation license to your e-mail in zip archive. In this case, the license file should not be corrupted.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  06-10-2009, 3:09 PM 183376 in reply to 183085

    Re: Deleting Blank Line

    Ok - everything works great. Thanks so much for your replies! The tables get appended to each other seamlessly, just as I need. (I got the license.)

    But I need to ask you something else: A few of my tables need page breaks after them. For example, if we use Doc1 and Doc2 as previously, I tried your code, with a Page Break Insert statement, to insert a page break between the two tables, yet the result is still a seamless table:

    Table tab = doc1.getFirstSection().getBody().getTables().get(0);

    DocumentBuilder dbld = new DocumentBuilder(doc1);
    dbld.insertBreak(BreakType.PAGE_BREAK);
    InsertDocument(tab, doc2);

    Here, I'm again using InsertDocument() from before. But it seems to ignore the page break. The result is the same as your output attachment when you were helping me with seamless tables.

    So, in this particular case, what can I do? Most tables are seamlessly appended, but some (let's say just Table #10) need a page break after them. Thanks again!!

     

     
  •  06-11-2009, 5:30 AM 183469 in reply to 183376

    Re: Deleting Blank Line

    Hi

     

    Thanks for your request. In the code I provided you earlier, I inserted sub document right after the table in the main document. You can insert sub document after any node in your document. If you need to insert sub document at the end of the main document, just insert it after the last paragraphs of the main document.

    In your case you can use code like the following:

     

    DocumentBuilder dbld = new DocumentBuilder(doc1);
    dbld.insertBreak(BreakType.PAGE_BREAK);
    InsertDocument(dbld.getCurrentParagraph(), doc2);

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  06-11-2009, 9:54 AM 183527 in reply to 183469

    Re: Deleting Blank Line

    After this page break, am I in a new section? So, if I need to continue seamless tables after this special case, will this no longer work?

    table1 = mainDoc.getFirstSection().getBody().getTables().get(0)

    and do I have to do

    table1 = mainDoc.getSections().get(1).getBody().getTables().get(0)?

    Thanks so much

     
  •  06-11-2009, 10:07 AM 183530 in reply to 183527

    Re: Deleting Blank Line

    Hi

     

    Thanks for your request. Page Break is not a section break. But after the page break you will have one more table, you need to get the last table in the section I think:

     

    table1 = mainDoc.getFirstSection().getBody().getTables().get(mainDoc.getFirstSection().getBody().getTables().getCount()-1);

     

    Hope this helps.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  06-11-2009, 12:30 PM 183551 in reply to 183530

    Re: Deleting Blank Line

    Thanks. Still having difficulties. The page break gets ignored and the subsequent tables get inserted within previous ones (maybe some offset issue).

    Is it possible to insert a page break after a given table, rather than before a given table?

    Also, is there a way to move to the end of the page, or the end of a section?

     
  •  06-11-2009, 12:48 PM 183555 in reply to 183551

    Re: Deleting Blank Line

    Hi

     

    Thanks for your inquiry. Could you please attach here set of your documents and show me how the expected result looks? You can create the expected document in MS Word, just to demonstrate what you would like to achieve. I will check your documents and created sample code.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  06-11-2009, 1:46 PM 183570 in reply to 183555

    Re: Deleting Blank Line

    Attachment: Present (inaccessible)

    Thanks a lot. I've attached several documents.

    On the first page of a document, I need:
    1) Doc1 (top table)
    2) Sequential rows of Doc2, attached seamlessly
    3) If I hit an X-th (say 7th, in this example) row of Doc2, then, after this 7th table (or before the 8th), I need to insert Doc3 (a single bottom table) and then a page break. Any other sequential rows of Doc2 must continue on the next page, after the page break.

    4) Sequential rows of Doc2 continue on the next page.

    Notes: Doc2 is the same template used for all of these middle sections, it's just that the data may be different there. Doc3 (a single bottom table) occurs only on the 1st page.

    The attached file result.doc shows how this would look after everything was done. We would get Doc1 + 7 rows of Doc2 + Doc3 + PAGE BREAK, then any remaining Doc2's.

    Thanks for your help

     
Page 1 of 2 (18 items)   1 2 Next >
View as RSS news feed in XML