Html duplicated with wkhtmltopdf

1

I am implementing an HTML to PDF conversion with wkhtmltopdf , I have two problems:

  • I do not respect the HTML styles
  • The main one and more, he is putting the content to me many times.
  • Deputy code:

    Process process;
    ProcessStartInfo processStartInfo = new ProcessStartInfo();
    processStartInfo.FileName = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~"), "Utilities", "wkhtmltopdf", "wkhtmltopdf.exe");
    processStartInfo.WorkingDirectory = @"D:\";
    
    // run the conversion utility
    processStartInfo.UseShellExecute = false;
    processStartInfo.CreateNoWindow = true;
    processStartInfo.RedirectStandardInput = true;
    processStartInfo.RedirectStandardOutput = true;
    processStartInfo.RedirectStandardError = true;
    
    // note: that we tell wkhtmltopdf to be quiet and not run scripts
    string args = "-q -n ";
    args += "--disable-smart-shrinking ";
    args += "";
    args += "--outline-depth 0 ";
    args += "--page-size A4 ";
    args += " - -";
    
    processStartInfo.Arguments = args;
    
    process = Process.Start(processStartInfo);
    
    using (StreamWriter stramWriter = process.StandardInput)
    {
        stramWriter.AutoFlush = true;
        stramWriter.Write(myHTML);
    }
    
    //read output
    byte[] buffer = new byte[32768];
    byte[] file;
    int read = 1;
    using (var memoryStream = new MemoryStream())
    {
    
       while (read>0)
        {
             read = process.StandardOutput.BaseStream.Read(buffer, 0, buffer.Length);
    
             memoryStream.Flush();
            // memoryStream.Position = 0;
            memoryStream.Write(buffer, 0, read);
       }
    
        file = memoryStream.ToArray();
    }
    
    process.StandardOutput.Close();
    // wait or exit
    process.WaitForExit(60000);
    
    // read the exit code, close process
    int returnCode = process.ExitCode;
    process.Close();
    
    process.Dispose();
    //se guarda el archivo
    
    File.WriteAllBytes(@"D:\test.pdf", file);
    
        
    asked by Conchita BH 20.07.2017 в 19:14
    source

    0 answers