qzmjef 发表于 2024-8-17 10:09:20

怎么样运用 Java 在 PDF 文档中添加、删除或旋转页面


    <h1 style="color: black; text-align: left; margin-bottom: 10px;">学习 API <span style="color: black;">处理</span><span style="color: black;">方法</span>,用于将页面从一个 PDF 添加到另一个、从 PDF 中删除页面、旋转 PDF 中的所有页面以及旋转 PDF 中的部分页面。</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/de0bbd40fb8e4a23a362cc7abffc2052~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723889701&amp;x-signature=QhrRQiie3YrTFQLtjpIegWJX2PU%3D" style="width: 50%; margin-bottom: 20px;"></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">鉴于在线<span style="color: black;">供给</span>的免费 PDF 编辑工具的数量(<span style="color: black;">包含</span> PDF 文件中存在的本机工具),在<span style="color: black;">必须</span>时对 PDF 文档进行小规模更改并不难。然而,在更大范围内进行<span style="color: black;">一样</span>的改变带来了全新的挑战。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">假设您有 100 个 PDF 文件,<span style="color: black;">每一个</span>文件都<span style="color: black;">必须</span>相同的编辑操作。在这种<span style="color: black;">状况</span>下,手动执行更改是<span style="color: black;">无</span><span style="color: black;">道理</span>的:该过程的低效率<span style="color: black;">最后</span>会产生比它<span style="color: black;">处理</span>的问题<span style="color: black;">更加多</span>的问题,从而妨碍竞争任务/优先级。大规模更改<span style="color: black;">海量</span> PDF 文档的最有效<span style="color: black;">办法</span>是以编程方式进行,<span style="color: black;">运用</span>旨在与压缩 PDF 文件通信并轻松操作其属性的 API。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在本文中,我将演示四种易于<span style="color: black;">运用</span>的 API <span style="color: black;">处理</span><span style="color: black;">方法</span>,它们<span style="color: black;">准许</span>您以编程方式在 PDF 文档中大规模添加、删除或旋转页面。这些<span style="color: black;">处理</span><span style="color: black;">方法</span><span style="color: black;">供给</span>以下特定服务:</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">将一个 PDF 文档中的页面<span style="color: black;">插进</span>/复制到另一个文档中</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">从 PDF 文档中删除/删除页面</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">旋转 PDF 文档中的所有页面</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">旋转 PDF 文档中的特定范围/页面子集</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">下面,我重点介绍了此列表中<span style="color: black;">每一个</span> API <span style="color: black;">处理</span><span style="color: black;">方法</span>的<span style="color: black;">有些</span>用例和所需参数,并<span style="color: black;">供给</span>了Java代码示例以<span style="color: black;">帮忙</span>您构建 API 调用。这些 API 完全免<span style="color: black;">花费</span>于有限规模的操作(每月<span style="color: black;">触及</span>不超过 800 次 API 调用的操作),且额外承诺为零。要<span style="color: black;">得到</span>安全的 API 密钥,您只需在<span style="color: black;">咱们</span>的网站上注册一个免费帐户<span style="color: black;">就可</span>。一旦你有了它,你就<span style="color: black;">能够</span>在下面<span style="color: black;">供给</span>的代码示例中<span style="color: black;">容易</span>且重复地验证 API <span style="color: black;">拜访</span>。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">安装 API 客户端</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在深入<span style="color: black;">科研</span><span style="color: black;">每一个</span> API <span style="color: black;">处理</span><span style="color: black;">方法</span>的用例和参数之前,<span style="color: black;">咱们</span>的<span style="color: black;">第1</span>步是安装 Cloudmersive API 客户端。<span style="color: black;">咱们</span><span style="color: black;">能够</span><span style="color: black;">经过</span><span style="color: black;">首要</span>添加对<span style="color: black;">咱们</span>的Maven POM 文件的引用来<span style="color: black;">起始</span>这样做,如下所示:</p>

    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">
      jitpack.io
    </p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">
      https://jitpack.io
    </p>&lt;/repositories&gt;
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">而后</span><span style="color: black;">咱们</span><span style="color: black;">能够</span>在依赖项中<span style="color: black;">包括</span>以下引用,使 JitPack 能够编译库:</p>

    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">
      com.github.Cloudmersive
    </p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">
      Cloudmersive.APIClient.Java
    </p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">
      v4.25
    </p>&lt;/dependencies&gt;
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">或</span>,<span style="color: black;">咱们</span><span style="color: black;">能够</span><span style="color: black;">经过</span>在存储库末尾的根 build.gradle 中<span style="color: black;">包括</span>以下内容来安装Gradle :</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">allprojects {</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">repositories {</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">...</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">maven { url https://jitpack.io }</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">}</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">}</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">之后,<span style="color: black;">咱们</span><span style="color: black;">能够</span>在 build.gradle 中添加依赖:</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">dependencies {</p><span style="color: black;">
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> implementation </p>com.github.Cloudmersive:Cloudmersive.APIClient.Java:v4.25
    </span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">}</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">最后,<span style="color: black;">咱们</span><span style="color: black;">必须</span>在文件顶部<span style="color: black;">包括</span>以下导入:</p><span style="color: black;">
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">// Import classes://import </p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">com.cloudmersive.client.invoker.ApiClient;//import</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">com.cloudmersive.client.invoker.ApiException;//import </p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">com.cloudmersive.client.invoker.Configuration;//import </p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">com.cloudmersive.client.invoker.auth.*;//import</p>com.cloudmersive.client.EditPdfApi;
    </span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">将页面从一个 PDF <span style="color: black;">插进</span>、复制到另一个</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">正如这个 API 的标题所暗示的,<span style="color: black;">咱们</span><span style="color: black;">能够</span><span style="color: black;">运用</span>这种“<span style="color: black;">插进</span>、复制”<span style="color: black;">处理</span><span style="color: black;">方法</span>将来自源 PDF 的特定范围的页面<span style="color: black;">包括</span>在<span style="color: black;">目的</span> PDF 中。这是快速编译大型报告、备忘录、营销样本等的绝佳工具。此 API 的参数<span style="color: black;">准许</span><span style="color: black;">咱们</span>准确指定要从<span style="color: black;">那些</span>页面<span style="color: black;">起始</span>和结束复制,以及将这些复制的页面<span style="color: black;">插进</span><span style="color: black;">目的</span>文档的<span style="color: black;">详细</span>位置。虽然源文件和<span style="color: black;">目的</span>文件输入很容易导航,但在配置以下三个参数时,<span style="color: black;">咱们</span><span style="color: black;">必须</span>更加<span style="color: black;">重视</span>:</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">pageStartSource:<span style="color: black;">起始</span>复制内容的页面(从 1 开始);此页面的内容将<span style="color: black;">包括</span>在<span style="color: black;">目的</span>文件中。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">pageEndSource:要从中复制内容的最后一页(从 1 <span style="color: black;">起始</span>);此页面的内容将<span style="color: black;">包括</span>在<span style="color: black;">目的</span>文件中。</p><span style="color: black;">pageInsertBeforeDestination:<span style="color: black;">目的</span> PDF 中应<span style="color: black;">包括</span>复制内容的页面(从 1 <span style="color: black;">起始</span>)。</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">随着<span style="color: black;">咱们</span>的参数平方,<span style="color: black;">咱们</span><span style="color: black;">能够</span>像<span style="color: black;">这般</span>构造 API 调用:</p><span style="color: black;">
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">ApiClient defaultClient = </p>Configuration.getDefaultApiClient();
    </span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">// Configure API key authorization: Apikey</p><span style="color: black;">
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">ApiKeyAuth Apikey = (ApiKeyAuth) </p>defaultClient.getAuthentication("Apikey");
    </span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Apikey.setApiKey("YOUR API KEY");</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">//Apikey.setApiKeyPrefix("Token");</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">EditPdfApi apiInstance = new EditPdfApi();</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">File sourceFile = new File("/path/to/inputfile"); // File | Source PDF file to copy pages from.</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">File destinationFile = new File("/path/to/inputfile"); // File | Destination PDF file to copy pages into.</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Integer pageStartSource = 56; // Integer | Page number (1 based) to start copying pages from (inclusive) in the Source file.</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Integer pageEndSource = 56; // Integer | Page number (1 based) to stop copying pages pages from (inclusive) in the Source file.</p><span style="color: black;">
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Integer </p>pageInsertBeforeDesitnation = 56; // Integer | Page number (1 based) to insert the pages before in the Destination file.
    </span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">try {</p><span style="color: black;">
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> byte[] result = </p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">apiInstance.editPdfInsertPages(sourceFile, destinationFile, pageStartSource, pageEndSource,</p>pageInsertBeforeDesitnation);
    </span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> System.out.println(result);</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">} catch (ApiException e) {</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">System.err.println("Exception when calling EditPdfApi#editPdfInsertPages");</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> e.printStackTrace();</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">}</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">从 PDF 文档中删除、删除页面</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">倘若</span><span style="color: black;">咱们</span>的<span style="color: black;">目的</span>是从 PDF 文件中大规模删除页面,<span style="color: black;">咱们</span><span style="color: black;">能够</span>采用“删除,删除”<span style="color: black;">处理</span><span style="color: black;">方法</span>。此页面删除<span style="color: black;">处理</span><span style="color: black;">方法</span>有许多用例。举一个<span style="color: black;">平常</span>的例子,它在<span style="color: black;">必须</span>跨组织共享多个版本的私人报告/备忘录的<span style="color: black;">状况</span>下<span style="color: black;">尤其</span>有用。要从输入 PDF 中删除页面,<span style="color: black;">咱们</span><span style="color: black;">必要</span><span style="color: black;">包括</span> PDF 文件路径,<span style="color: black;">而后</span>满足以下参数:</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">pageStart:指定从哪个页面(从 1 <span style="color: black;">起始</span>)<span style="color: black;">起始</span>删除,并删除该页面</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">pageEnd:指定从哪个页面(从 1 <span style="color: black;">起始</span>)完成删除,并删除该页面</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">咱们</span><span style="color: black;">能够</span>像<span style="color: black;">这般</span>构造<span style="color: black;">咱们</span>的页面删除 API 调用,再次从<span style="color: black;">咱们</span>的 API 密钥授权片段<span style="color: black;">起始</span>:</p><span style="color: black;">
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">ApiClient defaultClient = </p>Configuration.getDefaultApiClient();
    </span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">// Configure API key authorization: Apikey</p><span style="color: black;">
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">ApiKeyAuth Apikey = (ApiKeyAuth)</p>defaultClient.getAuthentication("Apikey");
    </span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Apikey.setApiKey("YOUR API KEY");</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">//Apikey.setApiKeyPrefix("Token");</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">EditPdfApi apiInstance = new EditPdfApi();</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">File inputFile = new File("/path/to/inputfile"); // File | Input file to perform the operation on.</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Integer pageStart = 56; // Integer | Page number (1 based) to start deleting pages from (inclusive).</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Integer pageEnd = 56; // Integer | Page number (1 based) to stop deleting pages from (inclusive).</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">try {</p><span style="color: black;">
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> byte[] result = </p>apiInstance.editPdfDeletePages(inputFile, pageStart, pageEnd);
    </span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> System.out.println(result);</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">} catch (ApiException e) {</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">System.err.println("Exception when calling EditPdfApi#editPdfDeletePages");</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> e.printStackTrace();</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">}</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">旋转 PDF 文档中的所有页面</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">无论是有意还是<span style="color: black;">因为</span>疏忽,大型 PDF 文件(尤其是从 JPG、PNG、PowerPoint PPTX 等格式转换而来的文件)<span style="color: black;">一般</span><span style="color: black;">包括</span>以不<span style="color: black;">期盼</span>的<span style="color: black;">方向</span>旋转的页面。当 PDF 文件中的每一页都错误地旋转到相同的<span style="color: black;">方向</span>时,<span style="color: black;">咱们</span>很幸运:<span style="color: black;">咱们</span><span style="color: black;">能够</span><span style="color: black;">运用</span>简单的“旋转所有页面”<span style="color: black;">处理</span><span style="color: black;">方法</span>来立即纠正问题。<span style="color: black;">咱们</span>只<span style="color: black;">必须</span>密切关注rotationAngle这个<span style="color: black;">处理</span><span style="color: black;">方法</span>中的参数,<span style="color: black;">由于</span>它只接受正(向右旋转)和负(向左旋转)整数,它们只能是 90 度的倍数。一旦<span style="color: black;">咱们</span>正确指定了这个参数,<span style="color: black;">咱们</span>就<span style="color: black;">能够</span>构建 API,如下面的示例所示:</p><span style="color: black;">
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">ApiClient defaultClient =</p>Configuration.getDefaultApiClient();
    </span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">// Configure API key authorization: Apikey</p><span style="color: black;">
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">ApiKeyAuth Apikey = (ApiKeyAuth) </p>defaultClient.getAuthentication("Apikey");
    </span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Apikey.setApiKey("YOUR API KEY");</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">//Apikey.setApiKeyPrefix("Token");</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">EditPdfApi apiInstance = new EditPdfApi();</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">File inputFile = new File("/path/to/inputfile"); // File | Input file to perform the operation on.</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Integer rotationAngle = 56; // Integer | The angle to rotate the page in degrees, must be a multiple of 90 degrees, e.g. 90, 180, 270, or -90, -180, -270, etc.</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">try {</p><span style="color: black;">
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> byte[] result = </p>apiInstance.editPdfRotateAllPages(inputFile, rotationAngle);
    </span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> System.out.println(result);</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">} catch (ApiException e) {</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> System.err.println("Exception when calling EditPdfApi#editPdfRotateAllPages");</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> e.printStackTrace();</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">}</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">旋转 PDF 文档中的范围、页面子集</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">当 PDF 文档中<span style="color: black;">仅有</span>特定页面子集<span style="color: black;">必须</span>旋转调整时,无需担心:<span style="color: black;">咱们</span><span style="color: black;">能够</span><span style="color: black;">容易</span>执行先前概述的操作的更<span style="color: black;">详细</span>版本。<span style="color: black;">咱们</span>只<span style="color: black;">必须</span>再次配置旋转<span style="color: black;">方向</span>,以及指定操作应该从哪里<span style="color: black;">起始</span>和结束的两个参数:</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">rotationAngle:定义指定页面将旋转多少度;接受正(向右旋转)和负(向左旋转)整数,它们是 90 度的倍数</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">pageStart:指定子集中的哪一页(从 1 <span style="color: black;">起始</span>),并<span style="color: black;">包括</span>该页</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">pageEnd:指定要在子集中的哪个页面(基于 1)完成,并<span style="color: black;">包括</span>此页面</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">此 API 调用的结构应如下所示:</p><span style="color: black;">
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">ApiClient defaultClient = </p>Configuration.getDefaultApiClient();
    </span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">// Configure API key authorization: Apikey</p><span style="color: black;">
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">ApiKeyAuth Apikey = (ApiKeyAuth) </p>defaultClient.getAuthentication("Apikey");
    </span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Apikey.setApiKey("YOUR API KEY");</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">//Apikey.setApiKeyPrefix("Token");</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">EditPdfApi apiInstance = new EditPdfApi();</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">File inputFile = new File("/path/to/inputfile"); // File | Input file to perform the operation on.</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Integer rotationAngle = 56; // Integer | The angle to rotate the page in degrees, must be a multiple of 90 degrees, e.g. 90, 180, 270, or -90, -180, -270, etc.</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Integer pageStart = 56; // Integer | Page number (1 based) to start rotating pages from (inclusive).</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Integer pageEnd = 56; // Integer | Page number (1 based) to stop rotating pages from (inclusive).</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">try {</p><span style="color: black;">
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> byte[] result = </p>apiInstance.editPdfRotatePageRange(inputFile, rotationAngle, pageStart, pageEnd);
    </span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> System.out.println(result);</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">} catch (ApiException e) {</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">System.err.println("Exception when calling EditPdfApi#editPdfRotatePageRange");</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> e.printStackTrace();</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">}</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">运用</span><span style="color: black;">以上</span>示例构建 API 调用后,一切就绪:<span style="color: black;">再也不</span><span style="color: black;">必须</span>代码。<span style="color: black;">每一个</span> API 响应都会为新的 PDF 文件生成一个编码字符串,可用于<span style="color: black;">按照</span><span style="color: black;">必须</span>生成新文件或更新现有文档。</p>





九天一剑 发表于 2024-8-21 12:05:14

你的努力一定会被看见,相信自己,加油。

4lqedz 发表于 2024-10-4 07:54:45

大势所趋,用于讽刺一些制作目的就是为了跟风玩梗,博取眼球的作品。

4lqedz 发表于 2024-10-10 06:54:13

论坛是一个舞台,让我们在这里尽情的释放自己。

4zhvml8 发表于 2024-10-11 02:55:25

你的话深深触动了我,仿佛说出了我心里的声音。

qzmjef 发表于 2024-11-8 12:43:44

你的留言真是温暖如春,让我感受到了无尽的支持与鼓励。
页: [1]
查看完整版本: 怎么样运用 Java 在 PDF 文档中添加、删除或旋转页面