Options

Automation server problem (Aut. that merges pdf files)

stiastastiasta Member Posts: 106
edited 2011-06-03 in NAV Three Tier
Hello!
I have tried to create a automation server using a tutorial i found here
http://www.gekko-software.nl/DotNet/Art03.htm

The trick here was to tick of the checkbox to register for COM.

I have tried this and saved 3 reports to PDF. Then i run the automation server on the Server itself. The result is that the Role based client disconnects and asks if it wants to reconnect.
The server is a x64 Windows 2008 server running a 3 tier arch. I have also registered the processor (in visual studio) for the automation server to be x64. The client itself is running on a x86 computer. I have an idea that the problem lies somewhere around the x64 and x86 compatibility.
Has anyone else been through this problem?

Here are some relevant screencaps and some code.
AUTOMATION SERVER CODE:
using System;
using System.Text;
using System.Runtime.InteropServices;
using iTextSharp.text.pdf;
using iTextSharp.text;
using System.IO;

namespace DyconPDFMerger
{
    [ComVisible(true)]
    [ProgId("DyconPDFMerger")]
    [ClassInterface(ClassInterfaceType.AutoDual)]
    public class Main
    {
        public String MergeFiles(string saveToFilename, string inputFileDirectory, string filesSeperatedBySemiColon)
        {
            String output = saveToFilename;
            string[] files = filesSeperatedBySemiColon.Split(';');
            for (int i = 0; i < files.Length; i++)
            {
                files[i] = inputFileDirectory + files[i];
            }
            
            Merge(saveToFilename, files);

            return output;
        }
        public String MergeFiles(string saveToFilename, string[] files)
        {
            String output = saveToFilename;

            Merge(saveToFilename, files);

            return output;
        }
        public void OpenFile(string filename)
        {
            if (string.IsNullOrEmpty(filename)) { throw new Exception("Empty filename"); }

            System.Diagnostics.Process.Start(@filename);
        }
        private void Merge(string destinationFile, string[] sourceFiles)
        {
            try
            {
                int f = 0;
                // we create a reader for a certain document
                PdfReader reader = new PdfReader(sourceFiles[f]);
                // we retrieve the total number of pages
                int n = reader.NumberOfPages;
                //Console.WriteLine("There are " + n + " pages in the original file.");
                // step 1: creation of a document-object
                Document document = new Document(reader.GetPageSizeWithRotation(1));
                // step 2: we create a writer that listens to the document
                PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(destinationFile, FileMode.Create));
                // step 3: we open the document
                document.Open();
                PdfContentByte cb = writer.DirectContent;
                PdfImportedPage page;
                int rotation;
                // step 4: we add content
                while (f < sourceFiles.Length)
                {
                    int i = 0;
                    while (i < n)
                    {
                        i++;
                        document.SetPageSize(reader.GetPageSizeWithRotation(i));
                        document.NewPage();
                        page = writer.GetImportedPage(reader, i);
                        rotation = reader.GetPageRotation(i);
                        if (rotation == 90 || rotation == 270)
                        {
                            cb.AddTemplate(page, 0, -1f, 1f, 0, 0, reader.GetPageSizeWithRotation(i).Height);
                        }
                        else
                        {
                            cb.AddTemplate(page, 1f, 0, 0, 1f, 0, 0);
                        }
                        //Console.WriteLine("Processed page " + i);
                    }
                    f++;
                    if (f < sourceFiles.Length)
                    {
                        reader = new PdfReader(sourceFiles[f]);
                        // we retrieve the total number of pages
                        n = reader.NumberOfPages;
                        //Console.WriteLine("There are " + n + " pages in the original file.");
                    }
                }
                // step 5: we close the document
                document.Close();
            }
            catch (Exception e)
            {
                string strOb = e.Message;
            }
        }

        private int CountPageNo(string strFileName)
        {
            // we create a reader for a certain document
            PdfReader reader = new PdfReader(strFileName);
            // we retrieve the total number of pages
            return reader.NumberOfPages;
        }


    }
}

C/SIDE CODE (PAGE):
CLEAR(SalesInvoiceReport);
CLEAR(DyconTimerReport);
CLEAR(DyconUtgiftReport);

SalesInvoiceReport.USEREQUESTFORM(FALSE);
DyconTimerReport.USEREQUESTFORM(FALSE);
DyconUtgiftReport.USEREQUESTFORM(FALSE);

EVALUATE(tempDate, '01' + COPYSTR(FORMAT(TODAY), 3, STRLEN(FORMAT(TODAY)))) ;
tempDate := CALCDATE('<+1M>', tempDate);
tempDate := CALCDATE('<-1D>', tempDate);

DyconTimer.SETFILTER(DyconTimer.Kunde, "Bill-to Customer No.");
DyconTimer.SETFILTER(DyconTimer.Arbeidsdato,
      '01' + COPYSTR(FORMAT(TODAY), 3, STRLEN(FORMAT(TODAY))) +
      '..' + 
      FORMAT(tempDate));

DyconUtgifter.SETFILTER(DyconUtgifter.Kunde, "Bill-to Customer No.");
DyconUtgifter.SETFILTER(DyconUtgifter.Innleggsdato, 
      '01' + COPYSTR(FORMAT(TODAY), 3, STRLEN(FORMAT(TODAY))) +
      '..' + 
      FORMAT(tempDate));

SalesInvoiceReport.SetFilt("No.");
DyconTimerReport.SetFilt("Bill-to Customer No.",
                            '01' + COPYSTR(FORMAT(TODAY), 3, STRLEN(FORMAT(TODAY))) +
                            '..' + 
                            FORMAT(tempDate));
DyconUtgiftReport.SetFilt("Bill-to Customer No.",
                            '01' + COPYSTR(FORMAT(TODAY), 3, STRLEN(FORMAT(TODAY))) +
                            '..' + 
                            FORMAT(tempDate));

Filenames[1] := 'C:\Temp\1.pdf';
Filenames[2] := 'C:\Temp\2.pdf';
Filenames[3] := 'C:\Temp\3.pdf';

SalesInvoiceReport.SAVEASPDF(Filenames[1]);
DyconTimerReport.SAVEASPDF(Filenames[2]);
DyconUtgiftReport.SAVEASPDF(Filenames[3]);

IF ISCLEAR(DyconPDFMerger) THEN
  CREATE(DyconPDFMerger, FALSE, FALSE);

tempText := DyconPDFMerger.MergeFiles('C:\Temp\output.pdf', 'C:\Temp\', '1.pdf;2.pdf;3.pdf');
1.png 37.5K
2.png 36.4K

Comments

  • Options
    stiastastiasta Member Posts: 106
    I solved the problem.
    1. Remove previous automation server
    2. Release as x86 (Since NAS and Client uses x86)
    3. Restart NAS
    4. Register New automation server
    5. Insert into code.
    6. Create the automation server using this command
    CREATE([automation server], FALSE, ISSERVICETIER);
    
Sign In or Register to comment.