Problem Exporting to PDF

Hi again,

Here I have completely created the word document I need! I even saved it to the
HD.

I downloaded the most recent version found in download page + the lastest hotfixes for both Aspose.Word ans Aspose.Pdf

but when I try to use:

docFinal.Save("c:/test/myFinalDoc.xml", Aspose.Word.SaveFormat.FormatAsposePdf);

I get: (I also tried with @“c:\test\myFinaldoc.xml” as the path to the save method)

Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

Line 826: Line 827: docFinal.Save(@“c:\test\myFinalDoc.doc”); Line 828: docFinal.Save(“c:/test/myFinalDoc.xml”, Aspose.Word.SaveFormat.FormatAsposePdf); Line 829: Line 830: //Read the document in Aspose
[ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index] System.Collections.ArrayList.get_Item(Int32 index) +91 Aspose.Word.File.u.a(Int32 A_0) Aspose.Word.RW.Pdf.Writer.a.a(ab A_0) 
Aspose.Word.Model.ab.a(Object A_0) Aspose.Word.Model.c.b(Object A_0) 
Aspose.Word.Model.z.a(Object A_0) Aspose.Word.Model.c.b(Object A_0) 
Aspose.Word.Model.u.a(Object A_0) Aspose.Word.Model.c.b(Object A_0) 
Aspose.Word.Model.g.a(Object A_0) Aspose.Word.Model.c.b(Object A_0) 
Aspose.Word.Model.o.a(Object A_0) Aspose.Word.Model.c.b(Object A_0) 
Aspose.Word.Model.p.a(Object A_0) Aspose.Word.Model.c.b(Object A_0) 
Aspose.Word.Model.f.a(Object A_0) Aspose.Word.Model.c.b(Object A_0) 
Aspose.Word.Model.c.a(Object A_0) Aspose.Word.Model.c.b(Object A_0) 
Aspose.Word.Model.c.a(Object A_0) Aspose.Word.Model.h.a(Object A_0) 
Aspose.Word.RW.Pdf.Writer.a.c() Aspose.Word.RW.Pdf.Writer.a.a(h A_0, String A_1) 
Aspose.Word.Document.Save(String fileName, SaveFormat fileFormat) 
Progmatik.com.ACCIsst.Web.audition.btnPrint_Click(Object sender, EventArgs e) in 
c:\inetpub\wwwroot\intranet\audition.aspx.cs:828 System.Web.UI.WebControls.Button.OnClick(EventArgs e) 
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) System.Web.UI.Page.ProcessRequestMain()

Please help me out asap! Thank you!

Send the document to word@aspose.com

Alright, Sent!

The Code I sent basically do the following:

open and add some text to doc1-5.doc
then loup through a collection of data from a database and add as many docFicheFAS.doc as required. Then Add docAnnexe.doc and finally save as myFinalDoc.doc

Any luck yet?

Please expect a reply in 2-3 days.

Hi,

It must have been fixed in one of the recent releases as it works perfect for me in Aspose.Word 2.1.14.

Here is my code:

[Test]
public void TestMartinBittner()
{
    Document doc1 = TestUtil.Open(@"Other\MartinBittner\doc1-5.doc");
    Document doc2 = TestUtil.Open(@"Other\MartinBittner\docFAS.doc");
    Document doc3 = TestUtil.Open(@"Other\MartinBittner\docAnnexes.doc");
    AppendDoc(doc1, doc2);
    AppendDoc(doc1, doc3);
    TestUtil.Save(doc1, @"Other\MartinBittner\out.doc");
}

/// 
/// Moves all sections from one document to another.
/// 
private void AppendDoc(Document dstDoc, Document srcDoc)
{
    while (srcDoc.Sections.Count > 0)
    {
        Section section = srcDoc.Sections[0];
        //The section must first be removed before it can be inserted into a document.
        srcDoc.Sections.RemoveAt(0);
        dstDoc.Sections.Add(section);
    }
}

but where do you actually export to xml pdf format ?

That was saving in DOC, but I’ve just checked saving in PDF also works well. Make sure you have latest hotfix of Aspose.Pdf too.

/// 
/// Pass an open document and a short .doc filename. It will use this name to derive the names
/// for the Aspose.Pdf.Xml and PDF files it will create.
/// 
protected XmlDocument CreatePdfDoc(Document doc, string fileName)
{
    string xmlFileName = System.IO.Path.Combine(
    TestPath,
    System.IO.Path.GetFileNameWithoutExtension(fileName) + " Out" + ".xml");
    doc.Save(xmlFileName, SaveFormat.FormatAsposePdf);
    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.Load(xmlFileName);
    Aspose.Pdf.Pdf pdf = new Aspose.Pdf.Pdf();
    pdf.BindXML(xmlDoc, null);
    pdf.IsImagesInXmlDeleteNeeded = true;
    string pdfFileName = System.IO.Path.Combine(
    TestPath,
    System.IO.Path.GetFileNameWithoutExtension(fileName) + " Out" + ".pdf");
    pdf.Save(pdfFileName);
    return xmlDoc;
}

Alright, I’ll check it out as soon as I get back to the office tomorrow morning !

I’ll let you know how it goes !

Thank you for your help!

Hi,

I still have the same error. Here is part of my code:

// Add the docIntro to Final Doc
AppendDoc(docFinal, docIntro);

// Add the FAS to the Final.doc
for (int i = 0; i < totalFiche; i++)
    AppendDoc(docFinal, docFicheFAS);

// Add the FAM to the Final.doc
for (int i = 0; i < totalFicheFAM; i++)
    AppendDoc(docFinal, docFicheFAM);

// Add the annexes
AppendDoc(docFinal, docAnnexes);

// The following save is commented, but works perfectly. I will send you the 
// ProgrammePrevention.doc file to <word@aspose.com> for you to check it out

// docFinal.Save("ProgrammePrevention.doc", Aspose.Word.SaveFormat.FormatDocument, Aspose.Word.SaveType.OpenInBrowser, this.Response);

// Create the Pdf Document from the Document
CreatePdfDoc(docFinal, "TheDoc");

Here is the CreatePdfDoc function I use (I used yours)

protected void CreatePdfDoc(Aspose.Word.Document doc, string fileName)
{
    string TestPath = @"c:\test";
    string xmlFileName = System.IO.Path.Combine(TestPath, System.IO.Path.GetFileNameWithoutExtension(fileName) + ".xml");

    ***// The following line produce the error describe above
    doc.Save(xmlFileName, Aspose.Word.SaveFormat.FormatAsposePdf); ***

        XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.Load(xmlFileName);

    Aspose.Pdf.Pdf pdf = new Aspose.Pdf.Pdf();
    pdf.BindXML(xmlDoc, null);
    pdf.IsImagesInXmlDeleteNeeded = true;

    string pdfFileName = System.IO.Path.Combine(TestPath, System.IO.Path.GetFileNameWithoutExtension(fileName) + ".pdf");

    pdf.Save(pdfFileName);

}

How many totalFiche and totalFicheFAM do you have? I was adding only one of each.

it depends of the user input.

can have 1 as it can have a maximum of 26 …

I can save the document you’ve sent to me to PDF just fine. Make sure you really have the latest version of Aspose.Word.dll by right clicking on it and checking version. Sometimes a company (your company) firewall or proxy server could cache it and prevent you from obtaining the updated version. I will email you the document I’ve produced.

Please note that you’ve specified explicit row height in the tables and ASpose.Pdf does not support this so some of your rows become narrower.

Humm…

When I check the property of the reference in my VS.NET, I See:

Aspose.Pdf:
Runtime Version: v1.1.4322
Version: 2.1.3.12

Aspose.Word:
Runtime Version: v1.1.4322
Version: 2.1.14.0

Once I got my final doc all together, I use this line to produce the pdf:

CreatePdfDoc(docFinal, "FinalDoc");

And here is my function (the red line produce the error):

protected void CreatePdfDoc(Aspose.Word.Document doc, string fileName)
{
    string TestPath = @"c:\test";
    string xmlFileName = System.IO.Path.Combine(TestPath, System.IO.Path.GetFileNameWithoutExtension(fileName) + ".xml");
    doc.Save(xmlFileName, Aspose.Word.SaveFormat.FormatAsposePdf); 
    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.Load(xmlFileName);
    Aspose.Pdf.Pdf pdf = new Aspose.Pdf.Pdf();
    pdf.BindXML(xmlDoc, null);
    pdf.IsImagesInXmlDeleteNeeded = true;
    string pdfFileName = System.IO.Path.Combine(TestPath, System.IO.Path.GetFileNameWithoutExtension(fileName) + ".pdf");
    pdf.Save(pdfFileName);
}

Please try Aspose.Word 2.2 maybe a fix for the fontcodes we did for another request solved the problem.

you mean an older version of what I actually have?

to install what I currently have, I went in the download section, download Aspose.Word and the hotfix and installed both.

Where can I get 2.0 ?

Sorry I meant 2.2. So 2.2 is not working for you?

Ok, I successfully created a pdf, but it is really not looking like the word document !!

What can I do to make it look the same way ? I’ll email it to you tomorrow when I get back to work so you can see what I mean

I still have a few problem in my pdf created from my word document.

I sent both document to word@aspose.com.

Thanks for the great support!