Υπογραφή PDF με barcode χρησιμοποιώντας HIBC σε Java

Αν αναπτύσσετε λογισμικό φαρμακευτικής ή υγειονομικής εφοδιαστικής αλυσίδας, πιθανότατα έχετε αντιμετωπίσει το πρόβλημα της παρακολούθησης με χαρτί, χαμένων υπογραφών και εφιάλτες ελέγχων. Η υπογραφή ενός PDF με barcode—ιδιαίτερα με HIBC Data Matrix ή QR code—δημιουργεί ένα ανιχνεύσιμο, μηχανικά αναγνώσιμο ίχνος που αντέχει στην εκτύπωση, τη σάρωση και την κανονιστική ανασκόπηση. Σε αυτό το tutorial θα δείτε ακριβώς πώς να προσθέσετε τόσο Data Matrix όσο και QR barcodes σε ένα PDF χρησιμοποιώντας το GroupDocs.Signature for Java.

Γρήγορες απαντήσεις

  • Ποια βιβλιοθήκη διαχειρίζεται τα HIBC barcodes σε Java; GroupDocs.Signature for Java.
  • Ποια μορφή barcode είναι η πιο συμπαγής; Data Matrix – ιδανική για μικρές ετικέτες.
  • Μπορώ να προσθέσω τόσο QR όσο και Data Matrix στο ίδιο PDF; Ναι, απλώς δημιουργήστε ξεχωριστά QrCodeSignOptions.
  • Χρειάζεται σύνδεση στο διαδίκτυο κατά την εκτέλεση; Όχι, η βιβλιοθήκη λειτουργεί πλήρως offline μετά την εγκατάσταση.
  • Ποια έκδοση Java συνιστάται; Java 11+ για απόδοση παραγωγικού επιπέδου.

Τι είναι η υπογραφή PDF με HIBC barcode;

Signature είναι η βασική κλάση του GroupDocs.Signature που αντιπροσωπεύει ένα PDF έγγραφο και επιτρέπει την ενσωμάτωση ψηφιακών υπογραφών. Η κλάση Signature στο GroupDocs.Signature for Java παρέχει μεθόδους για την ενσωμάτωση HIBC barcode ως ψηφιακές υπογραφές. Υπογράφοντας ένα PDF με HIBC barcode δημιουργείτε ένα επαληθεύσιμο, ανιχνεύσιμο αρχείο που μπορεί να σαρωθεί σε οποιοδήποτε σημείο της εφοδιαστικής αλυσίδας.

Γιατί να χρησιμοποιήσετε μαζί Data Matrix και QR codes;

Data Matrix προσφέρει το μικρότερο αποτύπωμα ενώ μπορεί να περιέχει έως 2.335 αλφαριθμητικούς χαρακτήρες, καθιστώντας το τέλειο για πυκνά περιοχές ετικετών. QR codes, από την άλλη, υποστηρίζουν έως 4.296 χαρακτήρες και είναι καθολικά αναγνώσιμα από smartphones. Ο συνδυασμός και των δύο παρέχει την καλύτερη ισορροπία μεταξύ αποδοτικότητας χώρου και χωρητικότητας δεδομένων, εξασφαλίζοντας ότι κάθε ενδιαφερόμενος—από σαρωτές αποθήκης μέχρι κινητές εφαρμογές—μπορεί να διαβάσει τις πληροφορίες που χρειάζεται.

Προαπαιτούμενα

  • JDK 11 ή νεότερο (Java 8 λειτουργεί αλλά το Java 11+ συνιστάται για βέλτιστη απόδοση).
  • IDE όπως IntelliJ IDEA, Eclipse ή VS Code με επεκτάσεις Java.
  • Maven ή Gradle για διαχείριση εξαρτήσεων (παραδείγματα παρακάτω).
  • Δείγμα PDF (π.χ., sample.pdf) για δοκιμή της υλοποίησης.
  • Έγκυρη άδεια GroupDocs.Signature (δωρεάν δοκιμή για ανάπτυξη, επί πληρωμή άδεια για παραγωγή).

Ρύθμιση του GroupDocs.Signature για Java

Διαμόρφωση Maven

Add the dependency to your pom.xml:

<dependency>
    <groupId>com.groupdocs</groupId>
    <artifactId>groupdocs-signature</artifactId>
    <version>23.12</version>
</dependency>

Διαμόρφωση Gradle

For Gradle projects, add this to your build.gradle:

implementation 'com.groupdocs:groupdocs-signature:23.12'

Επιλογή άμεσης λήψης

You can also download the JAR file directly from GroupDocs.Signature for Java releases and add it to your project’s classpath manually. This approach works well in restricted‑network environments.

Απόκτηση άδειας

Request a free trial or temporary license from GroupDocs to remove watermarks and unlock all features. Production deployments require a purchased license.

Βασική αρχικοποίηση

Signature is the entry point for all signing operations. It loads the PDF, applies the barcode, and writes the signed file.

import com.groupdocs.signature.Signature;

class InitializeSignature {
    public static void main(String[] args) {
        Signature signature = new Signature("sample.pdf");
        // Proceed with signing operations...
    }
}

Πώς να δημιουργήσετε PDF Data Matrix με HIBC barcode;

Instantiate Signature with your source PDF, set QrCodeSignOptions to the Data Matrix format, provide a correctly formatted HIBC string, and call sign(). The library writes the signed PDF to the destination, preserving layout and embedding the barcode as a tamper‑evident signature.

QrCodeSignOptions specifies the barcode type, content, size, and placement for a signature.

  1. Import the required classes – these give you access to the signature engine and Data Matrix options.
import com.groupdocs.signature.Signature;
import com.groupdocs.signature.options.sign.QrCodeSignOptions;
import com.groupdocs.signature.domain.qrcodes.QrCodeTypes;
  1. Instantiate the Signature object with absolute paths for source and destination files.
String sourceFilePath = "YOUR_DOCUMENT_DIRECTORY";
String destinFilePath = "YOUR_OUTPUT_DIRECTORY/SignWithHIBCLICQR.pdf";

final Signature signature = new Signature(sourceFilePath);
  1. Configure the Data Matrix options – set the HIBC string, choose QrCodeTypes.HIBCLICDataMatrix, and define placement coordinates. QrCodeTypes enumerates the supported barcode formats for HIBC signatures.
QrCodeSignOptions hibcLic_QR = new QrCodeSignOptions("A123PROD30917/75#422011907#GP293", QrCodeTypes.HIBCLICQR);
hibcLic_QR.setLeft(1); // Set the position from left
hibcLic_QR.setTop(1);   // Set the position from top
hibcLic_QR.setReturnContent(true); // Return content after signing
hibcLic_QR.setReturnContentType(FileType.PNG); // Specify return content type as PNG
  1. Apply the signature to the PDF.
signature.sign(destinFilePath, hibcLic_QR);
  1. Dispose of resources to free file handles and avoid memory leaks.
finally {
    if (signature != null) signature.dispose();
}

Πλήρες λειτουργικό παράδειγμα

Here’s the full flow in a single block (the placeholders represent the exact code you’ll paste from the earlier snippets):

import com.groupdocs.signature.Signature;
import com.groupdocs.signature.options.sign.QrCodeSignOptions;
import com.groupdocs.signature.domain.qrcodes.QrCodeTypes;

public class HibcQrSigning {
    public static void main(String[] args) {
        String sourceFilePath = "sample.pdf";
        String destinFilePath = "output/SignWithHIBCLICQR.pdf";
        
        Signature signature = null;
        try {
            signature = new Signature(sourceFilePath);
            
            QrCodeSignOptions hibcLic_QR = new QrCodeSignOptions(
                "A123PROD30917/75#422011907#GP293", 
                QrCodeTypes.HIBCLICQR
            );
            hibcLic_QR.setLeft(1);
            hibcLic_QR.setTop(1);
            hibcLic_QR.setReturnContent(true);
            hibcLic_QR.setReturnContentType(FileType.PNG);
            
            signature.sign(destinFilePath, hibcLic_QR);
            System.out.println("PDF signed successfully with HIBC QR code");
            
        } catch (Exception e) {
            System.err.println("Error signing PDF: " + e.getMessage());
            e.printStackTrace();
        } finally {
            if (signature != null) signature.dispose();
        }
    }
}

Άμεση απάντηση (40–70 λέξεις)

To create a Data Matrix PDF, instantiate Signature with your source PDF, set QrCodeSignOptions to QrCodeTypes.HIBCLICDataMatrix and provide a correctly formatted HIBC string, then call signature.sign(outputPath, options). The library writes the signed PDF to the destination, preserving layout and embedding the barcode as a tamper‑evident signature.

Πώς να προσθέσετε QR code PDF χρησιμοποιώντας το GroupDocs.Signature;

Load the PDF, configure QrCodeSignOptions for the QR format, and call sign(). The library scales the QR image for readability and positions it based on the coordinates you set, avoiding overlap with existing content. This ensures the barcode remains scannable after printing and complies with HIBC standards.

QrCodeSignOptions defines the QR barcode’s content, size, and position.

  1. Import QR‑specific classes
QrCodeSignOptions hibcLic_AZ = new QrCodeSignOptions("A123PROD30917/75#422011907#GP293", QrCodeTypes.HIBCLICAztec);
hibcLic_AZ.setLeft(1); // Set the position from left
hibcLic_AZ.setTop(200); // Set the position from top
hibcLic_AZ.setReturnContent(true); // Return content after signing
hibcLic_AZ.setReturnContentType(FileType.PNG); // Specify return content type as PNG
  1. Create and configure QR options – note the use of QrCodeTypes.HIBCLICQR.
signature.sign(destinFilePath, hibcLic_AZ);
  1. Sign the document
QrCodeSignOptions hibcLic_DM = new QrCodeSignOptions("A123PROD30917/75#422011907#GP293", QrCodeTypes.HIBCLICDataMatrix);
hibcLic_DM.setLeft(1); // Set the position from left
hibcLic_DM.setTop(400); // Set the position from top
hibcLic_DM.setReturnContent(true); // Return content after signing
hibcLic_DM.setReturnContentType(FileType.PNG); // Specify return content type as PNG

Direct answer: Use QrCodeTypes.HIBCLICQR in QrCodeSignOptions, set the HIBC content string, position the code with setLeft() and setTop(), then call signature.sign(outputPath, options). The QR barcode is embedded instantly, ready for smartphone or scanner capture.

Συνηθισμένα λάθη προς αποφυγή

1. Παράλειψη απελευθέρωσης πόρων

Wrong:

Signature signature = new Signature("sample.pdf");
signature.sign(destinFilePath, options);
// Oops, no dispose() call

Fix: Wrap the Signature usage in a try‑with‑resources block or explicitly call close() in a finally clause.

2. Χρήση λανθασμένων συμβολοσειρών μορφής HIBC

Wrong: Using generic strings like “12345”.
Fix: Follow the HIBCC standard (e.g., A123PROD30917/75#422011907#GP293). Validate with the HIBCC online validator.

3. Σκληρή κωδικοποίηση διαδρομών αρχείων

Wrong:

String sourceFilePath = "C:/Users/John/Documents/test.pdf";

Fix: Store paths in a configuration file or environment variable and read them at runtime.

4. Αγνόηση συγκρούσεων θέσης barcode

Place barcodes away from existing text or signatures. Use PDF coordinates (origin is bottom‑left) and test with a printed sample.

5. Μη δοκιμή με πραγματικούς σαρωτές

Print the signed PDF and scan it with the exact hardware used in your workflow. Verify readability at different print qualities.

Πρακτικές εφαρμογές στην υγειονομική περίθαλψη

ΣενάριοΣυνιστώμενο barcodeΓιατί ταιριάζει
Φαρμακευτική διανομήQR CodeΥψηλή χωρητικότητα δεδομένων, ευρέως σαρωμένο από smartphones.
Διαχείριση αποθεμάτωνData MatrixΜικρό αποτύπωμα, ιδανικό για πυκνές ετικέτες ραφιών.
Κανονιστική συμμόρφωση (FDA 21 CFR Part 11)QR + Data MatrixΔιπλή μορφή παρέχει εφεδρεία και δυνατότητα ελέγχου.
Παρακολούθηση ιατρικών συσκευώνAztec CodeΣυμπαγές μέγεθος λειτουργεί σε συσκευασία περιορισμένου χώρου.

Σκέψεις απόδοσης και βέλτιστες πρακτικές

Μοτίβο επεξεργασίας παρτίδας

List<String> filesToSign = getFileList();
for (String filePath : filesToSign) {
    Signature signature = null;
    try {
        signature = new Signature(filePath);
        // Sign and save
    } finally {
        if (signature != null) signature.dispose();
    }
}
  • Create a new Signature instance per file to keep memory usage low.
  • Use a fixed thread pool (Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() - 1)) for parallel processing, but monitor heap size because each Signature holds the full PDF in memory.
  • Keep libraries updated
    GroupDocs releases improve processing speed by up to 20 % and add new HIBC compliance features. Schedule quarterly dependency checks.
  • Caching templates
    Load a PDF template once, clone it for each barcode variant, and sign the clones. This reduces I/O and speeds up high‑volume workflows.

Συχνές ερωτήσεις

Q: Μπορεί το GroupDocs.Signature να υπογράψει τύπους αρχείων εκτός του PDF;
A: Ναι, υποστηρίζει επίσης DOCX, XLSX, PPTX, PNG, JPEG και TIFF με το ίδιο API υπογραφής barcode.

Q: Πώς αντιμετωπίζω τα σφάλματα “Invalid barcode content”;
A: Επαληθεύστε ότι η HIBC συμβολοσειρά ακολουθεί ακριβώς τη σύνταξη HIBCC, χρησιμοποιήστε τον online validator και βεβαιωθείτε ότι χρησιμοποιείτε τη σωστή σταθερά QrCodeTypes για τη μορφή που έχετε επιλέξει.

Q: Ποια είναι η μέγιστη χωρητικότητα δεδομένων για κάθε μορφή HIBC;
A: QR ≈ 4.296 αλφαριθμητικούς χαρακτήρες, Aztec ≈ 3.832 αριθμητικούς / 3.067 αλφαριθμητικούς, Data Matrix ≈ 3.116 αριθμητικούς / 2.335 αλφαριθμητικούς. Κρατήστε τους κώδικες κάτω από 200 χαρακτήρες για βέλτιστη αξιοπιστία σάρωσης.

Q: Είναι δυνατόν να ενσωματωθούν πολλαπλοί τύποι barcode σε ένα PDF;
A: Απόλυτα. Δημιουργήστε ξεχωριστά αντικείμενα QrCodeSignOptions με διαφορετικές θέσεις και καλέστε signature.sign() για το καθένα. Απλώς βεβαιωθείτε ότι δεν επικαλύπτονται.

Q: Χρειάζεται σύνδεση στο διαδίκτυο για υπογραφή κατά την εκτέλεση;
A: Όχι. Αφού το JAR βρίσκεται στο classpath και η άδεια ενεργοποιηθεί, όλες οι λειτουργίες εκτελούνται τοπικά.

Πρόσθετοι πόροι


Τελευταία ενημέρωση: 2026-09-15
Δοκιμασμένο με: GroupDocs.Signature 23.12 for Java
Συγγραφέας: GroupDocs


Σχετικά μαθήματα