Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8247587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:53:51+00:00 2026-06-07T22:53:51+00:00

Problem: need to convert the base64 code PNG images obtained from the textarea, a

  • 0

Problem: need to convert the base64 code PNG images obtained from the textarea, a PNG image (a binary file with the extension. Png – image.png) with PHP and store the image on the server. Then with the help of PHP and FPDF class to generate a PDF file (example1.pdf), inserting the previously saved PNG image. The resulting PDF file is also stored on the server.

Here is the file createPdfFromBase64.php, which I have turned:

<?php
    #header('Content-Type: image/png');

    $base64 = $_POST['base64']; // Получаем base64 код PNG изображения из <textarea id="base64" name="base64"></textarea>

    #echo("$base64");

    $base64 = str_replace(' ','+',$base64); // If you want to save data that is derived from a Javascript canvas.toDataURL() function, you have to convert blanks into plusses. If you do not do that, the decoded data is corrupted.

    $data = base64_decode($base64); // Декодирует данные base64 и записывает их в переменную $data

    echo("$data");

    $filename = "image.png";

    // Пишем содержимое в файл image.png
    file_put_contents($filename, $data); // Сохраняем изображение image.png на сервере

    // Подключаем класс FPDF, для генерации PDF документа
    require('/home/u552896297/public_html/FPDF/fpdf.php');

    // Создаем FPDF объект
    $pdf= new FPDF();

    // Устанавливаем свойства документа
    $pdf->SetAuthor('Evgeniy Privalov'); // Устанавливаем автора PDF документа.
    $pdf->SetTitle('PDF generator'); // Устанавливаем title PDF документа.

    // Настройки страницы. Теперь когда главное сделано, приступим к созданию страницы.
    $pdf->AddPage('P'); // Книжная ориентация страницы
    $pdf->SetDisplayMode('real','default'); //Функция SetDisplayMode определяет как будет отображена страница. Вы можете определить параметры увеличения и разметки. В примере мы используем 100% увеличение и разметку по умолчанию, определенную в программе, используемой для просмотра.

    // Вставляем PNG картинку в верхний левый угол с разрешением в 300 точек на дюйм (300dpi)
    $pdf->Image('image.png', 10, 10, -300);

    // В конце мы выведем наш результат используя функцию Output
    $pdf->Output('example1.pdf', 'F'); // Здесь мы указали имя файла и параметр вывода, в данном случае "F". "F"-параметр сохранит результат в файл example1.pdf
?>

The index.html file is here – http://print-online.16mb.com/. Must first press the “Save business card”(“Сохранить визитку”) and then click the “Convert to PDF”(“Конвертировать в PDF”).

But when generating PDF, an error FPDF error: Not a PNG file: image.png

Please help me solve the problem!

UPD: image.png file is created on the server, but it does not appear in your browser! http://print-online.16mb.com/image.png

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T22:53:53+00:00Added an answer on June 7, 2026 at 10:53 pm

    Obviously something goes wrong with uploading or your edits afterwards. Use http://www.php.net/manual/en/ref.fileinfo.php to test the uploaded image and see if the returned info is as you expected it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem in silverlight which I need to convert this image(from database
I have problem i need to convert from my Array structure to std::vector<int> ...
Problem: I need to write/read objects from a file.This because I need to write/read
I need to convert a binary file (a zip file) into hexadecimal representation, to
I need to convert a string, obtained from excel, in VBA to an interger.
I need to convert a very large file from DBF format to CSV format.
I need to convert a piece of code from Objective-C to Java, but I
Goal: Gain datatype date with year and month Problem: Need to help to convert
I need to convert some code compiled with ARMASM to gcc(code sourcery GCC-4.6.2 eabi).
I need to convert time from one format to another in C++ and it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.