@@ -30,15 +30,21 @@ This file is part of the iText (R) project.
30
30
import com .itextpdf .kernel .font .PdfFontFactory ;
31
31
import com .itextpdf .kernel .font .PdfFontFactory .EmbeddingStrategy ;
32
32
import com .itextpdf .kernel .geom .Rectangle ;
33
+ import com .itextpdf .kernel .pdf .PageLabelNumberingStyle ;
34
+ import com .itextpdf .kernel .pdf .PdfDictionary ;
33
35
import com .itextpdf .kernel .pdf .PdfDocument ;
34
36
import com .itextpdf .kernel .pdf .PdfDocumentInfo ;
37
+ import com .itextpdf .kernel .pdf .PdfName ;
38
+ import com .itextpdf .kernel .pdf .PdfNumber ;
39
+ import com .itextpdf .kernel .pdf .PdfPage ;
35
40
import com .itextpdf .kernel .pdf .PdfString ;
36
41
import com .itextpdf .kernel .pdf .PdfVersion ;
37
42
import com .itextpdf .kernel .pdf .PdfViewerPreferences ;
38
43
import com .itextpdf .kernel .pdf .PdfWriter ;
39
44
import com .itextpdf .kernel .pdf .WriterProperties ;
40
45
import com .itextpdf .kernel .pdf .action .PdfAction ;
41
46
import com .itextpdf .kernel .pdf .annot .PdfLinkAnnotation ;
47
+ import com .itextpdf .kernel .pdf .filespec .PdfFileSpec ;
42
48
import com .itextpdf .kernel .pdf .tagging .IStructureNode ;
43
49
import com .itextpdf .kernel .pdf .tagging .PdfNamespace ;
44
50
import com .itextpdf .kernel .pdf .tagging .PdfStructTreeRoot ;
@@ -581,14 +587,14 @@ public void checkBibliographicEntryTest() throws IOException, XMPException, Inte
581
587
String outFile = DESTINATION_FOLDER + "bibliographicEntryTest.pdf" ;
582
588
String cmpFile = SOURCE_FOLDER + "cmp_bibliographicEntryTest.pdf" ;
583
589
584
- try (PdfDocument pdfDocument = new PdfDocument (new PdfWriter (outFile , new WriterProperties ().setPdfVersion (PdfVersion .PDF_2_0 )))){
590
+ try (PdfDocument pdfDocument = new PdfDocument (
591
+ new PdfWriter (outFile , new WriterProperties ().setPdfVersion (PdfVersion .PDF_2_0 )))) {
585
592
Document document = new Document (pdfDocument );
586
593
PdfFont font = PdfFontFactory .createFont (FONT_FOLDER + "FreeSans.ttf" ,
587
594
"WinAnsi" , EmbeddingStrategy .FORCE_EMBEDDED );
588
595
document .setFont (font );
589
596
createSimplePdfUA2Document (pdfDocument );
590
597
591
-
592
598
Paragraph section = new Paragraph ("Bibliography section:\n " );
593
599
section .getAccessibilityProperties ().setRole (StandardRoles .SECT );
594
600
Paragraph bibliography = new Paragraph ("1. Author A. Title of Book. Publisher, Year." );
@@ -600,6 +606,116 @@ public void checkBibliographicEntryTest() throws IOException, XMPException, Inte
600
606
compareAndValidate (outFile , cmpFile );
601
607
}
602
608
609
+ @ Test
610
+ public void checkMetadataNoTitleTest () throws IOException , XMPException {
611
+ String outFile = DESTINATION_FOLDER + "pdfuaMetadataNoTitleTest.pdf" ;
612
+ try (PdfDocument pdfDocument = new PdfDocument (new PdfWriter (outFile , new WriterProperties ().setPdfVersion (PdfVersion .PDF_2_0 )))) {
613
+ byte [] bytes = Files .readAllBytes (Paths .get (SOURCE_FOLDER + "simplePdfUA2.xmp" ));
614
+ XMPMeta xmpMeta = XMPMetaFactory .parse (new ByteArrayInputStream (bytes ));
615
+ pdfDocument .setXmpMetadata (xmpMeta );
616
+ pdfDocument .setTagged ();
617
+ pdfDocument .getCatalog ().setViewerPreferences (new PdfViewerPreferences ().setDisplayDocTitle (true ));
618
+ pdfDocument .getCatalog ().setLang (new PdfString ("en-US" ));
619
+ }
620
+ Assert .assertNotNull (new VeraPdfValidator ().validate (outFile ));// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
621
+ }
622
+
623
+ @ Test
624
+ public void checkMetadataDisplayDocTitleFalseTest () throws IOException , XMPException {
625
+ String outFile = DESTINATION_FOLDER + "pdfuaMetadataDisplayDocTitleFalseTest.pdf" ;
626
+ try (PdfDocument pdfDocument = new PdfDocument (new PdfWriter (outFile , new WriterProperties ().setPdfVersion (PdfVersion .PDF_2_0 )))) {
627
+ byte [] bytes = Files .readAllBytes (Paths .get (SOURCE_FOLDER + "simplePdfUA2.xmp" ));
628
+ XMPMeta xmpMeta = XMPMetaFactory .parse (new ByteArrayInputStream (bytes ));
629
+ pdfDocument .setXmpMetadata (xmpMeta );
630
+ pdfDocument .setTagged ();
631
+ pdfDocument .getCatalog ().setViewerPreferences (new PdfViewerPreferences ().setDisplayDocTitle (false ));
632
+ pdfDocument .getCatalog ().setLang (new PdfString ("en-US" ));
633
+ PdfDocumentInfo info = pdfDocument .getDocumentInfo ();
634
+ info .setTitle ("PdfUA2 Title" );
635
+ }
636
+ Assert .assertNotNull (new VeraPdfValidator ().validate (outFile ));// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
637
+ }
638
+
639
+ @ Test
640
+ public void checkMetadataNoViewerPrefTest () throws IOException , XMPException {
641
+ String outFile = DESTINATION_FOLDER + "pdfuaMetadataNoViewerPrefTest.pdf" ;
642
+ try (PdfDocument pdfDocument = new PdfDocument (new PdfWriter (outFile , new WriterProperties ().setPdfVersion (PdfVersion .PDF_2_0 )))) {
643
+ byte [] bytes = Files .readAllBytes (Paths .get (SOURCE_FOLDER + "simplePdfUA2.xmp" ));
644
+ XMPMeta xmpMeta = XMPMetaFactory .parse (new ByteArrayInputStream (bytes ));
645
+ pdfDocument .setXmpMetadata (xmpMeta );
646
+ pdfDocument .setTagged ();
647
+ pdfDocument .getCatalog ().setLang (new PdfString ("en-US" ));
648
+ PdfDocumentInfo info = pdfDocument .getDocumentInfo ();
649
+ info .setTitle ("PdfUA2 Title" );
650
+ }
651
+ Assert .assertNotNull (new VeraPdfValidator ().validate (outFile ));// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
652
+ }
653
+
654
+ @ Test
655
+ public void checkEmbeddedFileTest () throws IOException , XMPException , InterruptedException {
656
+ String outFile = DESTINATION_FOLDER + "pdfuaEmbeddedFileTest.pdf" ;
657
+ String cmpFile = SOURCE_FOLDER + "cmp_pdfuaEmbeddedFileTest.pdf" ;
658
+
659
+ try (PdfDocument pdfDocument = new PdfDocument (new PdfWriter (outFile , new WriterProperties ().setPdfVersion (PdfVersion .PDF_2_0 )))) {
660
+ createSimplePdfUA2Document (pdfDocument );
661
+ PdfFont font = PdfFontFactory .createFont (FONT_FOLDER + "FreeSans.ttf" ,
662
+ "WinAnsi" , EmbeddingStrategy .FORCE_EMBEDDED );
663
+ Paragraph paragraph = new Paragraph ("Hello PdfUA2" ).setFont (font );
664
+ new Document (pdfDocument ).add (paragraph );
665
+ PdfFileSpec spec = PdfFileSpec .createEmbeddedFileSpec (pdfDocument , SOURCE_FOLDER + "sample.wav" , "sample.wav" , "sample" , null , null );
666
+ pdfDocument .addFileAttachment ("specificname" , spec );
667
+ }
668
+ compareAndValidate (outFile , cmpFile );
669
+ }
670
+
671
+ @ Test
672
+ public void checkEmbeddedFileNoDescTest () throws IOException , XMPException {
673
+ String outFile = DESTINATION_FOLDER + "pdfuaEmbeddedFileNoDescTest.pdf" ;
674
+ try (PdfDocument pdfDocument = new PdfDocument (new PdfWriter (outFile , new WriterProperties ().setPdfVersion (PdfVersion .PDF_2_0 )))) {
675
+ createSimplePdfUA2Document (pdfDocument );
676
+ PdfFileSpec spec = PdfFileSpec .createEmbeddedFileSpec (pdfDocument , SOURCE_FOLDER + "sample.wav" , "sample.wav" , "sample" , null , null );
677
+ ((PdfDictionary ) spec .getPdfObject ()).remove (PdfName .Desc );
678
+ pdfDocument .addFileAttachment ("specificname" , spec );
679
+ }
680
+ Assert .assertNotNull (new VeraPdfValidator ().validate (outFile ));// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
681
+ }
682
+
683
+ @ Test
684
+ public void checkPageLabelTest () throws IOException , XMPException , InterruptedException {
685
+ String outFile = DESTINATION_FOLDER + "pdfuaPageLabelTest.pdf" ;
686
+ String cmpFile = SOURCE_FOLDER + "cmp_pdfuaPageLabelTest.pdf" ;
687
+
688
+ try (PdfDocument pdfDocument = new PdfDocument (new PdfWriter (outFile , new WriterProperties ().setPdfVersion (PdfVersion .PDF_2_0 )))) {
689
+ createSimplePdfUA2Document (pdfDocument );
690
+ PdfPage pdfPage = pdfDocument .addNewPage ();
691
+ PdfFont font = PdfFontFactory .createFont (FONT_FOLDER + "FreeSans.ttf" ,
692
+ "WinAnsi" , EmbeddingStrategy .FORCE_EMBEDDED );
693
+ Paragraph paragraph = new Paragraph ("Hello PdfUA2" ).setFont (font );
694
+ new Document (pdfDocument ).add (paragraph );
695
+ pdfPage .setPageLabel (PageLabelNumberingStyle .DECIMAL_ARABIC_NUMERALS , null , 1 );
696
+ }
697
+ compareAndValidate (outFile , cmpFile );
698
+ }
699
+
700
+ @ Test
701
+ public void checkPageNumberAndLabelTest () throws IOException , XMPException , InterruptedException {
702
+ String outFile = DESTINATION_FOLDER + "pdfuaPageNumLabelTest.pdf" ;
703
+ String cmpFile = SOURCE_FOLDER + "cmp_pdfuaPageNumLabelTest.pdf" ;
704
+
705
+ try (PdfDocument pdfDocument = new PdfDocument (new PdfWriter (outFile , new WriterProperties ().setPdfVersion (PdfVersion .PDF_2_0 )))) {
706
+ createSimplePdfUA2Document (pdfDocument );
707
+ Document document = new Document (pdfDocument );
708
+ PdfPage pdfPage = pdfDocument .addNewPage ();
709
+ PdfFont font = PdfFontFactory .createFont (FONT_FOLDER + "FreeSans.ttf" ,
710
+ "WinAnsi" , EmbeddingStrategy .FORCE_EMBEDDED );
711
+ Paragraph paragraph = new Paragraph ("Hello PdfUA2" ).setFont (font );
712
+ document .add (paragraph );
713
+ pdfPage .getPdfObject ().getAsStream (PdfName .Contents ).put (PdfName .PageNum , new PdfNumber (5 ));
714
+ pdfPage .setPageLabel (PageLabelNumberingStyle .DECIMAL_ARABIC_NUMERALS , null , 5 );
715
+ }
716
+ compareAndValidate (outFile , cmpFile );
717
+ }
718
+
603
719
private void createSimplePdfUA2Document (PdfDocument pdfDocument ) throws IOException , XMPException {
604
720
byte [] bytes = Files .readAllBytes (Paths .get (SOURCE_FOLDER + "simplePdfUA2.xmp" ));
605
721
XMPMeta xmpMeta = XMPMetaFactory .parse (new ByteArrayInputStream (bytes ));
0 commit comments