Print Page | Close Window

How to use Quick PDF Library with PowerShell

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: Sample Code
Forum Description: Share Debenu Quick PDF Library sample code with other forum members
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=3180
Printed Date: 28 Mar 24 at 9:22PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: How to use Quick PDF Library with PowerShell
Posted By: Stefan Schnell
Subject: How to use Quick PDF Library with PowerShell
Date Posted: 29 Sep 15 at 5:36AM
Hello community,

here a sample code how to use Quick PDF ActiveX Library Lite inside PowerShell. It is only necessary to build an interoperability library via type library importer of the .NET SDK.

Enjoy it.

Cheers
Stefan

#-Begin-----------------------------------------------------------------
#-
#- PDF document creator
#-
#- Important hint: To use the ActiveX library it is necessary to build
#- an interoperability library via type library importer TlbImp.exe.
#-
#- Author: Stefan Schnell
#-
#-----------------------------------------------------------------------

  #-Constants-----------------------------------------------------------
    $PDFMillimetres = 1
    $PDFInches = 2

    $PDFAlignmentCenter = 0
    $PDFAlignmentTop = 1
    $PDFAlignmentBottom = 2

  #-Variables-----------------------------------------------------------
    $Text  = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, "
    $Text += "sed diam nonumy eirmod tempor invidunt ut labore et dolor"
    $Text += "e magna aliquyam erat, sed diam voluptua. At vero eos et "
    $Text += "accusam et justo duo dolores et ea rebum. Stet clita kasd"
    $Text += " gubergren, no sea takimata sanctus est Lorem ipsum dolor"
    $Text += " sit amet. Lorem ipsum dolor sit amet, consetetur sadipsc"
    $Text += "ing elitr, sed diam nonumy eirmod tempor invidunt ut labo"
    $Text += "re et dolore magna aliquyam erat, sed diam voluptua. At v"
    $Text += "ero eos et accusam et justo duo dolores et ea rebum. Stet"
    $Text += " clita kasd gubergren, no sea takimata sanctus est Lorem "
    $Text += "ipsum dolor sit amet."

  #-Sub CreatePDFDoc----------------------------------------------------
  #-
  #- Creates PDF documents automatically, with different count of
  #- pages and optional with a picture
  #-
  #---------------------------------------------------------------------
    Function Create-PDFDoc($cntPages, $PictureName) {

      If ($PictureName -eq $Null) {
        $WithPicture = $False
      }
      Else {
        $WithPicture = $True
        $PicName = $PSScriptRoot + "\" + $PictureName
      }

      $Path = $PSScriptRoot
      [Reflection.Assembly]::LoadFile($Path + 
        "\DebenuPDFLibraryLite1114.Interop.dll") > $Null

      $PDF = New-Object DebenuPDFLibraryLite1114.Interop.PDFLibraryClass
      $PDF.SetPageSize("A4") > $Null
      $PDF.SetMeasurementUnits($PDFMillimetres) > $Null

      For ($i = 1; $i -le $cntPages; $i++) {

        $PDF.DrawTextBox(10, 287, 190, 100, $Text, $PDFAlignmentTop) > $Null

        If ($WithPicture -eq $True) {
          $PDF.AddImageFromFile($PicName, 0) > $Null
          $ImgWidth = $PDF.ImageWidth() / 2
          $ImgHeight = $PDF.ImageHeight() / 2
          $PDF.DrawImage(10, 187, $ImgWidth, $ImgHeight) > $Null
        }

        If ($i -lt $cntPages) {
          $PDF.NewPage() > $Null
        }

      }

      $GUID = [GUID]::NewGuid()
      $FileName = $env:USERPROFILE + "\Documents\" + $GUID + ".pdf"
      $PDF.SaveToFile($FileName) > $Null

    }

  #-Sub Main------------------------------------------------------------
    Function Main() {

      Create-PDFDoc 10 "Gonzo.jpg"

    }

  #-Main----------------------------------------------------------------
    Main

#-End-------------------------------------------------------------------



Replies:
Posted By: mLipok
Date Posted: 29 Sep 15 at 7:56PM
Hello Stefan
Look at my AutoIt UDF for Debenu QuickPDF
https://www.autoitscript.com/forum/files/file/342-debenu-quick-pdf-library-udf/

I think it will be usefull for Powershell users.
As it is very easy to convert functions.

Best regards,
mLipok


-------------
Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk