Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Mon Mar 18, 2013 2:53 pm

Hi,


i have used the below code snippet till last friday .

Document document = new Document();
document.LoadFromFile(@"D:\TempoVSS-Document\Sign Off Documents\DocumentManagement\FRS Document Management V1.docx", Spire.Doc.FileFormat.Docx);

document.SaveToFile(@"D:\TempoVSS-Document\Sign Off Documents\DocumentManagement\FRS Document Management V1.pdf", Spire.Doc.FileFormat.PDF);

it was working fine till that day but i am facing ArgumentNullException error in saving the word document into pdf at SaveToFile part.


"Value cannot be null.
Parameter name: page"


I am using evaluation dll .
Please kindly advise me what i should do to rectify the issue.

Regards,
Arafath

araafathmd
 
Posts: 3
Joined: Mon Mar 18, 2013 1:38 pm

Tue Mar 19, 2013 3:02 am

Dear Arafath,

Thanks for your inquiry.
Could you please share your docx file? So that we do the test with your docx file to reproduce and solve this issue.
Thank you!

Thanks &Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Tue Mar 19, 2013 6:57 am

hi i couldnt able to attach the docx files along with this mail.

i have attahced the same in our mail conversation .please find the same and do the needful.

Regards,
Arafath

araafathmd
 
Posts: 3
Joined: Mon Mar 18, 2013 1:38 pm

Wed Mar 20, 2013 5:42 am

Dear Arafath,

We had received your file and sent you a solution by e-mail. Now we have known that the solution sloved your issue.
We share the solution here to help other customers which have this issue.
Code: Select all
namespace DocToPdf
{
    public class PdfConverter
    {
        public static byte[] Convert(String fileName)
        {
            AppDomain currentDomain = AppDomain.CurrentDomain;
            AppDomain ad = AppDomain.CreateDomain(String.Format("app-{0}", Guid.NewGuid()),
                currentDomain.Evidence, currentDomain.SetupInformation, currentDomain.PermissionSet);
            Type proxyType = typeof(DocToPdf.PdfConverterProxy);
            var proxy = (DocToPdf.PdfConverterProxy)ad.CreateInstanceAndUnwrap(proxyType.Assembly.FullName, proxyType.FullName);
            byte[] data = proxy.Convert(fileName);
            AppDomain.Unload(ad);

            return data;
        }
    }

    public class PdfConverterProxy : MarshalByRefObject
    {
        public byte[] Convert(String fileName)
        {
            Document doc = new Document(fileName);
            using (MemoryStream buffer = new MemoryStream())
            {
                doc.SaveToStream(buffer, FileFormat.PDF);
                return buffer.ToArray();
            }
        }
    }
}

Code: Select all
namespace Demo
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            String fileName = Server.MapPath("sample.docx");
           
            byte[] data = DocToPdf.PdfConverter.Convert(fileName);

            Response.Clear();
            Response.AddHeader("Content-Type", "application/pdf");
            Response.AddHeader("Content-Disposition", "attachment;filename=output.pdf");
            Response.OutputStream.Write(data, 0, data.Length);
            Response.End();
        }
     
    }
}



Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.Doc