You are viewing limited content. For full access, please sign in.

Question

Question

Pdf to tiff via sdk and tiff to pdf its possible ?

asked on January 20, 2014

 thank for help

0 0

Answer

SELECTED ANSWER
replied on January 21, 2014

The Laserfiche SDK does not have any tools in it to convert PDF to TIFF.  But that does not mean that it can not be done, but rather that it will require another tool be used to do the conversion and then SDK used to import the resulting TIFF.

 

There are many PDF to TIFF tools available and most have licensing that requires purchase for commercial use.  Search the web to find one that best suits your needs.

 

I like to use GhostScripts (http://www.ghostscript.com/download/gsdnld.html) for this job.  Download the 32 bit version (I have been reading reports that the x64 version is still not stable).

 

In a VB project, create a class named Ghostscript

Imports System.Runtime.InteropServices

Public Class Ghostscript

    <StructLayout(LayoutKind.Sequential)> _
    Public Structure GSVersion
        Public product As String
        Public copyright As String
        Public revision As Integer
        Public revisionDate As Integer
    End Structure

    <DllImport("gsdll32.dll", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.StdCall)> _
    Private Shared Function gsapi_revision(ByRef version As GSVersion, ByVal len As Integer) As Integer
    End Function

    <DllImport("gsdll32.dll", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.StdCall)> _
    Private Shared Function gsapi_new_instance(ByRef pinstance As System.IntPtr, ByVal handle As System.IntPtr) As Integer
    End Function

    <DllImport("gsdll32.dll", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.StdCall)> _
    Private Shared Function gsapi_init_with_args(ByVal pInstance As IntPtr, ByVal argc As Integer, <[In](), Out()> ByVal argv As String()) As Integer
    End Function

    <DllImport("gsdll32.dll", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.StdCall)> _
    Private Shared Function gsapi_exit(ByVal instance As IntPtr) As Integer
    End Function

    <DllImport("gsdll32.dll", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.StdCall)> _
    Private Shared Sub gsapi_delete_instance(ByVal pinstance As System.IntPtr)
    End Sub

    Public Shared Sub getVersion(ByRef version As GSVersion)
        gsapi_revision(version, Marshal.SizeOf(version))
    End Sub

    Public Shared Sub run(ByVal argv As String())
        Dim inst As IntPtr = IntPtr.Zero
        Dim code As Integer = gsapi_new_instance(inst, IntPtr.Zero)
        If code <> 0 Then
            Return
        End If
        code = gsapi_init_with_args(inst, argv.Length, argv)
        gsapi_exit(inst)
        gsapi_delete_instance(inst)
    End Sub

End Class

Then to convert a PDF to TIFF G4, call it like this

    Private Sub ToTIFFG4(ByVal sPDFPath As String, ByVal sOutputFolder As String)
        If Not String.IsNullOrEmpty(sPDFPath) Then
            If Not String.IsNullOrEmpty(sOutputFolder) Then
                If IO.File.Exists(sPDFPath) Then
                    Try
                        If Not IO.Directory.Exists(sOutputFolder) Then
                            IO.Directory.CreateDirectory(sOutputFolder)
                        End If
                        Dim fi As IO.FileInfo = New IO.FileInfo(sPDFPath)
                        Dim sOutName As String = IO.Path.Combine(sOutputFolder, fi.Name.Replace(fi.Extension, "_G4.tiff"))
                        If IO.File.Exists(sOutName) Then
                            IO.File.Delete(sOutName)
                        End If
                        Dim gsVer As New Ghostscript.GSVersion()
                        Ghostscript.getVersion(gsVer)
                        If gsVer.revision > 900 Then
                            Dim argv As String() = {"PDF2TIFF", "-q", "-sOutputFile=" & sOutName, "-dNOPAUSE", "-dBATCH", "-P-", _
                         "-dSAFER", "-sDEVICE=tiffg4", "-r300", sPDFPath}
                            Ghostscript.run(argv)
                        End If
                    Catch ex As Exception
                        MsgBox(ex.Message)
                    End Try
                End If
            End If
        End If
    End Sub

NOTE: Make sure after you install Ghostscripts, you copy the gs dll (Example: "C:\Program Files (x86)\gs\gs9.10\bin\gsdll32.dll") into your project (the dll must be in the same folder as the exe or its location included in the system path).

5 0

Replies

replied on February 19, 2014

We use a product by SautinSoft called PDFFocus which has worked well as a solution.  I think it runs about $500, but it will handle conversions to multiple formats and works quickly/efficiently.

 

For example:

 

Dim pdfFocus As SautinSoft.PdfFocus = New SautinSoft.PdfFocus
pdfFocus.Serial = "serialno"

pdfFocus.OpenPdf("\\pathtofile\filename.pdf")

pdfFocus.ImageOptions.Dpi = 300
pdfFocus.ToMultipageTiff("\\saveloc\filename.tiff")

1 0
replied on January 21, 2014

ok thanks

0 0
replied on March 7, 2014

Ok. thanks.

0 0
replied on June 22, 2016

how do you integrate this to laserfiche workflow?

0 0
replied on June 24, 2016

There are several ways, but the way I like best is this:

Create a command line utility that takes an Entry ID as an argument and then logs into Laserfiche and converts the document with the passed in ID and sets a specific field.  Then create a workflow that calls the external app and passes the Entry ID in the command line.  Then the workflow waits for the field specified field to equal the value that means it is completed with the conversion before it moves to the next step.

 

Alternatively, you can create your own workflow activity or use a workflow script to do the same thing.

0 0
replied on January 25, 2018

Hi Bert,

 

I tried your solution but I have an error with the SDK (sorry i'm not good with this)

 

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Data.SqlClient
Imports System.Text
Imports System.Runtime.InteropServices

Namespace WorkflowActivity.Scripting.Script
    '''<summary>
    '''Offre une ou plusieurs méthodes qui peuvent être exécutées au moment de l'exécution de l'activité de scriptage du flux de travail.


Public Class Ghostscript

    <StructLayout(LayoutKind.Sequential)> _
    Public Structure GSVersion
        Public product As String
        Public copyright As String
        Public revision As Integer
        Public revisionDate As Integer
    End Structure

    <DllImport("gsdll32.dll", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.StdCall)> _
    Private Shared Function gsapi_revision(ByRef version As GSVersion, ByVal len As Integer) As Integer
    End Function

    <DllImport("gsdll32.dll", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.StdCall)> _
    Private Shared Function gsapi_new_instance(ByRef pinstance As System.IntPtr, ByVal handle As System.IntPtr) As Integer
    End Function

    <DllImport("gsdll32.dll", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.StdCall)> _
    Private Shared Function gsapi_init_with_args(ByVal pInstance As IntPtr, ByVal argc As Integer, <[In](), Out()> ByVal argv As String()) As Integer
    End Function

    <DllImport("gsdll32.dll", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.StdCall)> _
    Private Shared Function gsapi_exit(ByVal instance As IntPtr) As Integer
    End Function

    <DllImport("gsdll32.dll", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.StdCall)> _
    Private Shared Sub gsapi_delete_instance(ByVal pinstance As System.IntPtr)
    End Sub

    Public Shared Sub getVersion(ByRef version As GSVersion)
        gsapi_revision(version, Marshal.SizeOf(version))
    End Sub

    Public Shared Sub run(ByVal argv As String())
        Dim inst As IntPtr = IntPtr.Zero
        Dim code As Integer = gsapi_new_instance(inst, IntPtr.Zero)
        If code <> 0 Then
            Return
        End If
        code = gsapi_init_with_args(inst, argv.Length, argv)
        gsapi_exit(inst)
        gsapi_delete_instance(inst)
    End Sub

End Class

Private Sub ToTIFFG4(ByVal sPDFPath As String, ByVal sOutputFolder As String)
    If Not String.IsNullOrEmpty(sPDFPath) Then
        If Not String.IsNullOrEmpty(sOutputFolder) Then
            If IO.File.Exists(sPDFPath) Then
                Try
                    If Not IO.Directory.Exists(sOutputFolder) Then
                        IO.Directory.CreateDirectory(sOutputFolder)
                    End If
                    Dim fi As IO.FileInfo = New IO.FileInfo(sPDFPath)
                    Dim sOutName As String = IO.Path.Combine(sOutputFolder, fi.Name.Replace(fi.Extension, "_G4.tiff"))
                    If IO.File.Exists(sOutName) Then
                        IO.File.Delete(sOutName)
                    End If
                    Dim gsVer As New Ghostscript.GSVersion()
                    Ghostscript.getVersion(gsVer)
                    If gsVer.revision > 900 Then
                        Dim argv As String() = {"PDF2TIFF", "-q", "-sOutputFile=" & sOutName, "-dNOPAUSE", "-dBATCH", "-P-", _
                     "-dSAFER", "-sDEVICE=tiffg4", "-r300", sPDFPath}
                        Ghostscript.run(argv)
                    End If
                Catch ex As Exception
                    MsgBox(ex.Message)
                End Try
            End If
        End If
    End If
End Sub

End Namespace

It said "Invalid statement in a namespace"

0 0
replied on January 21, 2014

Please do not post the same question in multiple threads.

0 1
You are not allowed to follow up in this post.

Sign in to reply to this post.