-1

I'm using visual studio 2015 with VB language Web application, my issue in brief I used Ghostscript to extract pdf first page to png its work fine but if pdf file name contain space its does not extract png and no error show up or if written on other language the error " Page number is not in pages number range!". I appreciate any help.

test.pdf ---> work fine

new york.pdf --->nothing happen no error show up

pdf file name not written in English --->error "Page number is not in pages number range!"

code is

Imports Ghostscript.NET
Imports Ghostscript.NET.Rasterizer
Imports System.IO
Imports System.Drawing.Imaging
Imports System.Drawing
Partial Class Default6
    Inherits System.Web.UI.Page
    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim inputPdfPath As String = "d:\test\test.pdf"
        Dim outputPath As String = "d:\test\"
        Using Rasterizer = New GhostscriptRasterizer
            Rasterizer.CustomSwitches.Add("-dUseTrimBox")
            Rasterizer.CustomSwitches.Add("-g683x960")
            Rasterizer.CustomSwitches.Add("-f")
            Rasterizer.Open(inputPdfPath)
            Dim pageFilePath As String = Path.Combine(outputPath, "Page1" + ".jpg")
            Dim img As Image = Rasterizer.GetPage(100, 1)
            img.Save(pageFilePath, ImageFormat.Png)
            Console.WriteLine(pageFilePath)
        End Using
    End Sub
End Class
  • Hi @Amer. Please, take a look at this post, as it might be helpful for your case: https://www.vbforums.com/showthread.php?703121-RESOLVED-How-to-Shell-from-a-directory-with-spaces-in-path – Dave Miller Apr 26 '21 at 09:46
  • Thanks a lot that solve the error happen if pdf file name contain space like new york.pdf --->nothing happen no error show up this was solved and its extract png, the last error still remain which is if pdf file name written in non English like Chinese or Arabic – Amer Apr 26 '21 at 21:05

1 Answers1

0

First posted in the comments section, I'm including information as answer, as it worked for the user.

Here is a link useful to solve the blank spaces trouble: https://www.vbforums.com/showthread.php?703121-RESOLVED-How-to-Shell-from-a-directory-with-spaces-in-path

For non-english characters, please try with the following approach: Illegal characters in path (Chinese characters)

If the last solution does not work, another alternative is to loop through files in directory and identify the one you are looking for by another meta-data ou file info. In this case, please check this link: vb.net how to loop through a directory listing?

Dave Miller
  • 536
  • 3
  • 19
  • Thanks again for your help ,error still remain For non-english characters which is error "Page number is not in pages number range!" if I change pdf file name to English its work fine with no error – Amer Apr 28 '21 at 22:37
  • Hi @Amer, the second approach (loop through files in directory) does not get rid of the error? – Dave Miller Apr 29 '21 at 07:53
  • Unfortunately the second approach not succeed and error still remain – Amer Apr 29 '21 at 15:34
  • Ok. I was able to reproduce the error in a test environment, but still haven't found a solution. – Dave Miller May 03 '21 at 06:32