Hi all
I'm trying to print PDF documents with pdfix sdk utilizing win32print. This PDF 
library requires printer HANDLE value as int directly not as a PyObject. 
Is there any way to obtain printer HANDLE value in Python code?(attached is a 
sample)
Thanks
Paolo
import os
import win32print, win32ui # https://github.com/mhammond/pywin32
import Utils
from Pdfix import *

def PrintPage(email, key, open_path):
    pdfix  = GetPdfix()
    if pdfix is None:
        raise Exception('Pdfix Initialization fail')

    # authorization
    if not pdfix.Authorize(email, key):
        raise Exception('Authorization fail : ' + pdfix.GetError())

    doc = pdfix.OpenDoc(open_path, "")
    if doc is None:
        raise Exception('Unable to open pdf : ' + pdfix.GetError())

    page = doc.AcquirePage(0)
    if page is None:
        raise Exception('Unable to acquire page : ' + pdfix.GetError())
    cropBox = page.GetCropBox()

    hDC = win32ui.CreateDC ()
    hDC.CreatePrinterDC (win32print.GetDefaultPrinter ())

    PHYSICALWIDTH = 110
    PHYSICALHEIGHT = 111
    printerSize = hDC.GetDeviceCaps (PHYSICALWIDTH), hDC.GetDeviceCaps (PHYSICALHEIGHT)

    hDC.StartDoc ("Test doc")
    hDC.StartPage ()

    printerSize = 8000, 10000

    zoom = min(printerSize[0] / (cropBox.right - cropBox.left), 
        printerSize[1] / (cropBox.top - cropBox.bottom))
    # render first page to jpg image
    pageView = page.AcquirePageView(zoom, kRotate0)
    if not pageView:
        raise Exception('Unable to acquire page view : ' + pdfix.GetError())

    clipRect = pageView.RectToDevice(cropBox)

    params = PdfPageRenderParams()
    params.device = hDC
    params.matrix = pageView.GetDeviceMatrix()
    params.clip_rect = clipRect
    if  not page.DrawContent(params, 0, None):
        raise Exception('Unable to draw content : ' + pdfix.GetError())
    page.ReleasePageView(pageView)

    hDC.EndPage ()
    hDC.EndDoc ()

    doc.ReleasePage(page)

    doc.Close()
    pdfix.Destroy()

try:
    email = Utils.getEmail()                # email address
    licenseKey = Utils.getLicenseKey()      # license key
    cwd = os.getcwd() + "/"                 # current working directory
    if not os.path.isdir(cwd + 'output'):
        os.makedirs(cwd + 'output')

    # pdfix initialization
    Pdfix_init(cwd + Utils.getModuleName('pdfix'))

    PrintPage(email, licenseKey, 
        cwd + '/resources/test.pdf'), 

    Pdfix_destroy()

except Exception as e:
    print('Oops! ' + str(e))
    
_______________________________________________
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32

Reply via email to