Print without a UI

PDF-XChange Viewer SDK for Developer's
(ActiveX and Simple DLL Versions)

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Post Reply
promisekey
User
Posts: 30
Joined: Tue Apr 17, 2012 8:55 pm

Print without a UI

Post by promisekey »

I am evaluating the PDF Exchange SDK tools and need to know if there is a way to Open a PDF and print it without displaying it. This function will be built into a custom dll, so it will not have any user interface. A VB6 example would be useful. Thanks.
Walter-Tracker Supp
User
Posts: 381
Joined: Mon Jun 13, 2011 5:10 pm

Re: Print without a UI

Post by Walter-Tracker Supp »

Sure, just use the simple viewer DLL.

Load the PDF with the function:

PXCV_ReadDocumentW()

Print it with:

PXCV_DrawPageToDC(), passing the flag pxvrm_Printing to the "RenderTarget" member of PXV_CommonRenderParameters. See the PDF-XChange Viewer Simple DLL documentation for more details. Note that you have to create a printer device context using standard windows API calls. PXCV_DrawPageToDC() will send the page to that DC.

See the example project in this folder (exact location obviously depends on your installation) for more complete code:

C:\Program Files\Tracker Software\PDF-XChange Viewer SDK\Examples\VBExamples\PXCView36

In particular, frmMain.frm -> Private Sub PrintPdfFile(ByVal hParentWnd As Long) shows how to do this. You may have to play with the windows API calls to pick your favourite printer, display (or not display) printer options, etc, but that part is up to you.


-Walter
promisekey
User
Posts: 30
Joined: Tue Apr 17, 2012 8:55 pm

Re: Print without a UI

Post by promisekey »

I was able to get the printing to work in the non-visual interface. We would like to have more options like, removing annotations, locking merge fields, and rasterizing the PDF. The ActiveX version does not work in the non-visual environment and the simple DLL is limited to viewing and printing. Do you have any other products that work in the non-visual environment that have more of the options we want to use?
User avatar
John - Tracker Supp
Site Admin
Posts: 5219
Joined: Tue Jun 29, 2004 10:34 am
Location: United Kingdom
Contact:

Re: Print without a UI

Post by John - Tracker Supp »

There is no barrier to using the ActiveX in the way required - if I understand you correctly - simply place the Ax on the form and hide it and use the available funcitons and methods to do as required...
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com
Walter-Tracker Supp
User
Posts: 381
Joined: Mon Jun 13, 2011 5:10 pm

Re: Print without a UI

Post by Walter-Tracker Supp »

In addition to the solution John mentioned above, the PDF-XChange PRO SDK or PDF Tools SDK may also have what you are looking for; please review the features here and let us know if you have questions:

https://www.pdf-xchange.com/product/pdf-tools-sdk

https://www.pdf-xchange.com/product ... ge-pro-sdk


promisekey wrote:I was able to get the printing to work in the non-visual interface. We would like to have more options like, removing annotations, locking merge fields, and rasterizing the PDF. The ActiveX version does not work in the non-visual environment and the simple DLL is limited to viewing and printing. Do you have any other products that work in the non-visual environment that have more of the options we want to use?
promisekey
User
Posts: 30
Joined: Tue Apr 17, 2012 8:55 pm

Re: Print without a UI

Post by promisekey »

The DLL I am creating is totally non-visual. It needs to do thinks like:
1. Open a PDF
2. Remove certain types of Annotations like Sticky Notes/Stamps/Highlight/Text Boxes
3. Lock Merge Fields
4. Save any of the above changes
5. Print the PDF
User avatar
John - Tracker Supp
Site Admin
Posts: 5219
Joined: Tue Jun 29, 2004 10:34 am
Location: United Kingdom
Contact:

Re: Print without a UI

Post by John - Tracker Supp »

Using the Viewer ActiveX and setting to a hidden state - all the items you outline can be done using Javsacript.

As to creating your own dll - we have no specific advice there and I am not sure what the benefit and purpose of that is, and also whether that would be allowed under the terms of the license - this would very much depend upon your intended use.
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com
promisekey
User
Posts: 30
Joined: Tue Apr 17, 2012 8:55 pm

Re: Print without a UI

Post by promisekey »

We have some Web services and other distribution programs that open a PDF and perform these functions prior to printing or emailing it. We can convert a few of these areas to use a hidden visual control, but in the case of the Web service, it needs to be completely non-visual.
User avatar
John - Tracker Supp
Site Admin
Posts: 5219
Joined: Tue Jun 29, 2004 10:34 am
Location: United Kingdom
Contact:

Re: Print without a UI

Post by John - Tracker Supp »

If you cannot use the hidden control - then you will have to use the PDF-Tools SDK options and I am afraid these are currently less advanced in many cases and where functionality does exist as required - it may well not be as easy to use and require more coding on your part. These are currently being rewritten for a new release later this year.

I suggest you take a look at the xcpro40.dll library functions as these are the ones designed to allow you to modify existing PDF files - but will not offer the print option - this is only available in the Viewer SDK's

www.tracker-software.com/PDFT4SDK.zip

Note also if working with PDF forms (Acroforms), low level API or Digi Sigs funcitionality - the Tools SDK requires you to hold a full PDF-XChange PRO SDK license or the functionality works in trial mode only - further if using the Low Level library this requires extensive PDF knowledge and experience on your part and we offer no technical support whatsoever on the low level functionality - it is provided only for those with extensive, exsisting PDF format experience and would be prohibitively expensive to support to any user.
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com
cew
User
Posts: 213
Joined: Tue Feb 01, 2011 8:14 am

Re: Print without a UI

Post by cew »

Hi all,

I also need to print documents without an activeX control. I read this (and other threads) but I'm not very familar using c++.
I studied the simple viewer sdk example but could not get it to work. Running this code will allways end in an "Invalid argument" error. :cry:
Something must be wrong with the DC.

Please help!

Best, cew

Here's my approach:

Code: Select all

  /// <summary>
  /// Prints the given PDF file
  /// </summary>
  public void PrintFile(string fileName, string g_RegKey, string g_DevCode) {
    IntPtr m_Doc = IntPtr.Zero;

    if (PXCV_Error.IS_DS_FAILED(PXCV_Lib36.PXCV_Init(out m_Doc, g_RegKey, g_DevCode))) {
      throw new ApplicationException("Init failed!");
    }

    if (PXCV_Error.IS_DS_FAILED(PXCV_Lib36.PXCV_ReadDocumentW(m_Doc, fileName, 0))) {
      throw new ApplicationException("Open document failed");
    }

    // open print dialog and get name of target printer
    var pDialog = new PrintDialog();
    var result = pDialog.ShowDialog();
    string printerName = pDialog.PrinterSettings.PrinterName;

    if (result == System.Windows.Forms.DialogResult.OK) {
      IntPtr dc = PlatformInvokeGDI32.CreateDC("WINSPOOL", printerName, null, IntPtr.Zero);
      var parameters = new PXCV_Lib36.PXV_CommonRenderParameters { RenderTarget = PXCV_Lib36.PXCV_RenderMode.pxvrm_Printing };

      // print document
      var printResult = PXCV_Lib36.PXCV_DrawPageToDC(m_Doc, 1, dc, ref parameters);

      if (PXCV_Error.IS_DS_FAILED(printResult)) {
        PXCV_Error.ShowDSErrorString(this, printResult);
      }

      PlatformInvokeGDI32.DeleteDC(dc);
    }
  }


public class PlatformInvokeGDI32 {
  #region Class Variables
      
  public const int SRCCOPY = 13369376;
      
  #endregion
      
  #region Class Functions

  [DllImport("gdi32.dll", EntryPoint = "CreateDC")]
  public static extern IntPtr CreateDC(string lpszDriver, string lpszDevice, string lpszOutput, IntPtr lpInitData);

  [DllImport("gdi32.dll", EntryPoint = "DeleteDC")]
  public static extern IntPtr DeleteDC(IntPtr hDc);

  [DllImport("gdi32.dll", EntryPoint = "CreateCompatibleDC")]
  public static extern IntPtr CreateCompatibleDC(IntPtr hdc);
      
  #endregion
}
Walter-Tracker Supp
User
Posts: 381
Joined: Mon Jun 13, 2011 5:10 pm

Re: Print without a UI

Post by Walter-Tracker Supp »

What is it that returns Invalid Argument?

Have you debugged to confirm that the correct printer name is being returned by the printer dialog?

Can you use one of the MS printer dialog classes to return the printer's HDC directly?
cew
User
Posts: 213
Joined: Tue Feb 01, 2011 8:14 am

Re: Print without a UI

Post by cew »

Walter-Tracker Supp wrote:What is it that returns Invalid Argument?
The error occures in call:
PXCV_Lib36.PXCV_DrawPageToDC(m_Doc, 1, dc, ref parameters);
Walter-Tracker Supp wrote:Have you debugged to confirm that the correct printer name is being returned by the printer dialog?
Yes, the printer name is correct.
Walter-Tracker Supp wrote:Can you use one of the MS printer dialog classes to return the printer's HDC directly?
I could not find an example doing this but I'm still investigating...
cew
User
Posts: 213
Joined: Tue Feb 01, 2011 8:14 am

Re: Print without a UI

Post by cew »

@Walter:

User promisekey got his problem solved and can print (see above).
Maybe you could contact him via email.
He has no public email address in his profile, so I can't do it...
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17910
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Print without a UI

Post by Tracker Supp-Stefan »

Hi Cew,

I've just e-mailed promisekey - and have asked him to take a look at this topic when he has the chance.

Best,
Stefan
Walter-Tracker Supp
User
Posts: 381
Joined: Mon Jun 13, 2011 5:10 pm

Re: Print without a UI

Post by Walter-Tracker Supp »

It looks to me as if you aren't defining the WholePageRect element of "parameters" (type PXV_CommonRenderParameters). While DrawRect can be NULL, I'm pretty sure you need to define WholePageRect.
promisekey
User
Posts: 30
Joined: Tue Apr 17, 2012 8:55 pm

Re: Print without a UI

Post by promisekey »

I used Visual Basic 6 to create a quick test to verify printing could be done using a non-visual interface. Here is a summary of how I created my test application. It was done very quickly just to verify it could be done.

1. Made a copy of the PXCView36.
2. Changed "Private Function ViewPDF(fname As String)" to "Public Function ViewPDF(fname As String)"
3. Changed "Private Sub PrintPdfFile(ByVal hParentWnd)" to "Public Sub PrintPdfFile(ByVal hParentWnd As Long, ByVal sPrinterName As String) " and made other changes (See the attached file)
4. Changed "Private Sub ClosePDF()" to "Public Sub ClosePDF()"
5. Added a User Control (allows for the program to be compiled as an OCX) so the new Public functions can be called from another program.
6. In annother application, I connected to the OCX object and called the functions:
ole_pdf = create OLEObject
ole_pdf.ConnectToNewObject("pxcview.pxcvctrl")
ole_pdf.ViewPDF (as_filename)
ole_pdf.PrintPdfFile (handle(this), "HP LaserJet 4200/4300 PCL6")
ole_pdf.closepdf()
destroy(ole_pdf)
Attachments
PXEView36_Print.zip
New PrintPdfFile Sub
(1.24 KiB) Downloaded 251 times
Last edited by promisekey on Fri Jun 29, 2012 9:57 pm, edited 1 time in total.
Walter-Tracker Supp
User
Posts: 381
Joined: Mon Jun 13, 2011 5:10 pm

Re: Print without a UI

Post by Walter-Tracker Supp »

Thank you, promisekey, for helping out with a description of how you accomplished this. Please note that the forum strips non-zipped attachments though.

-Walter
cew
User
Posts: 213
Joined: Tue Feb 01, 2011 8:14 am

Re: Print without a UI

Post by cew »

@promisekey:

Thanks a lot for your description!

Moody's, Fitch, Standard & Poor's said: AAA :D

Best ragards
cew
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17910
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Print without a UI

Post by Tracker Supp-Stefan »

:)
Post Reply