简体   繁体   English

C#打开一个特定的PDF页面,从SQL获取数据

[英]c# open a specific pdf page with getting data from sql

In my project I want to open a specific pdf page. 在我的项目中,我想打开一个特定的pdf页面。 I found a code from stackoverflow which works great here is the code 我从stackoverflow找到了一个很好的代码,这里的代码

private void button1_Click(object sender, EventArgs e)
{
    startInfo.FileName = @"C:\Program Files (x86)\Foxit Software\Foxit Reader\FoxitReader.exe";
    startInfo.Arguments = "/A \"page=3\" \"C:\\Users\\test.pdf";
    Process.Start(startInfo);
} 

Yet this code is working perfectly in c# when i want to get startInfo.Arguments's data from sql it only opens the last page which I opened with button1_Click . 但是,当我想从sql获取startInfo.Arguments's数据时,此代码在c#中可以正常工作,它只打开我用button1_Click打开的最后一页。

This is how im trying to get data with sql; 这就是我试图通过sql获取数据的方式。

SqlCommand sqlCmd = new SqlCommand("Select * From table ", baglanti);
baglanti.Open();
SqlDataReader reader = sqlCmd.ExecuteReader();
try
{
    while (reader.Read())
    {
        if (reader[1].ToString() == "pdf")
        {
            startInfo.FileName = @reader[4].ToString();
            startInfo.Arguments = reader[3].ToString();
            Process.Start(startInfo);
        }           
    }

    baglanti.Close();
    reader.Close();
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message.ToString());
}

Another thing is after I open a specific pdf page something like page 15 with button and then I want to open pdf from windows normally it also opens from page 15. Its like I cant dispose the argument after I use it. 另一件事是在打开特定的pdf页面(如带有按钮的第15页)之后,我通常要从Windows中打开pdf,它也从第15页打开。这就像在使用它后无法处理自变量一样。

So is anyone know anything about this issue or can see where I am wrong? 那么,有没有人对此问题有任何了解,或者可以看到我错了?

Your code works fine when I use it in a test application. 当我在测试应用程序中使用它时,您的代码可以正常工作。 What I noticed now from your comments is that you have a space in the arguments between / and A . 我现在从您的评论中注意到,您在/A之间的参数中有一个空格。 Remove it and make sure your path to the PDF is correct (no double escape sequences in your database row or something similar). 删除它,并确保您的PDF路径正确(数据库行中没有类似的双转义序列)。 So your output should be the following to get it running properly: 因此,您的输出应为以下内容以使其正常运行:

reader[1]: "pdf"
reader[3]:  "/A \"page=1\" \"C:\\Users\\dzcgkv\\Desktop\\Kiosk\\EOP-HPV_006_DHPV_HİDROLİK_MONTAJ.pdf\""
reader[4]: "C:\\Program Files (x86)\\Foxit Software\\Foxit Reader\\FoxitReader.exe"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM