Junk Characters Coming while Decoding Data in Base 64Decode Base64 data in JavaGrails Base64 decoding of Authorization header malformed on decodeJava mail attachment raw content appended to mail body and not as fileBase64 encoding pdf file stream byte array is not getting decoded properly in email attachmentPlay Base64 encoded audio file in javaWhy doesn't Base64 Encoding of a byte[] in Java work?Issues in converting base64 decoded byte array to String in javaData decoded from Base64 by a PowerShell script is corrupt in some casesRemove junk characters (probably BOM) from xml file - VBAJava - Base64 byte array return as a string

How slow can a car engine run?

Are there any Saints that have miraculously overcome death (should have died, but did not)?

What causes a rotating object to rotate forever without external force—inertia, or something else?

Is straight-up writing someone's opinions telling?

Why did my "seldom" get corrected?

How can one convert an expression to a string while keeping the quotation marks of strings that are part of the expression?

Software need db owner permission to master database (sql2016)

Why are there few or no black super GMs?

Amira L'Akum not on Shabbat

Why are flying carpets banned while flying brooms are not?

Should I use a resistor between the gate driver and MOSFET (gate pin)?

Should I have shared a document with a former employee?

How to find location on Cambridge-Mildenhall railway that still has tracks/rails?

How to not confuse readers with simultaneous events?

The most secure way to handle someone forgetting to verify their account?

Compiler only complains about the ambiguous overloaded functions when the parameter is 0

Why isn't a binary file shown as 0s and 1s?

Everyone but three

Is encryption still applied if you ignore the SSL certificate warning for self signed?

How fast does a character need to move to be effectively invisible?

Mass Spell Recursion & Storm

How to belay quickly ascending top-rope climbers?

Which modern firearm should a time traveler bring to be easily reproducible for a historic civilization?

Why is Google approaching my VPS machine?



Junk Characters Coming while Decoding Data in Base 64


Decode Base64 data in JavaGrails Base64 decoding of Authorization header malformed on decodeJava mail attachment raw content appended to mail body and not as fileBase64 encoding pdf file stream byte array is not getting decoded properly in email attachmentPlay Base64 encoded audio file in javaWhy doesn't Base64 Encoding of a byte[] in Java work?Issues in converting base64 decoded byte array to String in javaData decoded from Base64 by a PowerShell script is corrupt in some casesRemove junk characters (probably BOM) from xml file - VBAJava - Base64 byte array return as a string






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I am getting PDF content which is Base 64 encoded. I tried to decode it using NIFI with Processor Base64EncodeContent. The Decoded file I am sending in mail. Below is small sample of output coming in mail.



enter image description here



"No data should be available in . ¹ Check if sent . . All documents are sent as pdf to* 9 : ’ ³: > < âA m¬‘²@%é‚ÇŽÇ¢|ÀÈ™$Éز§Uû÷LÒTB¨ l,îåù˜$â´º?6N¬JC¤ŒÃ°‰_Ïg -æ¿;ž‰ìÛÖYl`õ?èÓÌ[ ÿÿ PK"



How to extract the data in PDF as sent by third party?



I have tried to decode it using JAVA code and there also its failing. Not able to open the PDF, junk characters coming there too.



ConvertedJPGPDF.pdf file used below contains Base64 encoded String.



 String filePath = "C:\Users\xyz\Desktop\";
String originalFileName = "ConvertedJPGPDF.pdf";
String newFileName = "test.pdf";

byte[] input_file =
Files.readAllBytes(Paths.get(filePath+originalFileName));


// byte[] decodedBytes = Base64.getDecoder().decode(input_file);
byte[] decodedBytes1 = Base64.getMimeDecoder().decode(input_file);


FileOutputStream fos = new FileOutputStream(filePath+newFileName);
fos.write(decodedBytes1);
fos.flush();
fos.close();









share|improve this question



















  • 1





    Note that a PDF file is not a plain text file; if you treat it as if it is plain text, you'll get unreadable, random looking characters.

    – Jesper
    Mar 26 at 10:09











  • I tried same as ConvertedJPGPDF.txt , not getting expected PDF. How can I achieve it?

    – nbalodi
    Mar 26 at 10:13












  • You should not treat a PDF file as if it is a text file, that will not work.

    – Jesper
    Mar 26 at 10:30

















0















I am getting PDF content which is Base 64 encoded. I tried to decode it using NIFI with Processor Base64EncodeContent. The Decoded file I am sending in mail. Below is small sample of output coming in mail.



enter image description here



"No data should be available in . ¹ Check if sent . . All documents are sent as pdf to* 9 : ’ ³: > < âA m¬‘²@%é‚ÇŽÇ¢|ÀÈ™$Éز§Uû÷LÒTB¨ l,îåù˜$â´º?6N¬JC¤ŒÃ°‰_Ïg -æ¿;ž‰ìÛÖYl`õ?èÓÌ[ ÿÿ PK"



How to extract the data in PDF as sent by third party?



I have tried to decode it using JAVA code and there also its failing. Not able to open the PDF, junk characters coming there too.



ConvertedJPGPDF.pdf file used below contains Base64 encoded String.



 String filePath = "C:\Users\xyz\Desktop\";
String originalFileName = "ConvertedJPGPDF.pdf";
String newFileName = "test.pdf";

byte[] input_file =
Files.readAllBytes(Paths.get(filePath+originalFileName));


// byte[] decodedBytes = Base64.getDecoder().decode(input_file);
byte[] decodedBytes1 = Base64.getMimeDecoder().decode(input_file);


FileOutputStream fos = new FileOutputStream(filePath+newFileName);
fos.write(decodedBytes1);
fos.flush();
fos.close();









share|improve this question



















  • 1





    Note that a PDF file is not a plain text file; if you treat it as if it is plain text, you'll get unreadable, random looking characters.

    – Jesper
    Mar 26 at 10:09











  • I tried same as ConvertedJPGPDF.txt , not getting expected PDF. How can I achieve it?

    – nbalodi
    Mar 26 at 10:13












  • You should not treat a PDF file as if it is a text file, that will not work.

    – Jesper
    Mar 26 at 10:30













0












0








0








I am getting PDF content which is Base 64 encoded. I tried to decode it using NIFI with Processor Base64EncodeContent. The Decoded file I am sending in mail. Below is small sample of output coming in mail.



enter image description here



"No data should be available in . ¹ Check if sent . . All documents are sent as pdf to* 9 : ’ ³: > < âA m¬‘²@%é‚ÇŽÇ¢|ÀÈ™$Éز§Uû÷LÒTB¨ l,îåù˜$â´º?6N¬JC¤ŒÃ°‰_Ïg -æ¿;ž‰ìÛÖYl`õ?èÓÌ[ ÿÿ PK"



How to extract the data in PDF as sent by third party?



I have tried to decode it using JAVA code and there also its failing. Not able to open the PDF, junk characters coming there too.



ConvertedJPGPDF.pdf file used below contains Base64 encoded String.



 String filePath = "C:\Users\xyz\Desktop\";
String originalFileName = "ConvertedJPGPDF.pdf";
String newFileName = "test.pdf";

byte[] input_file =
Files.readAllBytes(Paths.get(filePath+originalFileName));


// byte[] decodedBytes = Base64.getDecoder().decode(input_file);
byte[] decodedBytes1 = Base64.getMimeDecoder().decode(input_file);


FileOutputStream fos = new FileOutputStream(filePath+newFileName);
fos.write(decodedBytes1);
fos.flush();
fos.close();









share|improve this question
















I am getting PDF content which is Base 64 encoded. I tried to decode it using NIFI with Processor Base64EncodeContent. The Decoded file I am sending in mail. Below is small sample of output coming in mail.



enter image description here



"No data should be available in . ¹ Check if sent . . All documents are sent as pdf to* 9 : ’ ³: > < âA m¬‘²@%é‚ÇŽÇ¢|ÀÈ™$Éز§Uû÷LÒTB¨ l,îåù˜$â´º?6N¬JC¤ŒÃ°‰_Ïg -æ¿;ž‰ìÛÖYl`õ?èÓÌ[ ÿÿ PK"



How to extract the data in PDF as sent by third party?



I have tried to decode it using JAVA code and there also its failing. Not able to open the PDF, junk characters coming there too.



ConvertedJPGPDF.pdf file used below contains Base64 encoded String.



 String filePath = "C:\Users\xyz\Desktop\";
String originalFileName = "ConvertedJPGPDF.pdf";
String newFileName = "test.pdf";

byte[] input_file =
Files.readAllBytes(Paths.get(filePath+originalFileName));


// byte[] decodedBytes = Base64.getDecoder().decode(input_file);
byte[] decodedBytes1 = Base64.getMimeDecoder().decode(input_file);


FileOutputStream fos = new FileOutputStream(filePath+newFileName);
fos.write(decodedBytes1);
fos.flush();
fos.close();






java base64 apache-nifi






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 10:27







nbalodi

















asked Mar 26 at 9:59









nbalodinbalodi

227 bronze badges




227 bronze badges







  • 1





    Note that a PDF file is not a plain text file; if you treat it as if it is plain text, you'll get unreadable, random looking characters.

    – Jesper
    Mar 26 at 10:09











  • I tried same as ConvertedJPGPDF.txt , not getting expected PDF. How can I achieve it?

    – nbalodi
    Mar 26 at 10:13












  • You should not treat a PDF file as if it is a text file, that will not work.

    – Jesper
    Mar 26 at 10:30












  • 1





    Note that a PDF file is not a plain text file; if you treat it as if it is plain text, you'll get unreadable, random looking characters.

    – Jesper
    Mar 26 at 10:09











  • I tried same as ConvertedJPGPDF.txt , not getting expected PDF. How can I achieve it?

    – nbalodi
    Mar 26 at 10:13












  • You should not treat a PDF file as if it is a text file, that will not work.

    – Jesper
    Mar 26 at 10:30







1




1





Note that a PDF file is not a plain text file; if you treat it as if it is plain text, you'll get unreadable, random looking characters.

– Jesper
Mar 26 at 10:09





Note that a PDF file is not a plain text file; if you treat it as if it is plain text, you'll get unreadable, random looking characters.

– Jesper
Mar 26 at 10:09













I tried same as ConvertedJPGPDF.txt , not getting expected PDF. How can I achieve it?

– nbalodi
Mar 26 at 10:13






I tried same as ConvertedJPGPDF.txt , not getting expected PDF. How can I achieve it?

– nbalodi
Mar 26 at 10:13














You should not treat a PDF file as if it is a text file, that will not work.

– Jesper
Mar 26 at 10:30





You should not treat a PDF file as if it is a text file, that will not work.

– Jesper
Mar 26 at 10:30












1 Answer
1






active

oldest

votes


















1














You mentioned that the file contains base64 encoded string already.




ConvertedJPGPDF.pdf file used below contains Base64 encoded String.




So, you don't need to run this line:



byte[] encodedBytes = Base64.getEncoder().encode(input_file);


By doing so, you are trying to encode those bytes again.



Directly decode the input_file array and then save the obtained byte array into a .pdf file.



Update:



The ConvertedJPGPDF.pdf doesn't really have to be named .pdf. It's really a plain text file considering that it is base 64 encoded.



Anyway, the following piece of code is working for me:



 String filePath = "C:\Users\xyz\Desktop\";
String originalFileName = "ConvertedJPGPDF.pdf";
String newFileName = "test.pdf";

byte[] input_file = Files.readAllBytes(Paths.get(filePath+originalFileName));

byte[] decodedBytes1 = Base64.getMimeDecoder().decode(input_file);

Files.write(Paths.get(filePath+newFileName), decodedBytes1);



Hope this helps!






share|improve this answer

























  • Done, but still not getting expected output.

    – nbalodi
    Mar 26 at 10:30











  • May be the 3rd party pdf is already corrupted. May be it has fonts that your system does not recognize and you're seeing gibberish.

    – anacron
    Mar 26 at 10:51











  • May be, 3rd Party is proving this data in xml tags as <pdfContent>.... Base64EncodedString... </pdfContent>

    – nbalodi
    Mar 26 at 12:00










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55354281%2fjunk-characters-coming-while-decoding-data-in-base-64%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You mentioned that the file contains base64 encoded string already.




ConvertedJPGPDF.pdf file used below contains Base64 encoded String.




So, you don't need to run this line:



byte[] encodedBytes = Base64.getEncoder().encode(input_file);


By doing so, you are trying to encode those bytes again.



Directly decode the input_file array and then save the obtained byte array into a .pdf file.



Update:



The ConvertedJPGPDF.pdf doesn't really have to be named .pdf. It's really a plain text file considering that it is base 64 encoded.



Anyway, the following piece of code is working for me:



 String filePath = "C:\Users\xyz\Desktop\";
String originalFileName = "ConvertedJPGPDF.pdf";
String newFileName = "test.pdf";

byte[] input_file = Files.readAllBytes(Paths.get(filePath+originalFileName));

byte[] decodedBytes1 = Base64.getMimeDecoder().decode(input_file);

Files.write(Paths.get(filePath+newFileName), decodedBytes1);



Hope this helps!






share|improve this answer

























  • Done, but still not getting expected output.

    – nbalodi
    Mar 26 at 10:30











  • May be the 3rd party pdf is already corrupted. May be it has fonts that your system does not recognize and you're seeing gibberish.

    – anacron
    Mar 26 at 10:51











  • May be, 3rd Party is proving this data in xml tags as <pdfContent>.... Base64EncodedString... </pdfContent>

    – nbalodi
    Mar 26 at 12:00















1














You mentioned that the file contains base64 encoded string already.




ConvertedJPGPDF.pdf file used below contains Base64 encoded String.




So, you don't need to run this line:



byte[] encodedBytes = Base64.getEncoder().encode(input_file);


By doing so, you are trying to encode those bytes again.



Directly decode the input_file array and then save the obtained byte array into a .pdf file.



Update:



The ConvertedJPGPDF.pdf doesn't really have to be named .pdf. It's really a plain text file considering that it is base 64 encoded.



Anyway, the following piece of code is working for me:



 String filePath = "C:\Users\xyz\Desktop\";
String originalFileName = "ConvertedJPGPDF.pdf";
String newFileName = "test.pdf";

byte[] input_file = Files.readAllBytes(Paths.get(filePath+originalFileName));

byte[] decodedBytes1 = Base64.getMimeDecoder().decode(input_file);

Files.write(Paths.get(filePath+newFileName), decodedBytes1);



Hope this helps!






share|improve this answer

























  • Done, but still not getting expected output.

    – nbalodi
    Mar 26 at 10:30











  • May be the 3rd party pdf is already corrupted. May be it has fonts that your system does not recognize and you're seeing gibberish.

    – anacron
    Mar 26 at 10:51











  • May be, 3rd Party is proving this data in xml tags as <pdfContent>.... Base64EncodedString... </pdfContent>

    – nbalodi
    Mar 26 at 12:00













1












1








1







You mentioned that the file contains base64 encoded string already.




ConvertedJPGPDF.pdf file used below contains Base64 encoded String.




So, you don't need to run this line:



byte[] encodedBytes = Base64.getEncoder().encode(input_file);


By doing so, you are trying to encode those bytes again.



Directly decode the input_file array and then save the obtained byte array into a .pdf file.



Update:



The ConvertedJPGPDF.pdf doesn't really have to be named .pdf. It's really a plain text file considering that it is base 64 encoded.



Anyway, the following piece of code is working for me:



 String filePath = "C:\Users\xyz\Desktop\";
String originalFileName = "ConvertedJPGPDF.pdf";
String newFileName = "test.pdf";

byte[] input_file = Files.readAllBytes(Paths.get(filePath+originalFileName));

byte[] decodedBytes1 = Base64.getMimeDecoder().decode(input_file);

Files.write(Paths.get(filePath+newFileName), decodedBytes1);



Hope this helps!






share|improve this answer















You mentioned that the file contains base64 encoded string already.




ConvertedJPGPDF.pdf file used below contains Base64 encoded String.




So, you don't need to run this line:



byte[] encodedBytes = Base64.getEncoder().encode(input_file);


By doing so, you are trying to encode those bytes again.



Directly decode the input_file array and then save the obtained byte array into a .pdf file.



Update:



The ConvertedJPGPDF.pdf doesn't really have to be named .pdf. It's really a plain text file considering that it is base 64 encoded.



Anyway, the following piece of code is working for me:



 String filePath = "C:\Users\xyz\Desktop\";
String originalFileName = "ConvertedJPGPDF.pdf";
String newFileName = "test.pdf";

byte[] input_file = Files.readAllBytes(Paths.get(filePath+originalFileName));

byte[] decodedBytes1 = Base64.getMimeDecoder().decode(input_file);

Files.write(Paths.get(filePath+newFileName), decodedBytes1);



Hope this helps!







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 26 at 10:49

























answered Mar 26 at 10:27









anacronanacron

4,5721 gold badge17 silver badges28 bronze badges




4,5721 gold badge17 silver badges28 bronze badges












  • Done, but still not getting expected output.

    – nbalodi
    Mar 26 at 10:30











  • May be the 3rd party pdf is already corrupted. May be it has fonts that your system does not recognize and you're seeing gibberish.

    – anacron
    Mar 26 at 10:51











  • May be, 3rd Party is proving this data in xml tags as <pdfContent>.... Base64EncodedString... </pdfContent>

    – nbalodi
    Mar 26 at 12:00

















  • Done, but still not getting expected output.

    – nbalodi
    Mar 26 at 10:30











  • May be the 3rd party pdf is already corrupted. May be it has fonts that your system does not recognize and you're seeing gibberish.

    – anacron
    Mar 26 at 10:51











  • May be, 3rd Party is proving this data in xml tags as <pdfContent>.... Base64EncodedString... </pdfContent>

    – nbalodi
    Mar 26 at 12:00
















Done, but still not getting expected output.

– nbalodi
Mar 26 at 10:30





Done, but still not getting expected output.

– nbalodi
Mar 26 at 10:30













May be the 3rd party pdf is already corrupted. May be it has fonts that your system does not recognize and you're seeing gibberish.

– anacron
Mar 26 at 10:51





May be the 3rd party pdf is already corrupted. May be it has fonts that your system does not recognize and you're seeing gibberish.

– anacron
Mar 26 at 10:51













May be, 3rd Party is proving this data in xml tags as <pdfContent>.... Base64EncodedString... </pdfContent>

– nbalodi
Mar 26 at 12:00





May be, 3rd Party is proving this data in xml tags as <pdfContent>.... Base64EncodedString... </pdfContent>

– nbalodi
Mar 26 at 12:00








Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55354281%2fjunk-characters-coming-while-decoding-data-in-base-64%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현