-1

i want to convert xml file to pdf file in c#.

this is my code.

private void printAllDataReceiveToolStripMenuItem_Click(object sender, EventArgs e)
    {            
        // Load the FO style sheet.
        XslCompiledTransform xslt = new XslCompiledTransform();
        xslt.Load("bookFo.xsl");

        // Execute the transform and output the results to a file.
        xslt.Transform("books.xml", "books.fo");
    }
    private void GeneratePDF(string foFile, string pdfFile)
    {
        FileInputStream streamFO = new FileInputStream(foFile);
        InputSource src = new InputSource(streamFO);
        FileOutputStream streamOut = new FileOutputStream(pdfFile);
        Driver driver = new Driver(src, streamOut);
        driver.setRenderer(1);
        driver.run();
        streamOut.close();
    }

however, FileInputStream, InputSource and FileOutputStream shows the error

The type or namespace name 'FileInputStream', InputSource, FIleOutputStream could not be found (are you missing a using directive or an assembly reference?)

this is how i import things (i do not know the right terms for it)

    using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Timers;
using System.Net.Sockets;
using System.Threading;
using System.Net;

//add data to xml
using System.Xml;
using System.Xml.Linq;
//convert to pdf
using System.Xml.Xsl;
using System.Xml.XPath;


using System.IO;

i have been searching through the internet and it said i should add this.

using org.apache.fop;
using org.apache.fop.apps;
using org.apache.fop.tools;
using org.xml.sax;
using java.io;

even i am using this, it saying the same error missing using directive or an assembly reference. can anyone help me with this?

Adrian Fâciu
  • 12,414
  • 3
  • 53
  • 68
sara brown
  • 1,057
  • 8
  • 29
  • 46

3 Answers3

0

you probably also need the dll; I found this post with an answer marked as correct. It explains how to generate the dll: Using ApacheFOP v1.0 in .NET application

Community
  • 1
  • 1
Tom
  • 4,096
  • 2
  • 24
  • 38
0

FileInputStream is a java class. java.io is a java namespace. You can't use these sensibly in .NET. You appear to be mixing platforms and this is why you're having problems.

The approximate equivalent of FileInputStream in .NET is probably StreamReader; for FileOutputStream use StreamWriter. I'm not sure what InputSource is doing so I can't offer a solution there.

If you need more help, you should probably include details of which 3rd-party libraries you're using (since Driver isn't a standard class) and also which websites you've referred to, since adding java.io in a .NET app is unlikely to work in most situations...

Dan Puzey
  • 33,626
  • 4
  • 73
  • 96
0

vjslib.dll doesn't work for .NET Framework 4.0. Here are the details: msdn details

If you want your application to work, change the target framework to .Net Framework 3.0 or 2.0

Levon Alikhanov
  • 103
  • 4
  • 13