IRONSOFTWAREHOME
Website & System Logins

import com.ironsoftware.ironpdf.PdfDocument;
import com.ironsoftware.ironpdf.headerfooter.TextHeaderFooter;
import com.ironsoftware.ironpdf.render.ChromeHttpLoginCredentials;
import com.ironsoftware.ironpdf.render.ChromePdfRenderOptions;
import java.io.IOException;
import java.nio.file.Paths;

String url = "http://localhost:51169/Invoice";

ChromePdfRenderOptions renderOptions = new ChromePdfRenderOptions();
renderOptions.setMarginTop(50);
renderOptions.setMarginBottom(50);

// Set Login Credentials to bypass basic authentication
ChromeHttpLoginCredentials loginCredentials = new ChromeHttpLoginCredentials();
loginCredentials.setNetworkUsername("testUser");
loginCredentials.setNetworkPassword("testPassword");

try {
    PdfDocument webpage = PdfDocument.renderUrlAsPdf(url, loginCredentials);
    TextHeaderFooter textHeader = new TextHeaderFooter();
    textHeader.setCenterText("{pdf-title");
    textHeader.setDrawDividerLine(true);
    textHeader.setFontSize(16);
    webpage.addTextHeader(textHeader);

    TextHeaderFooter textFooter = new TextHeaderFooter();
    textFooter.setLeftText("{date} {time}");
    textFooter.setRightText("Page {page} of {total-pages}");
    textFooter.setDrawDividerLine(true);
    textFooter.setFontSize(14);
    webpage.addTextFooter(textFooter);
    
    webpage.saveAs(Paths.get("assets/UrlToPdfExample.pdf"));
} catch(IOException e) {
    e.printStackTrace();
}
mvn install
Website & System Logins

Website & System Logins

為將位於HTML表單和密碼保護網站目錄後的網頁轉換成PDF檔,最佳的做法是放棄程式化驗證和表單提交,轉而直接從本地檔案或HTML字串渲染標記,如IronPDF登入程式資源頁面所述。 然而,在需要手動獲取待轉換網頁源程式碼的情況下,如果這樣做繁瑣、耗時或不可行,IronPDF可以輕鬆無痛地從這些受限區域渲染PDF內容。

要轉換位於密碼保護目錄後的網頁,請指定一組有效的網路憑證供IronPdf的PDF Renderer與ChromeHttpLoginCredentials物件一起使用。 接下來,將PdfDocument.renderUrlAsPdf

Learn about ChromeHttpLoginCredentials for Java
在 GitHub 查看

準備好開始了嗎?

版本:2026.6剛剛發布

Key in blue circle

立即免費取得 30 天試用金鑰

Your trial license will be sent to your email address

無任何限制。100% 解鎖。無需信用卡。

OR
bullet_checked無需信用卡或建立帳號無任何限制。100% 解鎖。無需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
預訂您的免費 即時演示
Booking Badge

全球數百萬工程師的信任

Iron Software的客戶商標
獲取您的無義務諮詢
填寫以下表格或發送電子郵件至sales@ironsoftware.com
您的詳細資訊始終保持機密。
全球數百萬工程師的信任
Iron Software的客戶商標
立即獲取您的30天試用金鑰
無需信用卡或帳戶建立
PDF的Java Maven程式庫
using Maven 安裝

版本: 2026.6

<dependency>
   <groupId>com.ironsoftware</groupId>
   <artifactId>ironpdf</artifactId>
   <version>2026.6.1</version>
</dependency>
https://central.sonatype.com/artifact/com.ironsoftware/ironpdf/2026.6.1
or
Java PDF JAR
下載 JAR

版本: 2026.6

手動安裝到您的專案中