Detect if PDF is B&W, Grayscale or RBG using Aspose.PDF for .NET

I’m interested in purchasing Aspose.PDF and am evaluating it. One requirement we haveis to detect if the PDF has colour

However, the following error is occurring when trying to read the ColourType:

“Second argument of BDC operator can be inline dictionary or name object. Inline dictionary is implemented only.”

The code is as follows (the error occurs on line " oColourType = oAsposeDocument.Pages(i).ColorType"):

Dim oAsposeDocument As New Aspose.Pdf.Document(sFilename)
Dim i As Integer
Dim oColourType As Aspose.Pdf.ColorType

For i = 1 To oAsposeDocument.Pages.Count

  oColourType = oAsposeDocument.Pages(i).ColorType

  Select Case oColourType
    Case Aspose.Pdf.ColorType.BlackAndWhite
      ' B+W
    Case Aspose.Pdf.ColorType.Grayscale
      ' Grayscale
    Case Aspose.Pdf.ColorType.Rgb
      ' RGB
    Case Aspose.Pdf.ColorType.Undefined
      ' Undefined
  End Select

Next

This doesn’t happen on every PDF file, but has occurred on 1 out of every 2 I have trialled. NB. The same error occurs on .Background and .Watermark. I would be grateful for any tips on what the issue might be and how to resolve it.

Thank you.

@mowalie,

We have tested your scenario with the latest version 18.3 of Aspose.PDF for .NET API, and could not replicate the said error in our environment. Kindly send us your problematic PDF documents. We will investigate and share our findings with you.

Hi Imran. Thank you for your message. I am using version 17.9 (downloaded yesterday from PDF APIs & Components for Developers | Aspose.PDF Product Family) and simply moved the .NET 4.0 bin .DLLs, .XML and .pdb files into my project and added the DLL to the project references (do I need to do a NuGet install instead?)

I have attached a file that exhibits the problem. The example code I submitted seems to work ok on simple single colour PDF files, but not files like the attached.

Thank you.

colour.pdf (530.7 KB)

@mowalie,

We managed to replicate the said error in our environment. It has been logged under the ticket ID PDFNET-44428 in our bug tracking system. We have linked your post to this ticket and will keep you informed regarding any available updates.

I have a similar issue with version 18.4.1 (latest) …

attempting to set the background color - of the page or document throws the same error.

(crazy nested colour syntax is lifted from one of your own samples in desperation).

image.png (17.9 KB)

@nickax,

We could not replicate this error in our environment. Kindly send us your source PDF and code. We will investigate your scenario in our environment, and share our findings with you.

The issues you have found earlier (filed as PDFNET-44428) have been fixed in Aspose.PDF for .NET 18.5. This message was posted using BugNotificationTool by asad.ali

We encounter the same error while converting PDF’s to PDF-A documents. Not always, but certain PDF documents. Source documents have color images.

Can you share some more details on the origin of the error?
We haven’t seen this in our development or testing environments and want to rule out the possibility the calling party produces different PDF’s on production. Can we identify the PDF’s which will cause a problem?

@RaimonddeLange,

The linked ticket ID PDFNET-44428 is regarding the error in retrieving the color type of the PDF page, which has already been fixed. Please download and try the latest version 18.6.1 of Aspose.PDF for .NET API, and then let us know how that goes into your environment.

Hello

I am using Aspose.PDF for ,NET version 20.1
Trying to merge two accessible(508) PDFs(Aspose.Pdf.PdfFormat v_1_7 from the client),I get the error:

"Object reference not set to an instance of an object"

		StackTrace	"   at #=zu5qia_28cCgQA48$TjyrY8KZIE$f.#=zohST7j8Kt92y(Page #=zKQHMiyU=, MCRElement #=z8dIGGnlUVfjn)\r\n   at Aspose.Pdf.LogicalStructure.MCRElement.#=zpzbmSgY=()\r\n   at Aspose.Pdf.LogicalStructure.Element.#=zpzbmSgY=()\r\n   at Aspose.Pdf.LogicalStructure.Element.#=zpzbmSgY=()\r\n   at Aspose.Pdf.LogicalStructure.Element.#=zpzbmSgY=()\r\n   at Aspose.Pdf.LogicalStructure.Element.#=zpzbmSgY=()\r\n   at Aspose.Pdf.LogicalStructure.StructTreeRootElement.#=zZy1iQtpJ6D0q()\r\n   at #=zAMHZBH$wbA$bReK5CGkCW0tFkyW4.#=zpzbmSgY=()\r\n   at Aspose.Pdf.Document.#=zC$6G4a2eX0Uv(Stream #=zueqnKEo=, SaveOptions #=z2XCn_$4TQiAL)\r\n   at Aspose.Pdf.Document.#=zHPNFWS3F3WB1(String #=znLfuW3TOwpnn)\r\n   at Aspose.Pdf.Document.Save(String outputFileName)\r\n   at WebApplication3.Preview_FinRep.Page_Load(Object sender, EventArgs e) in c:\\Users\\colariu\\Documents\\Visual Studio 2012\\Projects\\WebApplication3\\WebApplication3\\Preview_FinRep.aspx.cs:line 215"	string

Is it referring to the MCR? What can be the issue?

When I try to set the background color to one of the PDFS I get: Second argument of BDC operator can be inline dictionary or name object. Inline dictionary is implemented only

The PDFs and the code:
[https://www.dropbox.com/sh/0p3ubf02aollpqv/AACVh-lBmgYXKg20eJn4f29va?dl=0]

@carmenpdf

We tested the scenario in our environment using Aspose.PDF for .NET 20.9 and following code snippet. We were unable to notice any exception.

Merge PDF files

Facades.PdfFileEditor pfe = new Facades.PdfFileEditor();
pfe.CopyLogicalStructure = true;
pfe.CopyOutlines = true;
pfe.Concatenate(dataDir + "4186_EN_MRFP_A.pdf", dataDir + "4186_EN_Q1.pdf", dataDir + "result.pdf");

result.pdf (665.1 KB)

We also tried to change background of pages of both PDFs and no exception was thrown:

// Tried with both PDFs
Document pdf = new Document(dataDir + "4186_EN_Q1.pdf");
foreach (Aspose.Pdf.Page page in pdf.Pages)
{
 page.Background = Aspose.Pdf.Color.White;
}

Would you please try to use latest version of the API and in case you still face any issue, please let us know.

Thank you very much for your reply and advice.
I am using Aspose.PDF 20.9 for .NET now. After merging some of the PDFs (that have annotations) I get “Tagged Annotations failed” error message in the Accessibility Checker.
Copying the logical structure into the merged PDF does not copy the Annotations too?
Please advice.
The code and the original PDF files are at:

@carmenpdf

We have logged an issue in our environment as PDFNET-48888 for further investigation against this scenario. We will further look into its details and keep you informed about its rectification status. Please be patient and spare us some time.

We are sorry for the inconvenience.

PS: Would you please share which Validity Checker are you using to validate the output. Please share a screenshot of error in checker as well.

Thank you for your help.
I am using the Accessibility Checker from Adobe Acrobat Pro DC.

I have placed a word document(ScreenshotsAnnotations.docx) with all of the screenshots at:

https://www.dropbox.com/scl/fi/ylf4euqjlclzev8v63s7j/ScreenShotsAnnotations.docx?dl=0&rlkey=ki9mhxcia8y1cgkrrvtgw7xcs

@carmenpdf

Thanks for providing requested information.

We have updated the logged ticket accordingly and will let you know in case of additional updates regarding its resolution.

Hello again,

We have received new PDF documents.
When merging these documents , we get errors on
“Notes” (ID entry in “Note” structure element is not unique in the merged PDF) and
“Annotations” (“Link” annotation is not nested inside a “Link” structure element in the merged PDF).
I have used PAC 3 accessibility checker( the client is using the same).
Also the “Title” of the merged PDF does not show in PAC 3.

I have placed all files and a PNG on:
[Dropbox]

The merged PDF is 786f5647-2245-4f58-85d3-79a560475639.pdf.

If we want to expedite the fix what should we do?
How much is the paid support for these 2 items? (Notes and Annotations in the merged PDF? and maybe the title)

Thank you,
Carmen Olariu

@carmenpdf

We tried to access the files over the given link but they did not exist. Would you kindly provide a link with which we can download the files and proceed further?

Please try Dropbox - ASPOSE.PDF Notes and Annotations errors (merge and 508) - Simplify your life

I have set the merged document’s title, but PAC 3 says that there is no title.

@carmenpdf

We have logged an issue as PDFNET-48998 in our issue management system for further investigation on this scenario. We will look into its details and keep you posted with the status of its correction. Please spare us some time.

Once the issue is moved to priority support, its precedence would be increased accordingly and the investigation process will be expedited in terms of getting a resolution of ETA. Furthermore, you can please create a post in our Purchase forum to get the information related to pricing and plans.

Would you please share how you are trying to set the title of the document by sharing the sample code snippet. We will investigate from this perspective as well.

Good morning,
Our client have sent us new PDFs, new structure of the Pdf document, and the merge API is not working anymore.
The PDFs were created to address persons with disabilities (508) and the merged PDF should also be accessible.
I am using Aspose.pdf version 20.10
When save merged PDF command is run(line 313 in the code: taggedDocument.Save(Server.MapPath(“~/files/Output/”) + fileName, SaveFormat.Pdf);), the error is “Object reference not set to an instance of an object”
2 PDFs, and the code are at Dropbox - MergePDFNotWorking - Simplify your life
This is a time sensitive matter. The website should function ASAP. Please advise.