-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from knipferrc/feature/read-pdfs
Feature/read pdfs
- Loading branch information
Showing
7 changed files
with
109 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package pdfdoc | ||
|
||
import ( | ||
"bytes" | ||
|
||
"github.com/knipferrc/fm/strfmt" | ||
|
||
"github.com/charmbracelet/lipgloss" | ||
"github.com/ledongthuc/pdf" | ||
) | ||
|
||
// Model represents the properties of text. | ||
type Model struct { | ||
Content string | ||
Width int | ||
} | ||
|
||
// ReadPdf reads a PDF file given a name. | ||
func ReadPdf(name string) (string, error) { | ||
f, r, err := pdf.Open(name) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
defer f.Close() | ||
|
||
buf := new(bytes.Buffer) | ||
b, err := r.GetPlainText() | ||
|
||
if err != nil { | ||
return "", err | ||
} | ||
|
||
_, err = buf.ReadFrom(b) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return buf.String(), nil | ||
} | ||
|
||
// SetSize sets the size of the pdfdoc. | ||
func (m *Model) SetSize(width int) { | ||
m.Width = width | ||
} | ||
|
||
// SetContent sets the content of the pdfdoc. | ||
func (m *Model) SetContent(content string) { | ||
m.Content = content | ||
} | ||
|
||
// GetContent returns the content of the pdfdoc. | ||
func (m Model) GetContent() string { | ||
return m.Content | ||
} | ||
|
||
// View returns a string representation of pdfdoc. | ||
func (m *Model) View() string { | ||
return lipgloss.NewStyle(). | ||
Width(m.Width). | ||
Render(strfmt.ConvertTabsToSpaces(m.Content)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters