PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.de/

multiple multi page tiffs to pdf
http://forum.pdfsharp.de/viewtopic.php?f=2&t=880
Page 1 of 1

Author:  nguye1r [ Mon Sep 21, 2009 11:25 pm ]
Post subject:  multiple multi page tiffs to pdf

Hi,
I'm using pdfsharp version 1.3.

I'm trying to convert multiple multi page tiffs into a single pdf with bookmarks. The code is working, but it take about 3 minutes to convert 225 pages.
Is there anyway for me to increase the speed?

Here are my code:


Dim wid As Integer
Dim max As Integer
Dim hei As Integer
Dim sc As Double
Dim doc As New PdfDocument()
Dim p As Integer = 0
Dim temp As String = rec(0, 1)
Dim outline As PdfOutline
For j = 0 To i - 1
Try
Dim timage As System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath(rec(j, 0)))
Dim index As guid = timage.FrameDimensionsList(0)
Dim dimension As FrameDimension = New FrameDimension(index)
Dim pagecount As Integer = timage.GetFrameCount(dimension)
For k = 0 To pagecount - 1
timage.SelectActiveFrame(dimension, k)
wid = timage.Width
hei = timage.Height
If wid > hei Then
max = wid
Else
max = hei
End If
If max > 1000 Then
sc = (1000 / max)
wid = CInt(wid * sc)
hei = CInt(hei * sc)
End If
Dim page As New PdfPage()
Dim image As XImage = XImage.FromGdiPlusImage(timage)
page.Width = wid
page.Height = hei
doc.Pages.Add(page)
Dim xgr As XGraphics = XGraphics.FromPdfPage(doc.Pages(p))
If p = 0 Or temp <> rec(j, 1) Then
outline = doc.Outlines.Add(rec(j, 1), page, True, PdfOutlineStyle.Bold, XColors.Black)
temp = rec(j, 1)
End If
If k = 0 Then
outline.Outlines.Add(rec(j, 2), page, True)
End If
p += 1
xgr.DrawImage(image, 0, 0, wid, hei)
xgr.Dispose()
Next
timage.Dispose()
Catch ex As Exception
prog.text += ex.message & "<br/> Failed to merge " & rec(j, 1) & " on " & rec(j, 2) & "<br/>"
End Try
Next
doc.Save(Server.MapPath("upload/combine.pdf"))
doc.Close()

Author:  Thomas Hoevel [ Tue Sep 22, 2009 7:44 am ]
Post subject:  Re: multiple multi page tiffs to pdf

Hi!
nguye1r wrote:
The code is working, but it take about 3 minutes to convert 225 pages.
Is there anyway for me to increase the speed?

Without knowing your task, your TIFF files, or your PC: what can I say?

I expect JPEG files to be processed faster.

Reducing the resolution of the TIFF files will probably also speed up the conversion.

Author:  nguye1r [ Tue Sep 22, 2009 5:05 pm ]
Post subject:  Re: multiple multi page tiffs to pdf

Hello,
Thanks for replying.

my task is to convert a bunch of multipage tiffs into a single pdf with bookmarks. If the tiffs are bigger than a certain size I need to scale them to a consistent size.

I'm using Microsoft Windows Server 2003.
Intel(R) Xeon(TM) CPU 3.20GHz
3.20 GHZ, 2.00 GB of RAM
System Model is ProLiant DL360 G3

Unfortunately I can not control how big the input tiffs will be

Author:  Thomas Hoevel [ Wed Sep 23, 2009 8:42 am ]
Post subject:  Re: multiple multi page tiffs to pdf

Hi!
nguye1r wrote:
If the tiffs are bigger than a certain size I need to scale them to a consistent size.

PDFsharp takes the images as they are. A 4 megapixel photo drawn on 1" by 1" will have about 2000 dpi.
If 300 dpi are sufficient, it's up to you to call GDI+ to shrink the image (from 2000x2000 down to 300x300 in this example).

This shrinking will take some time, but it'll save some time while the PDF is being written - and the final PDF should be smaller.
That's what I mean with "reducing the resolution"

Author:  nguye1r [ Thu Sep 24, 2009 11:13 pm ]
Post subject:  Re: multiple multi page tiffs to pdf

Thanks for the help

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/