1

我需要一些认真的帮助。我遇到了麻烦,如果能得到任何帮助,我将不胜感激。我在网上搜索了几个小时,结果空手而归。我做了一个在目录中进行递归并将所有图像转换为 PDF 的项目。我正在使用 itextsharp 和 pdfsharp (如果没有彼此,它们似乎无法正常工作)。无论如何,该项目运行完美,直到 Visual Studio 抱怨我上次从 VS 修复问题时了解到的程序集,它会破坏它们。所以,我忽略了它。在使用 [在此处插入五颜六色的文字] Beta 测试的电话时,他把我搞糊涂了,我最终点击了 VS 正在抛出的警告。当我点击它时,我开始收到以下错误: 1)转换 pdf 文件时,它只转换目录中任何文件的前 15 个字节。2) 当 PDF 已经存在时,它会在标题中出现异常并出错。这是我正在使用的代码,它运行良好:

WebException 未处理(这不是 WEB APP)进程无法访问文件“filepath\andname.pdf”,因为它正被另一个进程使用。

在此之前,当我在应用程序的 app.config 部分加载原始代码时,我会收到此错误:

FileLoadException 未处理 无法加载文件或程序集“itextsharp,版本=5.3.2.0,文化=中性,PublicKeyToken=8354ae6d2174ddca”或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。(来自 HRESULT 的异常:0x80131040)

在我勒死这家伙并在黑市上卖掉他的肝脏之前,谁能帮帮我?这真是令人沮丧。我将不胜感激。

./x86

按照标题中在访问时轰炸的 app.config 文件的顺序,并且只向应用程序添加 15 个字节:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
      <section name="TAMI.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
    </sectionGroup>
  </configSections>
  <system.diagnostics>
  </system.diagnostics>
  <userSettings>
    <TAMI.My.MySettings>
      <setting name="scanner" serializeAs="String">
        <value />
      </setting>
      <setting name="authenticated_user" serializeAs="String">
        <value />
      </setting>
    </TAMI.My.MySettings>
  </userSettings>
</configuration>

错误版本的程序集

<?xml version="1.0"?>
<configuration>
  <configSections>
    <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <section name="TAMI.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
    </sectionGroup>
  </configSections>
  <system.diagnostics>
    <sources>
      <!-- This section defines the logging configuration for My.Application.Log -->
      <source name="DefaultSource" switchName="DefaultSwitch">
        <listeners>
          <add name="FileLog"/>
          <!-- Uncomment the below section to write to the Application Event Log -->
          <!--<add name="EventLog"/>-->
        </listeners>
      </source>
    </sources>
    <switches>
      <add name="DefaultSwitch" value="Information"/>
    </switches>
    <sharedListeners>
      <add name="FileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" initializeData="FileLogWriter"/>
      <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
      <!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
    </sharedListeners>
  </system.diagnostics>
  <userSettings>
    <TAMI.My.MySettings>
      <setting name="scanner" serializeAs="String">
        <value/>
      </setting>
      <setting name="authenticated_user" serializeAs="String">
        <value/>
      </setting>
    </TAMI.My.MySettings>
  </userSettings>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="itextsharp" publicKeyToken="8354AE6D2174DDCA" culture="neutral"/>
                <bindingRedirect oldVersion="0.0.0.0-5.3.2.0" newVersion="5.3.2.0"/>
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>

我一直在使用的代码

        For b As Integer = 0 To lboxconv.Items.Count - 1
            Application.DoEvents()
            Dim extension = Microsoft.VisualBasic.Right(b, 3)
            Dim doc As New Document()
            Dim File_Type As String
            File_Type = Replace(lboxconv.Items(b), ".png", ".pdf", vbTextCompare)
            Dim writer As PdfWriter = PdfWriter.GetInstance(doc, New FileStream(File_Type, FileMode.Create))
            doc.Open()
            Dim imgpath As String = lboxconv.Items(b)
            Dim png As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(imgpath)
            png.ScaleToFit("500", "500")
            png.Alignment = Element.ALIGN_CENTER
            doc.Add(png)
            doc.Close()
        Next

有人请帮忙!我很绝望,没有时间和答案。

4

0 回答 0