I am trying to print on printer with go, but printer only prints strange characters ... I don't know how can I solve it.
If I print string it works, if I try print pdf on external software it works, only fail on go.
I used "github.com/jadefox10200/goprint"
printerHandle, err := goprint.GoOpenPrinter("CUSTOM K80")
if err != nil {log("Failed to open printer")}
defer goprint.GoClosePrinter(printerHandle)
err = goprint.GoPrint(printerHandle, "hello.pdf")
if err != nil { log("during the func sendToPrinter, there was an error") }
Result:
> %PDF-1.3 3 0 obj <</Type /Page /Parent 1 0 R /Resources 2 0 R
> /Contents 4 0 R>> endobj 4 0 obj <</Filter /FlateDecode /Length 215>>
> stream
> x�ϿJ4A�|�����?���A���Ό��!�p>��bf�IS�*Ɠcl�))���}_��p^Fj�z��ϥ��Ҧ���,�K�c�^221�fs�F��r�5������a9ن�x9/\5+���α��$�פ��P+�iU�}-��a�}��J,�($ӑ-B�$�
> ��C:ُ���e ��?�[�c�;^oxk�dfs� ���qN^ endstream endobj 1 0 obj
> <</Type /Pages /Kids [3 0 R ] /Count 1 /MediaBox [0 0 175.75 255.12]
> endobj 5 0 obj <</Type /Font /BaseFont /Helvetica-Bold /Subtype /Type1
> /Encoding /WinAnsiEncoding
> >> endobj 6 0 obj <</Type /Font /BaseFont /Helvetica /Subtype /Type1 /Encoding /WinAnsiEncoding
> >> endobj 2 0 obj << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] /Font << /Ff5d2de5f3a71699ae4b2d83179e62d09e6fc4126 5 0 R
> /F0a76705d18e0494dd24cb573e53aa0a8c710ec99 6 0 R
> >> /XObject <<
> >> /ColorSpace <<
> >>
> >> endobj 7 0 obj << /Producer (FPDF 1.7) /Title (�� T e s t P D F) /CreationDate (D:20190722103543)
> >> endobj 8 0 obj << /Type /Catalog /Pages 1 0 R
> >> endobj xref 0 9 0000000000 65535 f 0000000372 00000 n 0000000656 00000 n 0000000009 00000 n 0000000087 00000 n 0000000459 00000 n
> 0000000560 00000 n 0000000866 00000 n 0000000969 00000 n trailer <<
> /Size 9 /Root 8 0 R /Info 7 0 R
> >> startxref 1018 %%EOF
Possible areas to check
jadefox goprint package might not perform rasterisation, or at least not for your "CUSTOM K80" printer. It might therefore pass the raw file contents to the printer for it to rasterise.
your printer might not support PDF internally. Many mid range and higher-end laser printers do. Cheaper printers often don't. Printers that don't parse PDF may instead treat the received data as plain ASCII text.
Related
I am using laravel 4 with DOMPDF to display an PDF. While i am clicking PDF it will display like below:
%PDF-1.3 1 0 obj << /Type /Catalog /Outlines 2 0 R /Pages 3 0 R >> endobj 2 0 obj << /Type /Outlines /Count 0 >> endobj 3 0 obj << /Type /Pages /Kids [6 0 R ] /Count 1 /Resources << /ProcSet 4 0 R /Font << /F1 8 0 R /F2 9 0 R >> /XObject << /I1 10 0 R >> >> /MediaBox [0.000 0.000 841.890 595.280] >> endobj 4 0 obj [/PDF /Text /ImageC ] endobj 5 0 obj << /Creator (DOMPDF) /CreationDate (D:20160823103816+00'00') /ModDate (D:20160823103816+00'00') >> endobj 6 0 obj << /Type /Page /Parent 3 0 R /Contents 7 0 R >> endobj 7 0 obj << /Filter /FlateDecode /Length 2558 >> stream x��[�n7}�W�1����v$�me%�29+$A�ز��d9F� �~�~j�3�K��l�L`b�����u�{�~;B�����`�)�$�XR��=���Ο��;"X�k��/�N7�E1L�e����¡��~���������w�������<>��/�����}��|���4�,������<�������緟����O�O7'�������?��d���s�WJ�9����1;$�4����:[-PJ/x � �����z�bԇY,��,_8�]-..���*��r��b5��ju�y}y�n���=Z/oV� �����+�U?~��U�#�d���TH��zq}�������f��"!6L���� $��J�\����\�/����ƺ�� 0t���U���7v|~�$��N���������p8�i��<�>4�¥�� ��D¨�-�����C(*�e��mqFbn+���db!��5R4n�w�,�C��-���hSN1������|��� ��b*m��1���[$�����3���)9����N��a�U�y��Փ��[ ���g��|���y �ID�p<��� n�w��[)LU펝� S��z6o�yg���-��{���0�k�I���S��[�������;���5��&��؈��3�E�Y�*o k�� �0�X��6��yg���a�%n;��bw�鼤�#>T#/�X����ް��M�1D��<�E�Y�*o([+z�Zr��>KoPc�yp�ܳ#U��4>�[�F$��`��$��x��j�%5��� �[�X�0�A�y{��;T���auo��Bnf���;T�m�"���ƧkE������3��y�wc�f������+ZJ��'��A+�E�Y�*w {�*=c&'��,�Aav���!��"�,P����+��t�5e���4��y�o�w_>y�c ��$w��#֧҆Ns�n�{h�}D�8�{m)XZVmV�2��c7�'�6ԥQIo�*&t%ͭ�D눒fu�N�衒���.EA4�0 ��HD�g�u=�\�X��ZDs��P4����n��L��g����` �t�����Q�^�����́{�E3�k|�w'u9���h�CxwRw.�L!G��Ļ����R����́w�E3»����L�yg�Z4�!�;�;��� 9j�&�Fl��S�ҝ��\ G����K�r��nz͑̑w�E2y$�8�N�&��,��g�Z$s�;����n�=S2�y��|#�x��x�$s��j�̇������r��M�;�\���Z�Jw&�\ G����K� �L2�s��n�gI��=�"���餐�J7�)�#�,P�d>�нҝy��9J��^2yK��f�{�t=�\��g�&%sT��i՝d. �y��)�U��N�?�V�`�X�������1%i|L ��U��'���2��ih9,a�rF����pCCww�v/7ѩ�N�W P��9#��W���bx:\wU��2Aе0�2,�544wk���D"�/���[2(�C����1ByK����PA��`�C��?��h�[2(/�����*ByK�=��U�eqt��K�%ByK��K ����y���%��j�'���FP�҇ a�$��>ByK�g����$��%��cxm�&���,}�09�መ\]�w#��dp~�-±I,?�F,oɰ�|�����2#KJ�"��T��8�vr��$��%��͆�3X2�~,1�B����zS�j`c�����^.�}����ޣ�ً���K��p8�9�܌��ߟ����COc�������oX��juw�ipA�Y5%`jqR���=��Xp���&�[�B��`el2��^nG?��YZ!s�����_���tU6��m�֍ n&OhgI���`�k;�)��˦ �Sm�4�쵇������*> endobj 9 0 obj << /Type /Font /Subtype /Type1 /Name /F2 /BaseFont /Helvetica-Bold /Encoding /WinAnsiEncoding >> endobj 10 0 obj << /Type /XObject /Subtype /Image /Width 64 /Height 64 /Filter /FlateDecode /DecodeParms << /Predictor 15 /Colors 3 /Columns 64 /BitsPerComponent 8>> /ColorSpace /DeviceRGB /BitsPerComponent 8 /Length 929>> stream h�՚�n�#����T�R�#���.�"Z!�����P���\!W[M�.����]�,��*#ș��������3����6��n�O�M]�#����|֯/�����D4�I��LJ�pEQ�$UUM\UU�e�l6�O~C�8��|��DD��>�cD�>5��������k�~�gߴZ ���bQŤ4QY���g��$��"*�b�X�Z�ડ,����#'I�N��O b����nD?Q�睑��Q����j+��z�6Xfp�����{��3w##��k�!��<�<�TU�~�����r��R�y�{���`/1˲p9��k�8��~��slpW?��4ǽ��3VI܂�LY� �ӮY���"��|���#p�>9=,k[�;� u]ߝsl�M��%p����fE��^`\�%=��["�e^b�-�|CHcS[뺶��,��õ��O�n�K�Tv����}a�5/��N �M���x�7 "�y\��� ��������L(Dt:��,��wQ�$�T����C���(���cs� �3����9�vƒ�R���}�6��XL�R�t:%Ib��!v�2��������M���#峷����1H�V_(��C�NS�����\sV�ՀS���a����i��~i`��b�c��0D�����N8�I��k}�Ӷ�����}����Y��Ŵ�ug|_�}��������>���M��L��b9/�z�k��Ͼ�ͼ�-����c��i����;B�{�#��O������`�����*�BvΑ����k}���%�9kǪ���yi>������i�N�z���������f�a�O���`�ݎg�/��� endstream endobj xref 0 11 0000000000 65535 f 0000000008 00000 n 0000000073 00000 n 0000000119 00000 n 0000000310 00000 n 0000000347 00000 n 0000000461 00000 n 0000000524 00000 n 0000003155 00000 n 0000003262 00000 n 0000003374 00000 n trailer << /Size 11 /Root 1 0 R /Info 5 0 R >> startxref
How to solve this issues. Please Help Me. Thanks in advance
You can check how to convert data into pdf here. Try this code in to generate pdf. Dont forget to use dompdf library.
I have a script that is supposed to find the number of pages in a PDF document. In some cases, it is finding this incorrectly, and I'm looking at it and finding something puzzling: InStr isn't returning the first instance of my string, but one in the middle. Here is some code:
Set TempFile = fso.OpenTextFile(sFileName, 1)
lNumPages = 0
sLine = TempFile.ReadAll
Temp = InStr(sLine, "/Count ")
'Strip out the number of pages
lNumPages = CLng(Mid(sLine, Temp + 7, InStr(Temp + 1, sLine, "/") - Temp - 7))
Using a text editor (Textpad in this case) I can see the following in the file itself when I search for "/Count ":
515 0 obj
<<
/Count 13
/Kids [ 516 0 R 520 0 R 525 0 R 528 0 R
532 0 R 535 0 R 539 0 R ]
/Type /Pages
>>
endobj
516 0 obj
<<
/Count 2
/Kids [ 517 0 R ]
/Parent 515 0 R
/Type /Pages
>>
endobj
517 0 obj
<<
/Count 2
/Kids [ 518 0 R 519 0 R ]
/Parent 516 0 R
/Type /Pages
>>
endobj
down to
522 0 obj
<<
/Count 1
/Kids [ 53 0 R ]
/Parent 521 0 R
/Type /Pages
>>
endobj
523 0 obj
<<
/Count 1
/Kids [ 97 0 R ]
/Parent 521 0 R
/Type /Pages
>>
endobj
524 0 obj
<<
/Count 1
/Kids [ 136 0 R ]
/Parent 521 0 R
/Type /Pages
>>
endobj
525 0 obj
<<
/Count 1
/Kids [ 526 0 R ]
/Parent 515 0 R
/Type /Pages
>>
endobj
and more. The issue is that the Temp = InStr(sLine, "/Count ") line sets Temp to the position for /Count following the 522 object, instead of the first instance, the 515 object, which all text editors find.
I even did a hex comparison, and find them all to be the same, with the following characters: 43 6F 75 6E 74 20 31 33
What could possibly be causing InStr to locate a string that is neither first nor last?
The file is about 532k, but the first character found with InStr is at position 532,584, so not really close to 524,288, either, if it would make any difference.
I defined an image within a pdf stream. It works correctly an shows me a red 4 pixel palette:
%PDF-1.7
1 0 obj
<<
/Type /Catalog
/Pages 2 0 R
/PageMode /UseNone
>>
endobj
2 0 obj
<<
/Type /Pages
/Count 1
/Kids [3 0 R]
>>
endobj
3 0 obj
<<
/Type /Page
/Parent 2 0 R
/MediaBox [0 0 50 20]
/Contents 4 0 R
/Resources
<<
/XObject << /Im1 5 0 R >>
>>
>>
endobj
4 0 obj
<<
/Length 38
>>
stream
40 0 0 10 5 5 cm
/Im1 Do
endstream
endobj
5 0 obj
<<
/Type /XObject
/Subtype /Image
/Width 4
/Height 1
/ColorSpace /DeviceRGB
/BitsPerComponent 2
/Filter /ASCIIHexDecode
/Length 10
>>
stream
01 08 30
endstream
endobj
xref
0 6
0000000000 65535 f
0000000009 00000 n
0000000090 00000 n
0000000155 00000 n
0000000311 00000 n
0000000400 00000 n
trailer
<<
/Size 6
/Root 1 0 R
>>
startxref
720
%%EOF
But when I try to show the same image as an inline image, there is only a blank page:
...
...same as above...
...
3 0 obj
<<
/Type /Page
/Parent 2 0 R
/MediaBox [0 0 50 20]
/Contents 4 0 R
>>
endobj
4 0 obj
<<
/Length 92
>>
stream
40 0 0 10 5 5 cm
BI
/W 4
/H 1
/CS /RGB
/BPC 2
/F /AHx
ID
01 08 30
EI
endstream
endobj
...
When I use no abbreviations for the image properties, there is already a blank page.
Does anyone has an idea what could be the problem?
Thank you for any hint and help!
Okay, the last two days I read the specification again and again. But it was worthwhile.
There were two mistakes. Only the correction of both of them gave me my wanted result...
First of all I did not end the ASCIIHexDecodeFilter portion between ID and ED. The specification says: "A right angle bracket character (>) indicates EOD." If there is a full stream filtered with ASCIIHexDecodeFilter, the Adobe Reader knows about the end of the stream by reading the /Length attribute. But as part of the stream itself it needs the > character.
The second thing is that my page object (3 0 obj) requires a /Resources attribute mandatory. It may be empty (/Resources << >>) but it may not be missing.
Thanks for everyone who tried to answer or help!!
Here the correct working inline image PDF file stream:
%PDF-1.7
1 0 obj
<<
/Type /Catalog
/Pages 2 0 R
/PageMode /UseNone
>>
endobj
2 0 obj
<<
/Type /Pages
/Count 1
/Kids [3 0 R]
>>
endobj
3 0 obj
<<
/Type /Page
/Parent 2 0 R
/MediaBox [0 0 50 20]
/Contents 4 0 R
/Resources << >>
>>
endobj
4 0 obj
<<
/Length 90
>>
stream
q
40 0 0 10 5 5 cm
BI
/W 4
/H 1
/CS/RGB
/BPC 2
/F /AHx
ID
01 08 30 >
EI
Q
endstream
endobj
xref
0 5
0000000000 65535 f
0000000009 00000 n
0000000090 00000 n
0000000155 00000 n
0000000277 00000 n
trailer
<<
/Size 5
/Root 1 0 R
>>
startxref
418
%%EOF
I would like my ruby File.open(FILE PATH).read be same output as what I am getting from PHP file_get_contents(FILE PATH)
Right now,
Ouput in PHP
%PDF-1.4 1 0 obj << /Title (þÿ) /Creator (þÿ) /Producer (þÿQt 4.8.4 (C) 2011 Nokia Corporation and/or its subsidiary(-ies)) /CreationDate (D:20130701144043) >> endobj 2 0 obj << /Type /Catalog /Pages 3 0 R >> endobj 4 0 obj << /Type /ExtGState /SA true /SM 0.02 /ca 1.0 /CA 1.0 /AIS false /SMask /None>> endobj 5 0 obj [/Pattern /DeviceRGB] endobj 6 0 obj << /Type /Page /Parent 3 0 R /Contents 7 0 R /Resources 9 0 R /Annots 10 0 R /MediaBox [0 0 595 842] >> endobj 9 0 obj << /ColorSpace << /PCSp 5 0 R /CSp /DeviceRGB /CSpg /DeviceGray >> /ExtGState << /GSa 4 0 R >> /Pattern << >> /Font << >> /XObject << >> >> endobj 10 0 obj [ ] endobj 7 0 obj << /Length 8 0 R /Filter /FlateDecode >> stream xœÔ½K6ɲ¥5ß¿â#‘íîá×q µzÀ1#ÅM¨6âÀ€¿Ïz–G¾a;³…8GݧÊ*Òßws»Û²÷üÇÿîÏÿôüùwÿþ?þoþºÿï¿ÿÿH©§ý?øßÿ<ÊüºÊþÇ™¯¯>–þçÏ_ÿüÇ¿ýù·ü‡üýÿüßûGî_}ÿyý«þàûg÷üý¯ÿøwû…þ±)ÿñßÿWú§ÿóOùó_êßþ—?ÿÍ«ÿóßß¿ÁÿüÇ\ÝË6þõïø¯ùJ£]svÑÿå_yøþÇýŸýù_yÑëëªWi×Ø/zþëÿ“ý·ÏŸfÿoüÓÿ¿Ëÿé£üãÏÿþ?üãäËÿß~Ýò¼î¿ý'þð?ó¯ÿ}äÖ¿’v7ÿ¹®ùU×5ëÒùŒ<êט£Š^ëW-e\œ€èùk•Ôן«Õ¯YµÀõgä>¾ôP{ùjsÕÖ ¦¯:;kè¿÷ºøÇ¿øÍëk敯?×(_#Yºž®íëê)7QÛW¹ÖÊKÔ«}å´êˆTÖ(EoÕëu>ËWJ%éGúZi”‘EMú=½XñÛ•š×¨¬‘VÓ5H¬¡7j£÷1ÿˆšõCŸuÕü5ʽÔÒõÎúý¹×øÐsúšI/⧵ò*¹þ)K»ÚF×~•²¼Ì%v×{ìýÐ[笛*ºÖèô®¤ÿStjŸOö£•YN*kÔñ¥KTÚùtúõ>³¨Kç–{c§»Î¶]KÔÙ¿fóº¼F__iqæei÷²¶÷Ð]%¾E_>jíõù£•>ÓŸ+‰?òJâŸmûªÚü)úüZCŸ¸Ì7â]eÝžOeæÂÉ4qSËU'“’ö#r€µ«D•–¾ô‹ã«´R$üðdíеÚlí‚˪¸ìJE»º´cä17ßè—Ö©æ›ùÅzù|nšú^Q· ûËóü-u¿1Ýû„øìWåÛuί‹]ÍY{-ž'ˆß昳Ô">‡ý-ý:Óôg¯¬ƒ÷ÚתeïGÖÙŽzÁ§Y}êk¿ïÀ¥÷¯¢÷¯¬·¨ìi*oצι‹1٪܌‡ê=•Ž¸–6òxš;¯
In Ruby
%PDF-1.4 1 0 obj << /Title (��) /Creator (��) /Producer (��Qt 4.8.4 (C) 2011 Nokia Corporation and/or its subsidiary(-ies)) /CreationDate (D:20130701144043) >> endobj 2 0 obj << /Type /Catalog /Pages 3 0 R >> endobj 4 0 obj << /Type /ExtGState /SA true /SM 0.02 /ca 1.0 /CA 1.0 /AIS false /SMask /None>> endobj 5 0 obj [/Pattern /DeviceRGB] endobj 6 0 obj << /Type /Page /Parent 3 0 R /Contents 7 0 R /Resources 9 0 R /Annots 10 0 R /MediaBox [0 0 595 842] >> endobj 9 0 obj << /ColorSpace << /PCSp 5 0 R /CSp /DeviceRGB /CSpg /DeviceGray >> /ExtGState << /GSa 4 0 R >> /Pattern << >> /Font << >> /XObject << >> >> endobj 10 0 obj [ ] endobj 7 0 obj << /Length 8 0 R /Filter /FlateDecode >> stream x�ԽK�6ɲ�5߿�#�����q� �z�1#�M�6�����z�G�a;��8Gݧ�*��ws�۲����������w��?�o�������H���?���<�����Ǚ��>������ǿ�����������G�}��y�����g�������w����)����W����O��_����?������߿����\��6������J�]sv���_y�������_y���Wi��/z������ϟf�o������������?������~����'��?��}�ֿ�v7����U�5����<�ט��^�W-e\����k��ן�կY���g�>��
I already tried this in Ruby(fyi, I am using RoR framework.)
open(FILE PATH, "r:ISO-8859-15:UTF-8", {:col_sep => "t", :row_sep => "rn", :headers => :first_row}) do |f|
(f.read)
end
I use GS with DjVu driver, as in this example:
gs %gs_args% -dProvideUnicode -dExtractText -sDEVICE=djvusep -o out.sep in.ps
and noticed issue, that with some files text is not correctly extracted (I get question marks in clipboard on copying text from generated file).
I thought it's some issue with encoding, and removed -dProvideUnicode switch, but then text is not extracted at all, and I assume that -dExtractText flag, specific only to this driver, needs it to function properly.
Trying to run single page PDF file (that generated in.ps through ps2write device), with ps2ascii gives also no text. But other tools like pdfminer, xpdf, extract correct text. Also PDF viewers like SumatraPDF that uses mupdf, or Acrobat, extract the text as expected.
Does anyone maybe knows something about these undocumented switches, and what could be the problem here?
Update: This only happens if I go through ps2write route. If instead I use PDF directly there is no issue.
Here is encoding info from the PDF file:
c:\temp>pdf-parser -s encoding sample.pdf
obj 11 0
Type: /Font
Referencing: 12 0 R, 20 0 R
<<
/BaseFont /XQKNMY+TT14112O00
/FontDescriptor 12 0 R
/Type /Font
/FirstChar 32
/LastChar 144
/Widths [
253 0 0 0 0 0 0 0 293 293 0 0 220 313 220 0
0 467 467 0 0 0 467 0 467 467 0 0 0 0 0 0
0 680 0 0 0 653 0 773 760 0 0 740 0 833 0 0
0 0 0 480 613 0 680 0 0 0 0 0 0 0 0 0
0 407 513 414 500 414 320 447 513 227 0 467 227 773 513 513
513 0 333 367 293 487 467 667 460 414 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
220]
/Encoding 20 0 R
/Subtype /Type1
>>
obj 20 0
Type: /Encoding
Referencing:
<<
/Type /Encoding
/BaseEncoding /WinAnsiEncoding
/Differences [
144/quoteright]
>>
This isn't really a Ghostscript question. The djvu device is decidedly non-standard in a Ghostscript build. I can't tell you anything about the switches, because they are specific to the DejaVu device.
If all you want to do is extract the text from a file you could use the txtwrite device (with recent versions of Ghostscript).
If you use a PDF file then a ToUnicode CMap may be present in the file and can be used to get Unicode information about the text. PostScript does not contain ToUnicode CMaps and so the Unicode information is NOT available from the PostScript file. I would imagine this is why the ps2write output can't have text extracted from it by the device.