Free Support Forum - aspose.com

Print a PDF from a Windows Service

Hello,

I would like to know how to print a PDF from a Windows service while specifying which printer to use.

I tried with PDFViewer, but apparently I have an error "Format string input invalid"

An idea, a procedure?

I try to open my pdf with Acrobat and it's ok. But, with PDFViewer, i have a error.

If I use PrintLargePdf => Error

If I use OpenPdfFile => Error

And always the same error : "Format invalid"

Hi Laurent,

I have tested this issue at my end and found no problem. I have used the following code:

PdfViewer viewer = new PdfViewer();
viewer.OpenPdfFile(common.Path("tmp86A.pdf"));

System.Drawing.Printing.PrinterSettings pset = new System.Drawing.Printing.PrinterSettings();
pset.Copies = 1; //specify number of copies
pset.PrinterName = "HP Officejet 4300 series"; // name of default printer to be used

viewer.PrintDocumentWithSettings(pset); //pass printer settings object to the method
viewer.ClosePdfFile();

Kindly try this code snippet at your end. You can also use this code in the windows service and specify the printer name as well. If you still find any problem, please do let us know.

Regards,

I do not find the "common.Path" I assume that the correction of my problem came from there, as my error is on the "OpenPdfFile"

The rest of your example is exactly what I do.

Hi Laurent,

I'm sorry for the inconvenience. In fact, common.Path has nothing to do with the actual code; that is my custom method to resolve the path to the test files. You can specify the path as OpenPdfFile(@"c:\test").

Please try it like this. If problem still persists then please make make a sample windows project with your code and share with us, so that we could have a look and find the problem.

Regards,

Ok, so I tried and it does not change my problem. My concern comes from the OpenPdfFile. I have the error when I try to call.

Hi,

Please share your code with us and the detailed error message as well. Kindly, mention which version of Aspose.Pdf.Kit for .NET you're using? Are you using a 32-bit or 64-bit machine? Which OS are you using.

As a matter of fact, in order to diagnose the problem we need to create the scenario at our end and reproduce the problem, so that we'll be able to fix it.

We really appreciate your cooperation.

Regards,

The file that I have provided as an attachment causes the error.
I am running Windows XP SP3 32 bits.
I'm using version 3.4.0.0 of Aspose.Pdf.Kit for. NET 2.0
I provided an example program that generates the same error (in french):
L'exception System.FormatException n'a pas été gérée
Message="Le format de la chaîne d'entrée est incorrect."
Source="Aspose.Pdf.Kit"
StackTrace:
à Aspose.Pdf.Kit.PdfViewer.OpenPdfFile(String filePath)
à WindowsApplication1.Form1.simpleButton1_Click(Object sender, EventArgs e) dans C:\Documents and Settings\Laurent Bensch\Mes documents\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplication1\Form1.cs:ligne 29
à System.Windows.Forms.Control.OnClick(EventArgs e)
à DevExpress.XtraEditors.BaseButton.OnClick(EventArgs e)
à DevExpress.XtraEditors.BaseButton.OnMouseUp(MouseEventArgs e)
à System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
à System.Windows.Forms.Control.WndProc(Message& m)
à DevExpress.Utils.Controls.ControlBase.WndProc(Message& m)
à System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
à System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
à System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
à System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
à System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
à System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
à System.Windows.Forms.Application.Run(Form mainForm)
à WindowsApplication1.Program.Main() dans C:\Documents and Settings\Laurent Bensch\Mes documents\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplication1\Program.cs:ligne 17
à System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
à System.Threading.ThreadHelper.ThreadStart()

I provided a new project as an example the first use of specific components, but the problem still exists in this version.

Hi,

Thank you very much for sharing the details. We'll look into the matter and update you the earliest possible.

We appreciate your patience.

Regards,

Hi,

I have again tested the issue at my end using the same specifications as yours and found no problem. Can you please try Aspose.Pdf.Kit 3.5.0.0 at your end? This is our latest version of Aspose.Pdf.Kit. I'm very sorry that you're having this problem. Nevertheless, if problem persists then, please do let us know, so that I'll be able to forward a request to our development team for further investigation.

We're sorry for the inconvenience.

Regards,

Hello,

I just tried with version 3.5.0.0 but I have apparently the same mistake. Apparently, this is a format error. Visual Studio refers to DateTime, so I wish to clarify that I use a French version of Windows with the locale french if it can help you during the tests.

L'exception System.FormatException n'a pas été gérée
Message="Le format de la chaîne d'entrée est incorrect."
Source="Aspose.Pdf.Kit"
StackTrace:
à Aspose.Pdf.Kit.PdfViewer.OpenPdfFile(String filePath)
à WindowsApplication1.Form1.button2_Click(Object sender, EventArgs e) dans C:\Documents and Settings\Laurent Bensch\Mes documents\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplication1\Form1.cs:ligne 38
à System.Windows.Forms.Control.OnClick(EventArgs e)
à System.Windows.Forms.Button.OnClick(EventArgs e)
à System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
à System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
à System.Windows.Forms.Control.WndProc(Message& m)
à System.Windows.Forms.ButtonBase.WndProc(Message& m)
à System.Windows.Forms.Button.WndProc(Message& m)
à System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
à System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
à System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
à System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
à System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
à System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
à System.Windows.Forms.Application.Run(Form mainForm)
à WindowsApplication1.Program.Main() dans C:\Documents and Settings\Laurent Bensch\Mes documents\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplication1\Program.cs:ligne 17
à System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
à System.Threading.ThreadHelper.ThreadStart()

Hi Laurent,

The 'French version' proved to be a valuable piece of information! In fact, I have reproduced the isse at my end by changing the culture info to French. I have logged this issue as PDFKITNET-9586 in our issue tracking system. Our team will be looking into the matter and you'll be updated via this forum as the issue is resolved.

Regards,

Pleased to have helped. I'm looking forward to the correction.

Hi,


I have the exact same problem. But… When I made a dummy app and created the class and method that we use in our main app the code works. But when it’s exectued in our main app we get the obove mentioned FormatException Error.

The class and method we use is:
public static void Print(string fileName, bool showDialog)
{
PdfViewer viewer = new PdfViewer();
try
{
viewer.OpenPdfFile(fileName);
if (showDialog)
{
viewer.PrintPageDialog = false;
viewer.PrintDocumentWithSetup();
}
else
{
viewer.PrintDocument();
}
}
finally
{
viewer.ClosePdfFile();
}
}

And the Exception ossurs on line: viewer.OpenPdfFile(fileName);
I have tested with fileName = @“c:\test.pdf”.

My developer enviroment is:
Windows 7 64 bit Swedish.
Visual Studio 2008 (c#)

Regards
Thomas Gyllencreutz

Hi Thomas,

Can you please share the sample project along with the PDF file you’re having problem with? We need to test the issue at our end.

We’re sorry for the inconvenience.
Regards,

The issues you have found earlier (filed as PDFNEWNET-9586) have been fixed in Aspose.Pdf for .NET 7.8.0update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan