pdf2dcm: unable to create PDF DICOM encapsulation

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
mparamas
Posts: 19
Joined: Fri, 2005-09-30, 15:23

pdf2dcm: unable to create PDF DICOM encapsulation

#1 Post by mparamas »

Hi,

I am unable to covert pdf file into a dicom file. This pdf file was generated by Text To PDF converter by verypdf.com, from text file. Adobe Reader opens this pdf file. Further details below. What am I missing? Thanks in advance. -Sundar

$pdf2dcm -d sundar2.pdf mydcm.dcm
file sundar2.pdf: unable to decode PDF version number.
unable to create PDF DICOM encapsulation

$ file sundar2.pdf
sundar2.pdf: PDF document, version 1.4

$ pdf2dcm --version
$dcmtk: pdf2dcm v3.5.4 2005-12-20 $

pdf2dcm: Convert PDF file to DICOM

Host type: i386-pc-win32

External libraries used:
- ZLIB, Version 1.2.3

Platform: Windows Server 2003 with cygwin.

Jörg Riesmeier
ICSMED DICOM Services
ICSMED DICOM Services
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

#2 Post by Jörg Riesmeier »

What are the first bytes of the PDF file? It would be helpful if you could post e.g. the first text line ...

mparamas
Posts: 19
Joined: Fri, 2005-09-30, 15:23

pdf2dcm ..

#3 Post by mparamas »

Hex dump of the pdf file from Hex editor:
25 50 44 46 2D 31 2E 34 20 76 65 72 79 70 64 66
2E 63 6F 6D 0A 33 20 30 20 6F 62 6A 0A 20 3C 3C
<trimmed>

Opening the pdf file under Notepad.exe:
%PDF-1.4 verypdf.com
3 0 obj
<</Length 4 0 R /Filter /FlateDecode >>
stream
<trimmed>

First few lines of the original text file:
-----------------------------------------------------
Region cps per pixel /Whole Brain
-----------------------------------------------------
rGFs.p9 661.73900 0.58590200
rGFd.p9 729.90800 0.64625800
lGFs.p9 862.63700 0.76377600
lGFd.p9 914.68000 0.80985500
lSM.p9 920.74200 0.81522200

Please let me know if you need the pdf file. Thanks. -Sundar

Michael Onken
DCMTK Developer
Posts: 2055
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

#4 Post by Michael Onken »

Hi,
your PDF file is invalid as far as I understand.
From your file:
%PDF-1.4 verypdf.com
According to the PDF specification, instead of a space character (0x20) after the version number there must be a line feed or carriage return, from the specification (see chapter 7.5)
This sub-clause describes how objects are organized in a PDF file for efficient random access and incremental update. A basic conforming PDF file shall be constructed of following four elements (see Figure 2):
• A one-line header identifying the version of the PDF specification to which the file conforms
and a few lines later:
Each line shall be terminated by an end-of-line (EOL) marker, which may be a CARRIAGE RETURN (0Dh), a LINE FEED (0Ah), or both. PDF files with binary data may have arbitrarily long lines.
It is pretty easy modifying pdf2dcm to support such an invalid encoding. Just change the line

Code: Select all

if (version[i] == 10 || version[i] == 13)
to

Code: Select all

if (version[i] == 10 || version[i] == 13 || version[i] == 20)
and the file will hopefully be read.

Regards,
Michael

mparamas
Posts: 19
Joined: Fri, 2005-09-30, 15:23

#5 Post by mparamas »

Awesome response. I simply used the Hex editor and changed 20 to 0A (after version number) in the pdf file, saved it, and pd2dcm now works! And adobe reader reads the file. I will request veripdf support team to correct in their software. Thanks a lot!

$ pdf2dcm -v sundar3.pdf mydcm3.dcm
creating encapsulated PDF object
file sundar3.pdf: PDF 1.4, 7kB
writing encapsulated PDF object as file mydcm3.dcm
Check if new output transfer syntax is possible
Output transfer syntax LittleEndianExplicit can be written
write converted DICOM file with metaheader
conversion successful

-Sundar

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest