|
| 1 | +/* |
| 2 | +This file is part of the iText (R) project. |
| 3 | +Copyright (c) 1998-2024 Apryse Group NV |
| 4 | +Authors: Apryse Software. |
| 5 | +
|
| 6 | +This program is offered under a commercial and under the AGPL license. |
| 7 | +For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below. |
| 8 | +
|
| 9 | +AGPL licensing: |
| 10 | +This program is free software: you can redistribute it and/or modify |
| 11 | +it under the terms of the GNU Affero General Public License as published by |
| 12 | +the Free Software Foundation, either version 3 of the License, or |
| 13 | +(at your option) any later version. |
| 14 | +
|
| 15 | +This program is distributed in the hope that it will be useful, |
| 16 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | +GNU Affero General Public License for more details. |
| 19 | +
|
| 20 | +You should have received a copy of the GNU Affero General Public License |
| 21 | +along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 22 | +*/ |
| 23 | +using System; |
| 24 | +using iText.Kernel.Geom; |
| 25 | +using iText.Kernel.Pdf; |
| 26 | +using iText.PdfCleanup.Exceptions; |
| 27 | +using iText.Test; |
| 28 | + |
| 29 | +namespace iText.PdfCleanup { |
| 30 | + [NUnit.Framework.Category("IntegrationTest")] |
| 31 | + public class UnsupportedImageTypeTest : ExtendedITextTest { |
| 32 | + private static readonly String INPUT_PATH = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext |
| 33 | + .CurrentContext.TestDirectory) + "/resources/itext/pdfcleanup/UnsupportedImageTypeTest/"; |
| 34 | + |
| 35 | + private static readonly String OUTPUT_PATH = NUnit.Framework.TestContext.CurrentContext.TestDirectory + "/test/itext/pdfcleanup/UnsupportedImageTypeTest/"; |
| 36 | + |
| 37 | + [NUnit.Framework.OneTimeSetUp] |
| 38 | + public static void Before() { |
| 39 | + CreateOrClearDestinationFolder(OUTPUT_PATH); |
| 40 | + } |
| 41 | + |
| 42 | + [NUnit.Framework.Test] |
| 43 | + public virtual void CheckUnSupportedImageTypeTest() { |
| 44 | + String input = INPUT_PATH + "JpegCmykImage.pdf"; |
| 45 | + String output = OUTPUT_PATH + "JpegCmykImage.pdf"; |
| 46 | + PdfDocument pdfDocument = new PdfDocument(new PdfReader(input), new PdfWriter(output, new WriterProperties |
| 47 | + ())); |
| 48 | + iText.PdfCleanup.PdfCleanUpTool workingTool = new iText.PdfCleanup.PdfCleanUpTool(pdfDocument); |
| 49 | + int pageIndex = 1; |
| 50 | + Rectangle area = pdfDocument.GetPage(pageIndex).GetPageSize(); |
| 51 | + workingTool.AddCleanupLocation(new iText.PdfCleanup.PdfCleanUpLocation(pageIndex, area)); |
| 52 | + Exception e = NUnit.Framework.Assert.Catch(typeof(Exception), () => workingTool.CleanUp()); |
| 53 | + NUnit.Framework.Assert.IsTrue(CleanupExceptionMessageConstant.UNSUPPORTED_IMAGE_TYPE.ToLowerInvariant().Equals |
| 54 | + (e.Message.ToLowerInvariant()) || "incompatible color conversion".Equals(e.Message.ToLowerInvariant()) |
| 55 | + ); |
| 56 | + pdfDocument.Close(); |
| 57 | + } |
| 58 | + } |
| 59 | +} |
0 commit comments