# ConvertFrom-PDF PowerShell Cmdlet |  convert a c# .net program to powershell cmd

**URL:** <https://forums.powershell.org/t/convertfrom-pdf-powershell-cmdlet-convert-a-c-net-program-to-powershell-cmd/3442>\
**Category:** PowerShell Help\
**Created:** [November 20, 2014, 5:37am UTC](https://forums.powershell.org/t/convertfrom-pdf-powershell-cmdlet-convert-a-c-net-program-to-powershell-cmd/3442 "2014-11-20T05:37:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![imessage357\_h](https://avatars.discourse-cdn.com/v4/letter/i/c2a13f/32.png) [@imessage357\_h](https://forums.powershell.org/u/imessage357_h)\
**Post date:** [November 20, 2014, 5:37am UTC](https://forums.powershell.org/t/convertfrom-pdf-powershell-cmdlet-convert-a-c-net-program-to-powershell-cmd/3442/1 "2014-11-20T05:37:13Z")

</div>

Can anyone help me to convert a c# .net program to powershell cmdlet.

Has anyone used this cmdlet ConvertFrom-PDF

[http://www.beefycode.com/post/ConvertFrom-PDF-Cmdlet.aspx](http://www.beefycode.com/post/ConvertFrom-PDF-Cmdlet.aspx)

I need to scan PDF’s and I cant seem to get the source code in this blog post into a working cmdlet

Anyhelp would be greatly apprecated

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [November 20, 2014, 5:50am UTC](https://forums.powershell.org/t/convertfrom-pdf-powershell-cmdlet-convert-a-c-net-program-to-powershell-cmd/3442/2 "2014-11-20T05:50:16Z")

</div>

I’ve done some work with the iTextSharp libraries directly in PowerShell before. You can see an example at [Search a PDF and return specific text](https://social.technet.microsoft.com/Forums/scriptcenter/en-US/086b9a8c-7e47-49ed-8e94-8f5f43f408fe/search-a-pdf-and-return-specific-text?forum=winserverpowershell) . You will need to download a copy of iTextSharp.dll.

---

<div class="post-metadata">

**Author:** ![imessage357\_h](https://avatars.discourse-cdn.com/v4/letter/i/c2a13f/32.png) [@imessage357\_h](https://forums.powershell.org/u/imessage357_h)\
**Post date:** [November 20, 2014, 6:50am UTC](https://forums.powershell.org/t/convertfrom-pdf-powershell-cmdlet-convert-a-c-net-program-to-powershell-cmd/3442/3 "2014-11-20T06:50:54Z")

</div>

Hi Dave thanks for getting back to me

I tried Get-ReferencesFromPdf cmdlet It didn’t return any data no errors either Any suggestions for troubleshooting this?

I do have the iTextSharp.dll and created the same directory structure from the post

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [November 20, 2014, 6:59am UTC](https://forums.powershell.org/t/convertfrom-pdf-powershell-cmdlet-convert-a-c-net-program-to-powershell-cmd/3442/4 "2014-11-20T06:59:02Z")

</div>

That function was written specifically for the question posted on that thread, looking for section numbers followed by some number of lines matching ABC-\*. It’s not meant for you to be able to run it directly.

However, the code does show you how to use the PdfReader and PdfTextExtractor classes to pull text out of a PDF into a .NET String variable. From there, you can split it by line as in the example, or just work with the whole page text as one string; that’s up to you.

Here’s a more trimmed down example that just extracts all of the text from the PDF and outputs it as a single string, that you can manipulate however you want:

```
function Get-PdfText
{
    [CmdletBinding()]
    [OutputType([string])]
    param (
        [Parameter(Mandatory = $true)]
        [string]
        $Path
    )

    $Path = $PSCmdlet.GetUnresolvedProviderPathFromPSPath($Path)

    try
    {
        $reader = New-Object iTextSharp.text.pdf.pdfreader -ArgumentList $Path
    }
    catch
    {
        throw
    }

    $stringBuilder = New-Object System.Text.StringBuilder

    for ($page = 1; $page -le $reader.NumberOfPages; $page++)
    {
        $text = [iTextSharp.text.pdf.parser.PdfTextExtractor]::GetTextFromPage($reader, $page)
        $null = $stringBuilder.AppendLine($text) 
    }

    $reader.Close()

    return $stringBuilder.ToString()
}
```

---

<div class="post-metadata">

**Author:** ![imessage357\_h](https://avatars.discourse-cdn.com/v4/letter/i/c2a13f/32.png) [@imessage357\_h](https://forums.powershell.org/u/imessage357_h)\
**Post date:** [November 20, 2014, 7:21am UTC](https://forums.powershell.org/t/convertfrom-pdf-powershell-cmdlet-convert-a-c-net-program-to-powershell-cmd/3442/5 "2014-11-20T07:21:32Z")

</div>

ok I tried it , still not returning a string am I still using

Add-Type -Path .\PdfToText\itextsharp.dll

I feel like im not placing this .dll right

any other suggestions

thx

---

<div class="post-metadata">

**Author:** ![\_timpringle](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/_timpringle/32/276_2.png) [@\_timpringle](https://forums.powershell.org/u/_timpringle)\
**Post date:** [November 20, 2014, 5:50pm UTC](https://forums.powershell.org/t/convertfrom-pdf-powershell-cmdlet-convert-a-c-net-program-to-powershell-cmd/3442/6 "2014-11-20T17:50:52Z")

</div>

Try something like this

```
[System.Reflection.Assembly]::LoadFrom(‘C:\Data\iTextSharp.DLL’)
```
.

(Copying the file there as well of course)

Use fully qualified paths BTW.

Then test Dave’s function. Worked good for me.

---

<div class="post-metadata">

**Author:** ![guldmann](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/guldmann/32/446_2.png) [@guldmann](https://forums.powershell.org/u/guldmann)\
**Post date:** [August 14, 2017, 4:56am UTC](https://forums.powershell.org/t/convertfrom-pdf-powershell-cmdlet-convert-a-c-net-program-to-powershell-cmd/3442/7 "2017-08-14T04:56:39Z")

</div>

For some reason I cannot load the dll as described…  
instead i have to do like this

```
$bytes = [System.IO.File]::ReadAllBytes("c:\...\itextsharp.dll")
[System.Reflection.Assembly]::Load($bytes)

```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:38pm UTC](https://forums.powershell.org/t/convertfrom-pdf-powershell-cmdlet-convert-a-c-net-program-to-powershell-cmd/3442/8 "2024-05-16T20:38:22Z")

</div>

Closed on May 16, 2024, 8:38pm UTC


