Need sample code

43 views
Skip to first unread message

LesterBE

unread,
Aug 8, 2012, 4:55:51 PM8/8/12
to silv...@googlegroups.com
Looking for sample code for doing the conversion from pdf to xod totally in memory and returning the XOD in a byte array.  Currently in my web service I'm saving the pdf I retrieve from my DB, then using docpub to convert the file, reading the xod result back and returning that in my web service.  I know this is completely ineffient, but I can find sample code for doing it in memory.  Below is the code I'm currently using:
 
if (attachTable.Rows.Count >= 1) 

DataRow row = attachTable.Rows[0]; 
byte[] fileData = new byte[0]; 
fileData = (byte[])row["filedata"]; 
string name = row["filename"].ToString();
name = col + "-" + rev.ToString() + "-" + name; 
int arraysize = fileData.GetUpperBound(0); 
string uploadFolder = @"D:\webservices\3x3PM\wwwstore"; 
if (!fileData.IsNull()) 
  name = name.Replace(" ", ""); 
  string filePath = Path.Combine(uploadFolder, name); 
   FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write);
   fs.Write(fileData, 0, arraysize); 
   fs.Close(); 
   LaunchConverterApp(filePath, filePath.Replace(".pdf", ".xod")); 
   result.File = System.IO.File.ReadAllBytes(filePath.Replace(".pdf", ".xod")); 

}
 




public void LaunchConverterApp(string input, string output) 


  ProcessStartInfo startInfo = new ProcessStartInfo(); 
  startInfo.CreateNoWindow = false;
  startInfo.UseShellExecute = false;
   startInfo.FileName = @"C:\docpub32.exe";
   startInfo.WindowStyle =
   ProcessWindowStyle.Normal;
   startInfo.Arguments = input + @" -f xod -o " + @"D:\webservices\3x3pm\wwwstore --noprompt";
   try
   {
      using (Process exeProcess = Process.Start(startInfo))
      {
         exeProcess.WaitForExit();
      } 
   } 
   catch 
   { 
   } 

}

Support

unread,
Aug 9, 2012, 3:29:03 PM8/9/12
to silv...@googlegroups.com
 
For conversion you can use PDFNet SDK (with pdftron.PDF.Convert.ToXod() .... i.e. WebViewer Publisher Add-on).
For sample code please take a look at WebViewerStreaming sample which is included as part of the SDK (http://www.pdftron.com/pdfnet/downloads.html).
 
Btw. to make things more effieceint you may want to cache XOD-s instead of reconverting files over and over.
Reply all
Reply to author
Forward
0 new messages