none
ADOBEDISTILLERX RRS feed

  • Question

  • Hey guys,

    I'm using the adobe distillerX import in my visual basic code, and specifically the .fileToPdf2() function. Basically a .xls file gets printed into .ps (postscript) file, then converted by the distiller to a pdf. On my test machine it seems to be working. Im running IIS with ASPNET. When I bring it over to the Web Server it seems to stall at the point of conversion from .ps to .pdf .. Ill paste my code below, but i really need some help with this one! Oh and I tried using the endTask() api function, however this makes my page crash.

        Public Function xls2PDF(ByVal myfile As String) As String
            'This function opens the given excel document in excel.
            'it then converts it using acrobat distiller to a pdf file.
            'it then returns the path of that saved pdf file.

            Try
                Dim docfile As String = ""
                docfile = Server.MapPath("Downloads") & "\" & Session.SessionID & "\" & myfile  'generates filepath
                Dim fso, xcl, psfile, objdoc, objfile, strfile ', pdf2, MyPDFDistiller
                Dim pdffile As String = ""
                fso = CreateObject("Scripting.FileSystemObject")


                xcl = CreateObject("Excel.Application")


                ' MyPDFDistiller = CreateObject("PdfDistiller.PDFDistiller1")
                Dim pdf As PdfDistiller6
                pdf = New PdfDistiller6

                ' pdf2 = CreateObject("PdfDistiller.PDFDistiller1")
                objfile = fso.GetFile(docfile)
                strfile = objfile.Path

                With xcl



                    .visible = False
                    Dim randomclass As New Random()
                    Dim RandomNumber As Integer
                    RandomNumber = randomclass.Next(0, 999) ' subject to collisions after approx squareRoot(1000) numbers
                    Session("randomnumber") = RandomNumber
                    psfile = fso.BuildPath(objfile.ParentFolder, _
                             fso.GetBaseName(objfile) & RandomNumber.ToString & ".ps")
                    ' psfile = Server.MapPath("downloads\") & Session.SessionID & "\" & Path.GetFileNameWithoutExtension(docfile) & RandomNumber.ToString & ".ps"
                    pdffile = fso.BuildPath(objfile.ParentFolder, _
                              fso.GetBaseName(objfile) & RandomNumber.ToString & ".pdf")
                    xcl.workbooks.open(strfile)
                    'make active wrkbook
                    objdoc = .ActiveWorkbook

                    .ActiveWindow.SelectedSheets.PrintOut(copies:=1, preview:=False, ActivePrinter:="Adobe PDF", _
                        printtofile:=True, collate:=True, prtofilename:=psfile)

                    'print to psfile.
                    '.printout(False, False, 0, psfile)


                    objdoc.close()
                    objdoc = Nothing
                    .Quit()
                End With

                Marshal.ReleaseComObject(xcl)
                xcl = Nothing

                pdf.FileToPDF2(psfile, pdffile, "", 0)

                If Not pdf Is Nothing Then
                    Marshal.ReleaseComObject(pdf)
                    pdf = Nothing
                End If

                Return pdffile

            Catch e As Exception
                File.WriteAllText(Server.MapPath("") & "\error.txt", e.Message)
                Return Nothing
            End Try
        End Function

    Tuesday, May 29, 2012 1:21 PM

Answers

All replies