Skip to main content
1-Visitor
March 22, 2022
Solved

Programmatically print file to PDF

  • March 22, 2022
  • 3 replies
  • 10073 views

We're thinking of using MathCAD Prime. One of our key requirements is to be able to programmatically print MathCAD Prime files to PDF (i.e. with no user interaction). I know this is possible with MathCAD 15 (you automate printing to PDF from the commandline with MathCAD 15 by adding the "-p" option after the executable and before the filename), but I cannot see how to do it with MathCAD Prime. I've been looking through the API documentation: https://support.ptc.com/help/mathcad/r7.0/en/index.html#page/PTC_Mathcad_Help%2Fmathcad_and_automation_api.html%23. It says that you can print MathCAD Prime worksheets, but I cannot actually find this documented anywhere.

Please could you let me know how to do this, either from the API or from the commandline?

Thanks for your help!

Best answer by MichaelW

I fear about related functionality up to Mathcad 15 (command mathcad.exe -p test.xmcd๐Ÿ˜ž this is not part of Mathcad Prime functionality

  • CS361245 How to call Mathcad from command to print a specific worksheet

Workaround: API functionality to save as PDF is introduced with Mathcad Prime 6.0

  • CS315481 for more information about how to print a worksheet as PDF through API
  • Details:
    • Use the API method:   IMathcadPrimeWorksheet3::SaveAs(string path)
    • Sample code:

Ptc.MathcadPrime.Automation.ApplicationCreator mathcad = new Ptc.MathcadPrime.Automation.ApplicationCreator();
           IMathcadPrimeWorksheet3 mathcadPrimeWorksheet = mathcad.Open("d:\\test.mcdx") as IMathcadPrimeWorksheet3;
         
           if (mathcadPrimeWorksheet != null)
           {
               mathcadPrimeWorksheet.SaveAs("d:\\test.pdf");
              //Just change the extension of the file here to print to other formats such as RTF.                
               mathcadPrimeWorksheet.Close(SaveOption.spDiscardChanges);
           }

 

  • Note:
    • Saving with PDF format is supported since Mathcad Prime 6.0.
    • Users can use Object Browser from Visual studio to see the list of all Mathcad Prime APIs, by loading the file Ptc.MathcadPrime.Automation.tlb from Mathcad Prime installation directory.
  • Related: CS338281 [Knowledge hub] Customization with Mathcad Prime

3 replies

18-Opal
March 23, 2022

I dont know the but perhaps this:

https://community.ptc.com/t5/PTC-Mathcad/Batch-Printing/td-p/209960 may have some answers.

 

https://www.fcoder.com/how-to/printing-video-tutorials

Print Conductor allows you to seamlessly print an unlimited number of CAD drawings including MathCAD, MathCAD Prime and Solid Edge drawings, multi-page DWFX drawings, and more. No CAD software required!

1-Visitor
March 25, 2022

Hi,

 

Thanks for your response.

  • The thread that you mention is for MathCAD 14 & 15, not MathCAD Prime, so it's not very relevant.
    • To automate publishing MathCAD 15 I ended up using the -p option and an old version of PDFCreator to print to a specific location with a specific naming convention. Once the PDF has been generated I then force close MathCAD 15 to get around the problem with the error message.
    • The other suggestion in that thread is AutoIt, which I have tried. It requires the window to be in focus to work and it is very fiddly to get all the codes for the click areas. It is flakey and does not always work. I ended up spending a lot of time building a solution that uses it, only to be disappointed and have to throw it away. I would not recommend it to anyone.
  •  Print Conductor does sound cool, but it seems like it still requires user intervention. If it can be automated then I would love to hear more about it.

 

What I'm really asking, is there a way to automate printing MathCAD Prime? Is there a -p option or is there a scripting language, e.g. VBscript, which you can use to print MathCAD Prime?

MichaelW17-PeridotAnswer
17-Peridot
April 1, 2022

I fear about related functionality up to Mathcad 15 (command mathcad.exe -p test.xmcd๐Ÿ˜ž this is not part of Mathcad Prime functionality

  • CS361245 How to call Mathcad from command to print a specific worksheet

Workaround: API functionality to save as PDF is introduced with Mathcad Prime 6.0

  • CS315481 for more information about how to print a worksheet as PDF through API
  • Details:
    • Use the API method:   IMathcadPrimeWorksheet3::SaveAs(string path)
    • Sample code:

Ptc.MathcadPrime.Automation.ApplicationCreator mathcad = new Ptc.MathcadPrime.Automation.ApplicationCreator();
           IMathcadPrimeWorksheet3 mathcadPrimeWorksheet = mathcad.Open("d:\\test.mcdx") as IMathcadPrimeWorksheet3;
         
           if (mathcadPrimeWorksheet != null)
           {
               mathcadPrimeWorksheet.SaveAs("d:\\test.pdf");
              //Just change the extension of the file here to print to other formats such as RTF.                
               mathcadPrimeWorksheet.Close(SaveOption.spDiscardChanges);
           }

 

  • Note:
    • Saving with PDF format is supported since Mathcad Prime 6.0.
    • Users can use Object Browser from Visual studio to see the list of all Mathcad Prime APIs, by loading the file Ptc.MathcadPrime.Automation.tlb from Mathcad Prime installation directory.
  • Related: CS338281 [Knowledge hub] Customization with Mathcad Prime
4-Participant
August 10, 2023

Hi

 

I found this topic very interesting so used my (little) programing skills to write simple GUI program for my own use, that allows batch printing of MCDX files into PDF and RTF files. Works quite fine, it processes as many files as you load into it (as long as you do not mess with it on purpose) ๐Ÿ˜€

 

Anyway, can share it from my side, but I am not sure what about legal thing of this. 

It is single exe file, that was buit on my computer and as I understand it contains MathCAD API *.dll burnt into it (which is not mine, but PTC owns it). So is here anyone from @unknown PTC MathCAD that can say something about legal issue of sharing such exe for the comunity?

 

It hasn't been written for commercial purposes, just to speed up work and to learn C#, so I do not guarantee that it will work once I share it.

 

2023-08-10 09_12_18-Desktop.png

4-Participant
August 11, 2023

Couldn't edit my previous post, so adding reply.

 

I figured out how to not 'bake' Mathcad *.dll into the app, so sharing the app with you. Now app uses link to the installation directory and checks it every time you want to print.

PS: read the readme file first. If it will not work. Probably you installed the MathCAD not using default directory, so you must provide proper path in 'config' file.

Good luck!

3-Newcomer
January 22, 2024

Thanks for the tool, but unfortunately the tool crashes (see error message below) despite the .dll is present and the .config file is correct. 

Does anybody have the same problem or - even better - knows a solution?

 

Informationen รผber das Aufrufen von JIT-Debuggen
anstelle dieses Dialogfelds finden Sie am Ende dieser Meldung.

************** Ausnahmetext **************
System.Runtime.InteropServices.COMException (0x80004004): Vorgang abgebrochen (Ausnahme von HRESULT: 0x80004004 (E_ABORT))
at Ptc.MathcadPrime.Automation.IMathcadPrimeWorksheet3.SaveAs(String fileName)
at Batch_MathCAD_Printer.MainForm.printFile(String sourceFileName, String sourceFilePath)
at Batch_MathCAD_Printer.MainForm.ExecuteBatch()
at Batch_MathCAD_Printer.MainForm.btnPrint_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, WM msg, IntPtr wparam, IntPtr lparam)


************** Geladene Assemblys **************
System.Private.CoreLib
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.12/System.Private.CoreLib.dll.
----------------------------------------
Batch MathCAD Printer
Assembly-Version: 1.0.0.0.
Win32-Version: n/v.
CodeBase: .
----------------------------------------
System.Runtime
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.12/System.Runtime.dll.
----------------------------------------
System.Windows.Forms
Assembly-Version: 6.0.2.0.
Win32-Version: 6.0.1222.56810.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.WindowsDesktop.App/6.0.12/System.Windows.Forms.dll.
----------------------------------------
System.ComponentModel.Primitives
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.12/System.ComponentModel.Primitives.dll.
----------------------------------------
System.Windows.Forms.Primitives
Assembly-Version: 6.0.2.0.
Win32-Version: 6.0.1222.56810.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.WindowsDesktop.App/6.0.12/System.Windows.Forms.Primitives.dll.
----------------------------------------
System.Runtime.InteropServices
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.12/System.Runtime.InteropServices.dll.
----------------------------------------
System.Drawing.Primitives
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.12/System.Drawing.Primitives.dll.
----------------------------------------
System.Collections.Specialized
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.12/System.Collections.Specialized.dll.
----------------------------------------
System.Threading
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.12/System.Threading.dll.
----------------------------------------
System.Diagnostics.TraceSource
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.12/System.Diagnostics.TraceSource.dll.
----------------------------------------
System.Collections
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.12/System.Collections.dll.
----------------------------------------
System.Drawing.Common
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.WindowsDesktop.App/6.0.12/System.Drawing.Common.dll.
----------------------------------------
Microsoft.Win32.Primitives
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.12/Microsoft.Win32.Primitives.dll.
----------------------------------------
System.ComponentModel.EventBasedAsync
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.12/System.ComponentModel.EventBasedAsync.dll.
----------------------------------------
System.Threading.Thread
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.12/System.Threading.Thread.dll.
----------------------------------------
Accessibility
Assembly-Version: 4.0.0.0.
Win32-Version: 6.0.1222.56810.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.WindowsDesktop.App/6.0.12/Accessibility.dll.
----------------------------------------
System.ComponentModel.TypeConverter
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.12/System.ComponentModel.TypeConverter.dll.
----------------------------------------
System.Numerics.Vectors
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.12/System.Numerics.Vectors.dll.
----------------------------------------
Microsoft.Win32.SystemEvents
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.WindowsDesktop.App/6.0.12/Microsoft.Win32.SystemEvents.dll.
----------------------------------------
System.Collections.Concurrent
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.12/System.Collections.Concurrent.dll.
----------------------------------------
System.ComponentModel
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.12/System.ComponentModel.dll.
----------------------------------------
System.Memory
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.12/System.Memory.dll.
----------------------------------------
System.Resources.Extensions
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.WindowsDesktop.App/6.0.12/System.Resources.Extensions.dll.
----------------------------------------
System.Drawing
Assembly-Version: 6.0.2.0.
Win32-Version: 6.0.1222.56810.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.WindowsDesktop.App/6.0.12/System.Drawing.dll.
----------------------------------------
System.ObjectModel
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.12/System.ObjectModel.dll.
----------------------------------------
System.Linq
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.12/System.Linq.dll.
----------------------------------------
System.Collections.NonGeneric
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.12/System.Collections.NonGeneric.dll.
----------------------------------------
System.Runtime.CompilerServices.Unsafe
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.12/System.Runtime.CompilerServices.Unsafe.dll.
----------------------------------------
System.Configuration.ConfigurationManager
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.WindowsDesktop.App/6.0.12/System.Configuration.ConfigurationManager.dll.
----------------------------------------
System.Runtime.InteropServices.RuntimeInformation
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.12/System.Runtime.InteropServices.RuntimeInformation.dll.
----------------------------------------
System.Private.Uri
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.12/System.Private.Uri.dll.
----------------------------------------
System.Diagnostics.Process
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.12/System.Diagnostics.Process.dll.
----------------------------------------
System.Xml.ReaderWriter
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.12/System.Xml.ReaderWriter.dll.
----------------------------------------
System.Private.Xml
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.12/System.Private.Xml.dll.
----------------------------------------
System.Net.WebClient
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.12/System.Net.WebClient.dll.
----------------------------------------
System.Text.Encoding.Extensions
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.12/System.Text.Encoding.Extensions.dll.
----------------------------------------
Ptc.MathcadPrime.Automation
Assembly-Version: 9.0.0.0.
Win32-Version: 9.0.0.0.
CodeBase: file:///C:/Program%20Files/PTC/Mathcad%20Prime%209.0.0.0/Ptc.MathcadPrime.Automation.dll.
----------------------------------------
mscorlib
Assembly-Version: 4.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.12/mscorlib.dll.
----------------------------------------
System.Runtime.Loader
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.12/System.Runtime.Loader.dll.
----------------------------------------
System.Windows.Forms.resources
Assembly-Version: 6.0.2.0.
Win32-Version: 6.0.1222.56810.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.WindowsDesktop.App/6.0.12/de/System.Windows.Forms.resources.dll.
----------------------------------------
System.Diagnostics.StackTrace
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.12/System.Diagnostics.StackTrace.dll.
----------------------------------------
System.Reflection.Metadata
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.12/System.Reflection.Metadata.dll.
----------------------------------------
System.Collections.Immutable
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.12/System.Collections.Immutable.dll.
----------------------------------------
System.Diagnostics.FileVersionInfo
Assembly-Version: 6.0.0.0.
Win32-Version: 6.0.1222.56807.
CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.12/System.Diagnostics.FileVersionInfo.dll.
----------------------------------------

************** JIT-Debuggen **************

 

7-Bedrock
January 31, 2026

Our team was running into this issue, and we finally got frustrated enough to build out our own app. 

 

We built an app that lets you drag and drop 100+ MathCAD Prime calculations and batch-publish them to PDF.  You can even choose to get individual PDFs or a single binder at the end with all files combined.  We even built in a progress bar with estimated time remaining, an error log for troubleshooting, and, best of all, background processing.  This means that instead of losing time while files are being published to PDF, our team can start the process and continue using MathCAD Prime on other calculations.  

 

This is a tool that we would have purchased if it existed, but since it didn't, we built it for ourselves and figured we'd share it with the community.  Link below if anyone's interested.  Happy to answer any questions.

 

https://ssellc.gumroad.com/l/mathcadprime