ArtifexSoftware / Ghostscript.NET

Ghostscript.NET - managed wrapper around the Ghostscript library (32-bit & 64-bit)
https://ghostscript.com
GNU Affero General Public License v3.0
391 stars 152 forks source link

The font kaiu.tff(標楷體) broken while convert pdf to png. #95

Open k9215105 opened 2 years ago

k9215105 commented 2 years ago

I am using RasterizerSample1 to convert a pdf file to png. The pdf file contains chinese word with font 標楷體(kaiu.tff), which will broken in output file. pdf image png image

rainmakerho commented 2 years ago

Hi @k9215105 , You can use GhostscriptProcessor from ProcessorSample1.

// call pdf2Png();
static void ghostscript_Processing(object sender, GhostscriptProcessorProcessingEventArgs e)
{
    Console.WriteLine(e.CurrentPage.ToString() + " / " + e.TotalPages.ToString());
}

private static void pdf2Png()
{
    string inputFile = @"c:\temp\abc.pdf";
    string outputFile = @"c:\temp\abc-page-%03d.png";

    int pageFrom = 1;
    int pageTo = 50;

    using (GhostscriptProcessor ghostscript = new GhostscriptProcessor())
    {
        ghostscript.Processing += new GhostscriptProcessorProcessingEventHandler(ghostscript_Processing);

        List<string> switches = new List<string>();
        switches.Add("-empty");
        switches.Add("-dSAFER");
        switches.Add("-dBATCH");
        switches.Add("-dNOPAUSE");
        switches.Add("-dNOPROMPT");
        switches.Add("-dFirstPage=" + pageFrom.ToString());
        switches.Add("-dLastPage=" + pageTo.ToString());
        switches.Add("-sDEVICE=png16m");
        switches.Add("-r96");
        switches.Add("-dTextAlphaBits=4");
        switches.Add("-dGraphicsAlphaBits=4");
        switches.Add(@"-sOutputFile=" + outputFile);
        switches.Add(@"-f");
        switches.Add(inputFile);
        ghostscript.Process(switches.ToArray());
    }
}
k9215105 commented 2 years ago

It works, thanks for that.

rainmakerho commented 2 years ago

Hi @k9215105 , Could you give us more information about "doesn't work" ?

k9215105 commented 2 years ago

Sorry, it was a mistake, it works now, thanks

k9215105 commented 2 years ago
您好不好意思想再請教一下,我用了這個範例是可以印出標楷體了但是不管input的pdf有幾頁,出來的圖檔都只有第一頁這是正常的嗎? 寄件者: 亂馬客傳送時間: 2021年11月29日 下午 11:39:46收件者: jhabjan/Ghostscript.NET副本: k9215105; Mention主旨: Re: [jhabjan/Ghostscript.NET] The font kaiu.tff(標楷體) broken while convert pdf to png. (Issue #95) Hi @k9215105 ,You can use GhostscriptProcessor from ProcessorSample1.// change DEVICE=tiffg4// call pdf2Tiff();static void ghostscript_Processing(object sender, GhostscriptProcessorProcessingEventArgs e){        Console.WriteLine(e.CurrentPage.ToString() + " / " + e.TotalPages.ToString());} private static void pdf2Tiff(){        string inputFile = @"c:\temp\abc.pdf";        string outputFile = @"c:\temp\abc-page-%03d.tiff";         int pageFrom = 1;        int pageTo = 50;         using (GhostscriptProcessor ghostscript = new GhostscriptProcessor())        {               ghostscript.Processing += new GhostscriptProcessorProcessingEventHandler(ghostscript_Processing);                List switches = new List();               switches.Add("-empty");               switches.Add("-dSAFER");               switches.Add("-dBATCH");               switches.Add("-dNOPAUSE");               switches.Add("-dNOPROMPT");               switches.Add("-dFirstPage=" + pageFrom.ToString());               switches.Add("-dLastPage=" + pageTo.ToString());               switches.Add("-sDEVICE=tiffg4");               switches.Add("-r96");               switches.Add("-dTextAlphaBits=4");               switches.Add("-dGraphicsAlphaBits=4");               switches.Add(@"-sOutputFile=" + outputFile);               switches.Add(@"-f");               switches.Add(inputFile);               ghostscript.Process(switches.ToArray());        }}—You are receiving this because you were mentioned.Reply to this email directly, view it on GitHub, or unsubscribe.Triage notifications on the go with GitHub Mobile for iOS or Android.