Here we render all the pages of the doc using 10 threads at a
time. We alternate rendering format between jpg and tiff. We also
alternate resolution between 150 and 300 dpi. Note how the
RenderingOperation is created in the constructor of
TheRenderingWorker. This is because at this point a copy of the
rendering options is made. Had we created the
RenderingOperation in DoWork, we would have picked up only the last
doc.Rendering.DotsPerInch, because the threads are started in the
following loop. Also note how we dispose the operation in DoWork, to
release resources stored on the native side (the copy of the
rendering options basically).
[C#]class
RenderingWorker { private string
mPath; private RenderOperation
mOp;
public RenderingWorker(Doc inDoc,
string inPath) { mPath
= inPath; mOp = new
RenderOperation(inDoc); }
public
void DoWork()
{ mOp.Save(mPath); mOp.Dispose(); } }
Doc
doc = new Doc(); doc.Read(Server.MapPath("ABCpdf.pdf")); string[]
theExts = { ".jpg", ".tif" }; int[] theDpis = { 150, 300
}; Thread[] threadList = new Thread[10]; int pageNum = 1,
pageCount = doc.PageCount; while (pageNum <= pageCount)
{ int count = 0; while
(count < threadList.Length && pageNum <= pageCount)
{ doc.Rendering.DotsPerInch
= theDpis[(pageNum - 1) % 2]; doc.PageNumber
= pageNum; string
path = Server.MapPath("ABCpdf" + pageNum.ToString() + theExts[(pageNum
- 1) % 2]);
threadList[count] =
new Thread(new RenderingWorker(doc,
path).DoWork); ++count; ++pageNum; } for
(int i = 0; i < count;
++i) threadList[i].Start(); for
(int i = 0; i < count;
++i) threadList[i].Join(); } doc.Clear();
[Visual Basic]Class
RenderingWorker Private mPath As
String Private mOp As
RenderOperation
Public Sub
New(ByVal inDoc As Doc, ByVal inPath As
String) mPath =
inPath mOp = New
RenderOperation(inDoc) End
Sub
Public Sub
DoWork() mOp.Save(mPath) mOp.Dispose() End
Sub End Class
Dim doc As Doc = new
Doc() doc.Read(Server.MapPath("ABCpdf.pdf")) Dim theExts
As String() = {".jpg", ".tif"} Dim theDpis As Integer() = {150,
300} Dim threadList(10 - 1) As Thread Dim pageNum As Integer =
1, pageCount As Integer = doc.PageCount While pageNum <=
pageCount Dim count As Integer =
0 While count < threadList.Length AndAlso pageNum <=
pageCount doc.Rendering.DotsPerInch
= theDpis((pageNum - 1) Mod 2) doc.PageNumber
= pageNum Dim
path As String = Server.MapPath(("ABCpdf" & pageNum.ToString()) +
theExts((pageNum - 1) Mod 2))
threadList(count)
= New Thread(AddressOf New RenderingWorker(doc,
path).DoWork) count +=
1 pageNum +=
1 End While
For
i As Integer = 0 To count -
1 threadList(i).Start() Next For
i As Integer = 0 To count -
1 threadList(i).Join() Next End
While doc.Clear()
|
|
|