เพิ่มลายน้ำผ่าน PHP

เพิ่มลายน้ำลงในเอกสาร PDF โดยใช้ Aspose.PDF สำหรับ PHP via Java

เพิ่มลายน้ำลงในไฟล์ PDF โดยใช้เครื่องมือ PHP via Java

ในการเพิ่มลายน้ำลงในไฟล์ PDF เราจะใช้ Aspose.PDF สำหรับ PHP ผ่าน Java API ซึ่งเป็นเครื่องมือจัดการเอกสารที่อุดมไปด้วยคุณสมบัติ ทรงพลัง และใช้งานง่ายใน php-javaติดตั้ง Tomcat 9.0 เวอร์ชัน ในตำแหน่งใดก็ได้เพิ่ม Aspose.pdf.war สำหรับรายละเอียดเพิ่มเติมตรวจสอบหน้า GitHub

เพิ่มลายน้ำผ่าน PHP


ในการลองใช้รหัสในสภาพแวดล้อมของคุณคุณต้อง Aspose.PDF for PHP ผ่าน Java

1.โหลดไฟล์ PDF ที่มีอินสแตนซ์ของเอกสาร 1.สร้างตัวอย่างของ WaterMarkArtifact 1.ตั้งค่าคุณสมบัติของวัตถุ WaterMarkArtifact 1.เพิ่มลายน้ำโดยใช้วิธีการเพิ่มระดับคอลเลกชัน Aspose.Pf.Page.Artifacts 1.บันทึกไฟล์ PDF

เพิ่มลายน้ำลงในไฟล์ PDF - PHP

    // Open document
    $document = new Document($inputFile);
            
    $formattedText = new facades_FormattedText("Watermark", 
        (new Color())->getBlue()->toRgb(),
        (new facades_FontStyle())->Courier, 
        (new facades_EncodingType())->Identity_h, 
        true, 72.0);

    $horizontalAlignment = new HorizontalAlignment();
    $verticalAlignment = new VerticalAlignment();

    $artifact = new WatermarkArtifact();        
    $artifact->setText($formattedText);        
    $artifact->setArtifactHorizontalAlignment ($horizontalAlignment->Center);
    $artifact->setArtifactVerticalAlignment ($verticalAlignment->Center);
    $artifact->setRotation(45);
    $artifact->setOpacity(0.5);
    $artifact->setBackground(true);
    $document->getPages()->get_Item(1)->getArtifacts()->add($artifact);
    
    // Save output document
    $document->save($outputFile);
    $document->close();