Click here to Skip to main content
15,922,427 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everybody,
in Visual Studio I am writing a program in C# to load and print a CAD file in PDF using the Thinkdesign program dlls.
I can load the drawing, set the PDF printer with its orientation parameters, and x y dimensions.
The problem is that nothing is seen in the produced PDF file.
Can someone help me?
Thank you.

This is the program I wrote:

What I have tried:

C#
//SERVE PER IMPOSTARE LA STAMPANTE PREDEFINITA
        public static class PrinterClass
        {
            [DllImport("winspool.drv", CharSet = CharSet.Auto, SetLastError = true)]
            public static extern bool SetDefaultPrinter(string Printer);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //set default printer
            PrinterClass.SetDefaultPrinter("ThinkDesign Printer");

            //printFont = new Font("Arial", 10);
            PrintDocument pd = new PrintDocument();

            PaperSize paperSize = new PaperSize("Test", 800, 1200);
            paperSize.RawKind = (int)PaperKind.Custom;

            pd.DefaultPageSettings.PaperSize = paperSize;
            pd.DefaultPageSettings.Landscape = true;
            pd.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);

            pd.PrintPage += new PrintPageEventHandler(this.stampaPdf);

            pd.Print();// Print the document.
        }

        public void stampaPdf(object sender, PrintPageEventArgs e)
        {
            TD_APPLLib.Application ifAppl = (TD_APPLLib.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Td_appl.Application");

            ifAppl.Visible = true;

            TD_APPLLib.Document docCorrente = ifAppl.Documents.Open(@"C:\Temp\1473-mj.e2");
            TD_APPLLib.Document ifCurrDoc = ifAppl.Documents.Add();
            docCorrente.Visible = true;
        }
Posted
Updated 16-Mar-22 2:24am
v2

You don't appear to add any information to the actual printer in your PrintPage hander stampaPdf and we have no idea where the date should come from or where it should go on your page(s), and no access to your ThinkDesign code (whatever that might be).
Normally, the PrintPage handler would "draw" the page on the supplied Graphics context (via the PrintPageEventArgs parameter) and yoru code ignores that completely.

It's possible that the DLL's you are using operate in a totally different manner, but we have no access to them so we can't tell if this approach is even capable of working! I would suggest that you go back to where you got the DLLs from, and see if they have an API description or a support contact as we can't help you based on what little information we have been given.
 
Share this answer
 
Comments
Member 14574032 16-Mar-22 8:57am    
Thanks for your prompt reply.
Actually, the dll has a function that takes care of printing and works partially. Although I have set the print format dimensions, x and y, the print format does not reset, remaining the default one, for example A4 ...
This is the complete procedure:

public void stampaPdf(object sender, PrintPageEventArgs e)
{
TD_APPLLib.Application ifAppl = (TD_APPLLib.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Td_appl.Application");
ifAppl.Visible = true;
TD_APPLLib.Document docCorrente = ifAppl.Documents.Open(@"C:\Temp\1473-mj.e2");
TD_APPLLib.Document ifCurrDoc = ifAppl.Documents.Add();
docCorrente.Visible = true;


TD_APPLLib.IPrintSetupManager stampa = (TD_APPLLib.IPrintSetupManager)System.Runtime.InteropServices.Marshal.GetActiveObject("Td_appl.Application");
//impostare come predefinita la stampante PDF
stampa.PrintMode = TD_APPLLib.TD_PRINT_MODE.TD_PRTM_PLOT;
stampa.Printer = "ThinkDesign Printer";
stampa.Orientation = TD_APPLLib.TD_PRINT_FORM_ORIENTATION.TD_PORTRAIT;
stampa.FitToPage = true;
stampa.Form2 = TD_APPLLib.TD_PRINT_FORM.TD_CUSTOM_FRM;
stampa.Scale = 5;
stampa.SizeX = 500;
stampa.SizeY = 500;
stampa.Print("VT_EMPTY");
}

However I believe that I will take your advice and ask their technical support. Thank you
Hi,I have the same problem with Thinkdesign: convert in PDF or DWG a lot of .e2 document.
did you find a way with your code?

Could you share how, please?
regards,
 
Share this answer
 
Comments
Dave Kreskowiak 5-Oct-23 18:42pm    
You posted your question as a solution to an old question. This will do nothing but get your question ignored.

You also didn't read Solution 1. This site cannot support every .DLL library in existence and Solution 1 tells you who you hasve to contact for support on the libraries.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900