I want to create a WCF service (working like windows service). This service will read a PDF file from a specific path, extract pages, create a new PDF file and return it to the caller.
How can I do this ? I use QuickPDF to process on PDF files, I can extract and create new PDF file. How can use this in a WCF service ?
Waiting your helps…
This is only sample code :
public Stream ExtractPdf(string PathOfOriginalPdfFile, int StartPage,int PageCount)
{
PDFLibrary qp = new PDFLibrary();
Stream Stream_ = null;
if (qp.UnlockKey(".................") == 0)
{
string fileName = @"..\..\Test Files\sample1.pdf";
string OutputFile = @"..\..\Test Files\sample1_extracted.pdf";
if (qp.Unlocked() == 1)
{
int docID = qp.LoadFromFile(fileName, "");
int extractPageSuccess = qp.ExtractPages(StartPage, PageCount);
if (extractPageSuccess == 0)
{
// error
}
else
{
qp.SaveToFile(OutputFile);
}
}
}
//
// Codes here
//
return Stream_;
}
I edited it :
public byte[] ExtractPdf(string PathOfOriginalPdfFile, int StartPage,int PageCount)
{
QuickPDFDLL0815.PDFLibrary qp = new QuickPDFDLL0815.PDFLibrary(@"C:\Program Files (x86)\Quick PDF Library\DLL\QuickPDFDLL0815.dll");
string fileName = @"..\..\Test Files\sample1.pdf";
byte[] binFile = null;
if (qp.UnlockKey("...................") == 0)
{
if (qp.Unlocked() == 1)
{
int docID = qp.LoadFromFile(fileName, "");
int extractPageSuccess = qp.ExtractPages(StartPage, PageCount);
if (extractPageSuccess == 0)
{
// error
}
else
{
binFile = qp.SaveToString();
}
}
}
return binFile;
}
You could send the file as a
Stream, see How to: Enable Streaming, then on the client save off the file and have the shell execute it. The MSDN article includes a sampleGetStreammethod as well as a whole section onWriting a custom stream.If you would like fuller sample code the forum post Streamed file transfer using WCF starts with some, however, note that the author posted it there because they were encountering issues running it.
As to byte[] or stream see Uploading Image Blobs–Stream vs Byte Array and Stream vs Raw Bytes. The second states