我有pdf文件。我想用php打印pdf的详细信息,如页面大小。
我有这段代码
<?php
$pdffile = "C:\Users\suresh\Downloads\Invoice_52683.pdf";
$pdfinfo = shell_exec("pdfinfo ".$pdffile);
// find height and width
preg_match('/Page size:\s+([0-9]{0,5}\.?[0-9]{0,3}) x ([0-9]{0,5}\.?[0-9]{0,3})/', $pdfinfo,$heightandwidth);
echo $width = $heightandwidth[1];
echo $height = $heightandwidth[2];
?>
这是我的代码可以为此提供任何帮助。
提前致谢
答案 0 :(得分:1)
/// <summary>
/// Application test fixture to generate the test host.
/// </summary>
/// <typeparam name="TStartup">The type of the startup.</typeparam>
/// <seealso cref="WebApplicationFactory{TStartup}" />
public class AppTestFixture<TStartup> : WebApplicationFactory<TStartup>
where TStartup : class
{
/// <summary>
/// The configuration.
/// </summary>
private Action<IServiceCollection> _configuration;
/// <summary>
/// Call this as a way to override container registration for integration testing.
/// </summary>
/// <param name="configuration">The configuration.</param>
public void ConfigureTestServices(Action<IServiceCollection> configuration)
{
this._configuration = configuration;
}
/// <summary>
/// Creates a <see cref="T:Microsoft.AspNetCore.Hosting.IWebHostBuilder" /> used to set up <see cref="T:Microsoft.AspNetCore.TestHost.TestServer" />.
/// </summary>
/// <returns>
/// A <see cref="T:Microsoft.AspNetCore.Hosting.IWebHostBuilder" /> instance.
/// </returns>
/// <remarks>
/// The default implementation of this method looks for a <c>public static IWebHostBuilder CreateWebHostBuilder(string[] args)</c>
/// method defined on the entry point of the assembly of <typeparamref name="TEntryPoint" /> and invokes it passing an empty string
/// array as arguments.
/// </remarks>
protected override IWebHostBuilder CreateWebHostBuilder()
{
var builder = WebHost.CreateDefaultBuilder()
.UseEnvironment("integration-test")
.UseStartup<TStartup>();
if (this._configuration != null)
{
builder.ConfigureTestServices(this._configuration);
}
return builder;
}
}
答案 1 :(得分:0)
首先检查您的pdfinfo
路径,如果您没有:XPDF ...那么请更改您的代码:
$pdffile = "C:\\Users\\suresh\\Downloads\\Invoice_52683.pdf";
$pdfinfo_path = "C:\\path\\to\\pdfinfo.exe";
$pdfinfo = shell_exec($pdfinfo_path." ".$pdffile);
// find height and width
preg_match('/Page size:\s+([0-9]{0,5}\.?[0-9]{0,3}) x ([0-9]{0,5}\.?[0-9]{0,3})/',$pdfinfo,$heightandwidth);
echo $width = $heightandwidth[1];
echo $height = $heightandwidth[2];
如果您使用Linux:$pdfinfo_path = "/path/to/pdfinfo";