Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDF in iframe showing title as 'Anonymous'

I am using Angular2. I am getting PDF response as BLOB from backend API. The PDF is showing fine in iframe but it is showing title as 'anonymous'. Can someone please guide?

html code:

<iframe id="showPDFIframe" allowtransparency="false" title="TestPDF" width="100%" height="800" [attr.src]="dataLocalUrl" type="application/pdf"></iframe>

pdf.component.ts

    pdfDownload: any;
    protected dataLocalUrl: SafeResourceUrl;
    
    ngOnInit() {
    this.requestOptions = this.createRequestOptions();
    this.requestOptions.responseType = ResponseContentType.Blob;
    this._pdfModelService.showPDF(this.requestOptions)
    .subscribe( (res) => {
      this.pdfDownload = res;
      this.dataLocalUrl = this.domSanitizer.bypassSecurityTrustResourceUrl(window.URL.createObjectURL(res));
    }, err => {
      console.log(err);
    })
   }

pdfModelService.ts

showPDF(options?: RequestOptions): any {
    return this._http.get(this.endpoints.showPDF.uri, options)
      .map( (res) => {
        return new Blob([res], { type: 'application/pdf' })
      });
  }

See below image 'Anonymous' is showing enter image description here

Note: backend API gives the bytes which we cast in BLOB.

like image 973
Hassan Kashif Avatar asked Aug 18 '17 15:08

Hassan Kashif


2 Answers

have you tried providing title in the options:

showPDF(options?: RequestOptions): any {
return this._http.get(this.endpoints.showPDF.uri, options)
  .map( (res) => {
    return new Blob([res], { type: 'application/pdf', title: 'testpdf' })
  });
}
like image 176
Manas Avatar answered Sep 17 '22 14:09

Manas


Although I am not certain why the specified title field "TestPDF" in the code is not appearing on the page, the "(anonymous)" value that is displaying could simply be pulling the meta data from the PDF file itself. A possible solution would be to check the title field in the PDF document properties to set the title there. In Adobe Acrobat, from the file menu select Properties > Description to check/update the title field.

Reference article from W3.org: https://www.w3.org/TR/WCAG20-TECHS/PDF18.html

like image 20
Applied-Innovations Avatar answered Sep 16 '22 14:09

Applied-Innovations